Overall Statistics
Total Trades
62
Average Win
8.14%
Average Loss
-0.22%
Compounding Annual Return
32.628%
Drawdown
46.000%
Expectancy
35.939
Net Profit
1908.342%
Sharpe Ratio
1.409
Probabilistic Sharpe Ratio
73.421%
Loss Rate
3%
Win Rate
97%
Profit-Loss Ratio
37.21
Alpha
0.295
Beta
0.577
Annual Standard Deviation
0.266
Annual Variance
0.071
Information Ratio
0.915
Tracking Error
0.258
Treynor Ratio
0.651
Total Fees
$903.21
# Inspired by the theory here:
# https://seekingalpha.com/article/4299701-leveraged-etfs-for-long-term-investing

class MultidimensionalTransdimensionalPrism(QCAlgorithm):

    def Initialize(self):
        self.SetStartDate(2009, 9, 1)               # Earliest start date for all ETFs in universe 2/1/10
        self.SetEndDate(2020, 4, 13)
        self.SetCash(100000) 
        self.AddEquity("TQQQ", Resolution.Minute)    # 3x QQQ
        self.AddEquity("TMF", Resolution.Minute)     # 3x 20yr Treasury
        self.tkr = ["TQQQ", "TMF"]
        
        self.rebal = 4                              # 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.MonthEnd("TQQQ"),self.TimeRules.BeforeMarketClose("TQQQ",25), self.Rebalance)


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