Overall Statistics
Total Trades
97
Average Win
0%
Average Loss
0%
Compounding Annual Return
87.748%
Drawdown
16.800%
Expectancy
0
Net Profit
16328.015%
Sharpe Ratio
1.43
Probabilistic Sharpe Ratio
97.630%
Loss Rate
0%
Win Rate
0%
Profit-Loss Ratio
0
Alpha
0.573
Beta
0.044
Annual Standard Deviation
0.404
Annual Variance
0.163
Information Ratio
1.096
Tracking Error
0.419
Treynor Ratio
13.169
Total Fees
$97.00
from math import trunc
class DynamicParticleComputer(QCAlgorithm):

    def Initialize(self):
        self.SetStartDate(2012, 1, 1)  # Set Start Date
        self.SetCash(1000)  # Set Strategy Cash
        self.AddEquity("SPY", Resolution.Daily)
        self.time_to_add = self.Time.month

    def OnData(self, data):
        if not self.Portfolio.Invested:
            shares = 1000 / data['SPY'].Close
            self.MarketOrder("SPY", trunc(shares))
        
        if data.Bars.ContainsKey("SPY"):
            self.Log(f'Portfolio Cash: {self.Portfolio.Cash}')
            if self.time_to_add != self.Time.month:
                self.Log('Adding $1,000 to portfolio')
                # Add cash
                self.Portfolio.SetCash(self.Portfolio.Cash + 1000)
                # Place order
                shares = 1000 / data['SPY'].Close
                self.MarketOrder("SPY", trunc(shares))
                self.time_to_add = self.Time.month