Overall Statistics
Total Trades
784
Average Win
0.60%
Average Loss
-0.04%
Compounding Annual Return
24.689%
Drawdown
26.500%
Expectancy
14.899
Net Profit
840.602%
Sharpe Ratio
1.559
Probabilistic Sharpe Ratio
88.265%
Loss Rate
7%
Win Rate
93%
Profit-Loss Ratio
16.00
Alpha
0.194
Beta
0.576
Annual Standard Deviation
0.17
Annual Variance
0.029
Information Ratio
0.898
Tracking Error
0.157
Treynor Ratio
0.461
Total Fees
$1521.10
# 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)               # Earliest start date for all ETFs in universe 2/1/10
        self.SetEndDate(2020, 3, 27)
        self.SetCash(100000) 
        self.AddEquity("TQQQ", Resolution.Hour)    # 3x QQQ
        self.AddEquity("UBT", Resolution.Hour)     # 3x 20yr Treasury
        self.AddEquity("UST", Resolution.Hour)     # 3x 10yr Treasury
        self.tkr = ["TQQQ", "UBT", "UST"]
        
        self.rebal = 2                              # Rebalance every 2 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("UST"), self.TimeRules.AfterMarketOpen("UST", 150), self.Rebalance)


    def OnData(self, data):
        # If ready to rebalance, set each holding at 1/3
        if self.flag1 == 1:                     
            for stock in self.tkr:
                self.SetHoldings(stock, 0.33)
            self.rebalTimer = 0                     # Reset rebalance timer
        self.flag1 = 0          
        
    def Rebalance(self):
        self.rebalTimer +=1
        if self.rebalTimer == self.rebal:
            self.flag1 = 1