| Overall Statistics |
|
Total Trades 272 Average Win 0.80% Average Loss -0.64% Compounding Annual Return 28.924% Drawdown 8.900% Expectancy 0.181 Net Profit 16.038% Sharpe Ratio 1.62 Probabilistic Sharpe Ratio 66.784% Loss Rate 48% Win Rate 52% Profit-Loss Ratio 1.26 Alpha 0.092 Beta 0.359 Annual Standard Deviation 0.124 Annual Variance 0.015 Information Ratio -0.689 Tracking Error 0.149 Treynor Ratio 0.561 Total Fees $550.27 Estimated Strategy Capacity $29000000.00 Lowest Capacity Asset QQQ RIWIV7K5Z9LX Portfolio Turnover 126.64% |
# region imports
from AlgorithmImports import *
# endregion
class CasualRedOrangeBadger(QCAlgorithm):
def Initialize(self):
self.SetStartDate(2020, 6, 1)
self.SetEndDate(2021, 1, 1)
self.SetCash(100000)
self.symbol = "QQQ"
self.AddEquity(self.symbol, Resolution.Hour)
self.AddEquity("PSQ",Resolution.Hour)
self.macd = self.MACD(self.symbol, 30, 150, 20)
self.macd.Updated+= lambda sender, updated:self.macd_windows.Add(self.macd.Histogram.Current.Value)
self.macd_windows = RollingWindow[float](2)
self.ema_30 = self.EMA(self.symbol, 30)
self.ema_120 = IndicatorExtensions.EMA(self.ema_30, 150)
self.psq_ema_30 = self.EMA("PSQ", 30)
self.psq_ema_120 = self.EMA("PSQ", 150)
self.psq_dif = IndicatorExtensions.Minus(self.psq_ema_30, self.psq_ema_120)
self.psq_dif.Updated += lambda sender, updated:self.psq_dif_window.Add(self.psq_dif.Current.Value)
self.psq_dif_window = RollingWindow[float](2)
self.stoch = self.STO(self.symbol, 20, 2, 10)
self.stoch_dif = IndicatorExtensions.Minus(self.stoch.StochK, self.stoch.StochD)
self.stoch_dif.Updated += lambda sender, updated:self.stoch_dif_window.Add(self.stoch_dif.Current.Value)
self.stoch_dif_window = RollingWindow[float](2)
self.dif = IndicatorExtensions.Minus(self.ema_30, self.ema_120)
self.dif.Updated+=self.UpdateDif
self.dif_window = RollingWindow[float](2)
self.PlotIndicator("EMA", self.ema_30,self.ema_120)
# self.Schedule.On(self.DateRules.EveryDay("QQQ"), self.TimeRules.BeforeMarketClose("QQQ"), lambda :self.Liquidate())
def OnData(self, data: Slice):
hour = self.Time.hour
self.Plot("MovingAverageConvergenceDivergence", "histogram", self.macd.Histogram.Current.Value)
for symbol, trade_bar in data.Bars.items():
self.Plot("Close","price",trade_bar.Close)
if self.dif_window.IsReady:
if self.dif_window[0]>self.dif_window[1]and self.dif_window[0]>0 and hour>10:
signal = 2
self.SetHoldings(self.symbol, 1)
elif self.stoch_dif_window[0]>self.stoch_dif_window[1] and self.stoch.StochK.Current.Value > self.stoch.StochD.Current.Value and hour>10 and self.dif_window[0]>0:
self.SetHoldings(self.symbol,1)
signal=0
else:
signal = -2
self.Liquidate()
self.Plot("IN_OUT","Signal",signal)
def UpdateDif(self,sender, updated):
self.dif_window.Add(self.dif.Current.Value)