Overall Statistics |
Total Trades 1 Average Win 0% Average Loss 0% Compounding Annual Return 9.597% Drawdown 54.700% Expectancy 0 Net Profit 295.766% Sharpe Ratio 0.489 Probabilistic Sharpe Ratio 0.706% Loss Rate 0% Win Rate 0% Profit-Loss Ratio 0 Alpha -0.001 Beta 0.991 Annual Standard Deviation 0.163 Annual Variance 0.027 Information Ratio -0.375 Tracking Error 0.004 Treynor Ratio 0.08 Total Fees $1.00 Estimated Strategy Capacity $230000000.00 Lowest Capacity Asset SPY R735QTJ8XC9X |
#region imports from AlgorithmImports import * #endregion class RSIAlgorithm(QCAlgorithm): stopMarketTicket = None stopMarketOrderFillTime = datetime.min def Initialize(self): self.SetStartDate(2006, 1, 1) self.SetEndDate(2020, 12, 31) self.SetCash(10000) EMA_Period = 100 RSI_Period = 14 self.RSI_OB = 70 self.RSI_OS = 30 self.ADX_Trending = 25 self.ADX_Exhaust = 65 #self.Allocate = 0.25 self.AddEquity("SPY", Resolution.Daily) self.AddEquity("BND", Resolution.Daily) self.AddEquity("DIA", Resolution.Daily) self.AddEquity("IWM", Resolution.Daily) self.SetBenchmark("SPY") self.SetBrokerageModel(BrokerageName.InteractiveBrokersBrokerage) self.EMA_BND = self.EMA("BND", EMA_Period) self.EMA_SPY = self.EMA("SPY", EMA_Period) self.PSAR_BND = self.PSAR("BND") self.PSAR_SPY = self.PSAR("SPY") self.RSI_SPY = self.RSI("SPY", RSI_Period) self.RSI_BND = self.RSI("BND", RSI_Period) self.ADX_SPY = self.ADX("SPY", 14) self.SetWarmUp(RSI_Period) self.SetWarmUp(EMA_Period) self.PlotIndicator("RSI_SPY", self.RSI_SPY) self.PlotIndicator("RSI_BND", self.RSI_BND) self.PlotIndicator("PSAR", self.PSAR_SPY) self.PlotIndicator("PSAR", self.PSAR_BND) def OnData(self, data): if self.IsWarmingUp: return if not self.Portfolio.Invested: #if self.RSI_SPY.Current.Value < self.RSI_OS and self.Securities["SPY"].Close > self.EMA_SPY.Current.Value: self.SetHoldings("SPY", 1) #self.SetHoldings("IWM", .5) #self.stopMarketTicket = self.StopMarketOrder("SPY", self.Liquidate(), self.PSAR_SPY.Current.Value) #if self.Securities["SPY"].Close < self.EMA_SPY.Current.Value: #self.SetHoldings("BND", 1) #self.stopMarketTicket = self.StopMarketOrder("BND", self.Liquidate(), self.PSAR_BND.Current.Value) #if self.Portfolio.Invested: #if self.Portfolio["BND"].Invested: #if self.Securities["SPY"].Close > self.EMA_SPY.Current.Value or \ #self.Securities["BND"].Close < self.EMA_BND.Current.Value: #self.Liquidate("BND") #if self.Portfolio["SPY"].Invested: #if self.Securities["SPY"].Close < self.EMA_SPY.Current.Value: #self.Liquidate("SPY") # else: # if self.Portfolio["SPY"].Invested: # self.highestSPYPrice = self.PSAR_SPY.Current.Value # updateFields = UpdateOrderFields() # updateFields.StopPrice = self.highestSPYPrice # self.stopMarketTicket.Update(updateFields) # # elif self.Portfolio["BND"].Invested: # self.highestBNDPrice = self.PSAR_BND.Current.Value # updateFields = UpdateOrderFields() # updateFields.StopPrice = self.highestBNDPrice # self.stopMarketTicket.Update(updateFields) # # else: # return #