Overall Statistics Total Trades 132 Average Win 3.19% Average Loss -1.34% Compounding Annual Return 11.539% Drawdown 18.600% Expectancy 1.086 Net Profit 195.421% Sharpe Ratio 0.991 Probabilistic Sharpe Ratio 41.920% Loss Rate 38% Win Rate 62% Profit-Loss Ratio 2.38 Alpha 0.065 Beta 0.396 Annual Standard Deviation 0.126 Annual Variance 0.016 Information Ratio -0.183 Tracking Error 0.142 Treynor Ratio 0.314 Total Fees \$132.22
# Inspired by the theory here:
# https://seekingalpha.com/article/4299701-leveraged-etfs-for-long-term-investing

class MultidimensionalTransdimensionalPrism(QCAlgorithm):
def Initialize(self):
self.SetStartDate(2010, 2, 1)               # Start and End Date for Stocks
self.SetEndDate(2020, 1, 1)
self.SetCash(10000) # Set Amount of Money to be used
self._sma = self.SMA("SPY", 50, Resolution.Daily)
self._smab= self.SMA("SPY", 10, Resolution.Daily)
self._smabg= self.SMA("SPY", 200, Resolution.Daily)

self.rebal = 4                            # Rebalance every 4 weeks
self.rebalTimer = self.rebal - 1            # Initialize to trigger first week
self.flag1 = 0                              # Flag to initate trades

# Increment rebalance timer at every week start
self.Schedule.On(self.DateRules.WeekStart("SPY"), self.TimeRules.AfterMarketOpen("SPY", 150), self.Rebalance)

def OnData(self, data):
if self.flag1 == 1:
if data["SPY"].Close > self._smabg.Current.Value and self._smab > self._sma:
self.SetHoldings("SPY", 1, True) # Invest in 100% SPY
self.rebalTimer = 0
elif data["SPY"].Close > self._smabg.Current.Value and self._smab < self._sma:
self.SetHoldings("SPY", .7, True)
self.SetHoldings("TLT", .3, True)
self.rebalTimer = 0
elif data["SPY"].Close < self._smabg.Current.Value and self._smab > self._sma:
self.SetHoldings("SPY", .3, True)
self.SetHoldings("TLT", .7, True)
self.rebalTimer = 0
else:
self.SetHoldings("TLT", 1, True) # Invest in 100% TLT
self.rebalTimer = 0
self.flag1 = 0

def Rebalance(self):
self.rebalTimer +=1
if self.rebalTimer == self.rebal:
self.flag1 = 1