Overall Statistics
Total Trades
77
Average Win
6.54%
Average Loss
-2.19%
Compounding Annual Return
12.240%
Drawdown
23.800%
Expectancy
1.291
Net Profit
217.501%
Sharpe Ratio
0.754
Probabilistic Sharpe Ratio
16.261%
Loss Rate
42%
Win Rate
58%
Profit-Loss Ratio
2.98
Alpha
0.119
Beta
-0.063
Annual Standard Deviation
0.148
Annual Variance
0.022
Information Ratio
-0.036
Tracking Error
0.205
Treynor Ratio
-1.783
Total Fees
$556.86
class RSIAlgorithm(QCAlgorithm):
    
    def Initialize(self):
        
        self.SetStartDate(2010, 1, 1)
        self.SetEndDate(2020, 1, 1)
        self.SetCash(100000)

        self.AddEquity("QQQ", Resolution.Daily)
        self.AddEquity("SPY", Resolution.Daily)

        self.benchmarkTicker = 'SPY'
        self.SetBenchmark(self.benchmarkTicker)
        self.initBenchmarkPrice = None
        
        self.SetBrokerageModel(BrokerageName.InteractiveBrokersBrokerage)
        
        self.BB_QQQ  = self.BB("QQQ", 10, 2, MovingAverageType.Exponential, Resolution.Daily)

        self.SetWarmUp(52, Resolution.Daily)
        
    
    def OnData(self, data):
        
        # self.UpdateBenchmarkValue()
        # self.Plot('Strategy Equity', self.benchmarkTicker, self.benchmarkValue)

        if self.IsWarmingUp:
            return

        
        self.IN           = self.Securities["QQQ"].Close > self.BB_QQQ.MiddleBand.Current.Value
                            

        self.OUT          = self.Securities["QQQ"].Close < self.BB_QQQ.LowerBand.Current.Value
                            

        if self.IN:
            
            self.SetHoldings([PortfolioTarget("QQQ", 1.00)])


        elif self.OUT:
            
            self.SetHoldings([PortfolioTarget("QQQ", 0.00)])
    
    
    def UpdateBenchmarkValue(self):
            
        ''' Simulate buy and hold the Benchmark '''
        
        if self.initBenchmarkPrice is None:
            
            self.initBenchmarkCash = self.Portfolio.Cash
            self.initBenchmarkPrice = self.Benchmark.Evaluate(self.Time)
            self.benchmarkValue = self.initBenchmarkCash
            
            
        else:
            
            currentBenchmarkPrice = self.Benchmark.Evaluate(self.Time)
            self.benchmarkValue = (currentBenchmarkPrice / self.initBenchmarkPrice) * self.initBenchmarkCash