Overall Statistics
Total Trades
43
Average Win
7.46%
Average Loss
-0.81%
Compounding Annual Return
13.615%
Drawdown
16.000%
Expectancy
8.736
Net Profit
307.472%
Sharpe Ratio
1.049
Probabilistic Sharpe Ratio
48.803%
Loss Rate
5%
Win Rate
95%
Profit-Loss Ratio
9.22
Alpha
0.123
Beta
-0.038
Annual Standard Deviation
0.112
Annual Variance
0.013
Information Ratio
-0.066
Tracking Error
0.189
Treynor Ratio
-3.106
Total Fees
$59.13
class RSIAlgorithm(QCAlgorithm):

    def Initialize(self):
        self.SetStartDate(2009, 1, 1)  
        self.SetEndDate(2019, 12, 31)  
        self.SetCash(10000)           
        
        RSI_Period    = 14            
        self.RSI_OB   = 70                
        self.RSI_OS   = 30                
        #self.Allocate = 0.25              
        
        self.AddEquity("SPY", Resolution.Daily)
        self.AddEquity("BND", Resolution.Daily)
        
        self.RSI_SPY = self.RSI("SPY", RSI_Period)
        self.RSI_BND = self.RSI("BND", RSI_Period)
        self.SetWarmUp(RSI_Period)
        
    def OnData(self, data):
        if self.IsWarmingUp:
            return
        
        if not self.Portfolio.Invested:
            if self.RSI_SPY.Current.Value < self.RSI_OS:
                self.SetHoldings("SPY", 1)
            elif self.RSI_SPY.Current.Value > self.RSI_OB:
                self.SetHoldings("BND", 1)
        
        elif self.Portfolio["BND"].Invested:
            if self.RSI_SPY.Current.Value < self.RSI_OS:
                self.Liquidate("BND")
                self.SetHoldings("SPY", 1)
            else:
                return
            
        elif self.Portfolio["SPY"].Invested:
            if self.RSI_SPY.Current.Value > self.RSI_OB:
                self.Liquidate("SPY")
                self.SetHoldings("BND", 1)
            
            else:
                return