Overall Statistics
Total Trades
1462
Average Win
1.42%
Average Loss
-0.84%
Compounding Annual Return
9.046%
Drawdown
18.900%
Expectancy
0.263
Net Profit
465.950%
Sharpe Ratio
0.788
Probabilistic Sharpe Ratio
13.326%
Loss Rate
53%
Win Rate
47%
Profit-Loss Ratio
1.70
Alpha
0.072
Beta
0.338
Annual Standard Deviation
0.126
Annual Variance
0.016
Information Ratio
0.109
Tracking Error
0.168
Treynor Ratio
0.294
Total Fees
$46381367.77
class DailyVMASSforQQQ(QCAlgorithm):

    def Initialize(self):
        self.SetStartDate(2000, 7, 22)  # Set Start Date
        self.SetEndDate(2020, 7, 22)
        self.SetCash(250000000)  # Set Strategy Cash
        self.AddEquity("QQQ", Resolution.Minute)
        self.AddEquity("SPY", Resolution.Minute)
        #self.AddEquity("TQQQ", Resolution.Minute)
        #self.AddEquity("UVXY", Resolution.Minute)
        self.SetBenchmark("SPY")
        self.lastBenchmarkValue = None
        self.BenchmarkPerformance = self.Portfolio.TotalPortfolioValue
        
        self.UniverseSettings.Resolution = Resolution.Daily
        self.AddEquity("QQQ", Resolution.Minute)
        #self.AddEquity("TQQQ", Resolution.Minute)
        #self.AddEquity("UVXY", Resolution.Minute)
        self.vma = self.SMA("QQQ", 365, Resolution.Daily, Field.Volume)

        self.vmaSlope = Momentum(12)
        
        self.BuyThreshold = -0.123
        self.SellThreshold = -0.1

        self.Schedule.On(
            self.DateRules.EveryDay("QQQ"),
            self.TimeRules.AfterMarketOpen("QQQ", 3),
            self.Derp)
        #Whenever I raise the number of minutes to anything < 2 or > 10,
        #it buys and sells once every single trading day throughout
        #the entire backtest. I don't understand this at all.
        
        self.SetWarmup(365, Resolution.Daily)
        
    def OnData(self, data):
        if self.IsWarmingUp:
            return
        self.vmaSlope.Update(self.Time, self.vma.Current.Value)
        
        benchmark = self.Securities["SPY"].Close
        if self.lastBenchmarkValue is not  None:
           self.BenchmarkPerformance = self.BenchmarkPerformance * (benchmark/self.lastBenchmarkValue)
        self.lastBenchmarkValue = benchmark
        self.Plot("Strategy vs Benchmark", "Portfolio Value", self.Portfolio.TotalPortfolioValue)
        self.Plot("Strategy vs Benchmark", "Benchmark", self.BenchmarkPerformance)
        
    
    def Derp(self):
        if not self.vmaSlope.IsReady:
            return

        if (self.vmaSlope.Current.Value >= self.SellThreshold):
            self.Liquidate("QQQ")                
            #self.SetHoldings("UVXY", 0)  
            #self.Liquidate("TQQQ")


        if self.vmaSlope.Current.Value <= self.BuyThreshold:
            self.SetHoldings("QQQ", 1)
            #self.SetHoldings("TQQQ", 0)
            #self.SetHoldings("UVXY", 0)

            #self.Short == False
            #self.Long == True
        
        #if self.vmaSlope.Current.Value >= self.SellThreshold:
        #    self.Liquidate("TQQQ")
        #    self.Liquidate("QQQ")
            #self.Long == False
            #self.Short == True
            
            #self.market or limit order for UVXY equal to 10% of total portfolio value
        
    #def GimmeHedge(self):
        #if not self.vmaSlope.IsReady:
            #return
        #if self.Short == True:
            #self.SetHoldings("UVXY", 0.15)