Overall Statistics |
Total Trades 362 Average Win 2.30% Average Loss -1.04% Compounding Annual Return 6.397% Drawdown 18.100% Expectancy 0.462 Net Profit 124.370% Sharpe Ratio 0.541 Probabilistic Sharpe Ratio 3.038% Loss Rate 55% Win Rate 45% Profit-Loss Ratio 2.22 Alpha 0.062 Beta -0.03 Annual Standard Deviation 0.108 Annual Variance 0.012 Information Ratio -0.218 Tracking Error 0.22 Treynor Ratio -1.944 Total Fees $1244.34 Estimated Strategy Capacity $580000000.00 |
# MACD, EMA(MACD), MACD.Signal MA_FAST = 12; MA_SLOW = 26; MA_SIGNAL = 9; TYPE = "Exponential" class MACD_SignalCrossover(QCAlgorithm): def Initialize(self): self.SetStartDate(2008, 1, 19) self.SetEndDate(2021, 1, 26) self.SetCash(100000) self.AddEquity("SPY", Resolution.Daily).Symbol self.macd = self.MACD("SPY", MA_FAST, MA_SLOW, MA_SIGNAL, MovingAverageType.Exponential, Resolution.Daily ) self.macd_ema = IndicatorExtensions.EMA(self.macd, MA_SIGNAL) self.SetWarmUp(MA_SLOW*5) def OnData(self, data): if not self.macd_ema.IsReady: return macd = self.macd.Current.Value macd_signal = self.macd.Signal.Current.Value macd_signal_2 = self.macd_ema.Current.Value self.Plot("MACD", "macd_signal", self.macd.Signal.Current.Value) self.Plot("MACD", "macd_ema", self.macd_ema.Current.Value) self.Plot("MACD", "Zero", 0) if macd > macd_signal: self.SetHoldings("SPY", 1) else: self.Liquidate("SPY")