| Overall Statistics |
|
Total Trades 124 Average Win 4.34% Average Loss -2.08% Compounding Annual Return 13.710% Drawdown 35.500% Expectancy 1.057 Net Profit 241.412% Sharpe Ratio 0.836 Probabilistic Sharpe Ratio 24.316% Loss Rate 33% Win Rate 67% Profit-Loss Ratio 2.09 Alpha 0.131 Beta -0.064 Annual Standard Deviation 0.148 Annual Variance 0.022 Information Ratio 0.029 Tracking Error 0.224 Treynor Ratio -1.93 Total Fees $961.94 |
class SPYMeanReversionAlgorithm(QCAlgorithm):
def Initialize(self):
self.SetStartDate(2011,3, 1) #Set Start Date
#self.SetEndDate(2020,1,20) #Set End Date
self.SetCash(100000) #Set Strategy Cash
self.spy = self.AddEquity("SPY", Resolution.Daily)
self.qqq = self.AddEquity("QQQ", Resolution.Daily)
self.upro = self.AddEquity("UPRO", Resolution.Daily)
self.shy = self.AddEquity("SHY", Resolution.Daily)
self.tqqq = self.AddEquity("TQQQ", Resolution.Daily)
self.ubt = self.AddEquity("UBT", Resolution.Daily)
self.ust = self.AddEquity("UST", Resolution.Daily)
self.agg = self.AddEquity("AGG", Resolution.Daily)
self.ETFs = ["UPRO","TQQQ", "UST", "UBT"]
self.rsi = self.RSI("SPY", 2, Resolution.Daily)
#self.sma200 = self.SMA("SPY", 200, Resolution.Daily)
#self.momp = self.MOMP("SPY", 120, Resolution.Daily)
self.SetWarmUp(200)
self.Settings.FreePortfolioValuePercentage = 0.05
def OnData(self, data):
#if not self.sma200.IsReady: return
if not self.rsi.IsReady: return
if data.ContainsKey("SPY") == True: return
#spyClose = data["SPY"].Close
if not self.Portfolio["UPRO"].Invested and self.rsi.Current.Value<25:
for stock in self.ETFs:
self.SetHoldings(stock, 0.25)
self.Debug("Long Positions Opened")
self.Debug(str("SPY RSI value: ") + str(self.rsi.Current.Value))
if self.Portfolio["UPRO"].Invested:
if self.rsi.Current.Value>70:
self.Liquidate()
self.Debug("Long Positions Closed")
else:
return