| Overall Statistics |
|
Total Trades 10 Average Win 0% Average Loss 0% Compounding Annual Return 140.952% Drawdown 1.900% Expectancy 0 Net Profit 93.960% Sharpe Ratio 3.585 Loss Rate 0% Win Rate 0% Profit-Loss Ratio 0 Alpha 0.837 Beta 0.292 Annual Standard Deviation 0.253 Annual Variance 0.064 Information Ratio 2.506 Tracking Error 0.267 Treynor Ratio 3.098 Total Fees $10.00 |
from math import trunc
class DynamicParticleComputer(QCAlgorithm):
def Initialize(self):
self.SetStartDate(2019, 1, 1) # Set Start Date
self.SetCash(10000) # 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