Overall Statistics |
Total Trades 0 Average Win 0% Average Loss 0% Compounding Annual Return 0% Drawdown 0% Expectancy 0 Net Profit 0% Sharpe Ratio 0 Probabilistic Sharpe Ratio 0% Loss Rate 0% Win Rate 0% Profit-Loss Ratio 0 Alpha 0 Beta 0 Annual Standard Deviation 0 Annual Variance 0 Information Ratio -3.141 Tracking Error 0.086 Treynor Ratio 0 Total Fees $0.00 Estimated Strategy Capacity $0 Lowest Capacity Asset |
# https://quantpedia.com/Screener/Details/14 class MomentumEffectAlgorithm(QCAlgorithm): def Initialize(self): self.SetStartDate(2021, 7, 1) # Set Start Date self.SetCash(100000) # Set Strategy Cash self.UniverseSettings.Resolution = Resolution.Daily self.macd = {} # Dict of Momentum indicator keyed by Symbol self.num_coarse = 100 # Number of symbols selected at Coarse Selection self.num_fine = 50 # Number of symbols selected at Fine Selection self.userlist = ["SPY"] #User list self.AddUniverse(self.CoarseSelectionFunction, self.FineSelectionFunction) def CoarseSelectionFunction(self, coarse): return [x for x in coarse if x.Symbol in self.userlist] def FineSelectionFunction(self, fine): return [x.Symbol for x in fine if x.Symbol in self.userlist] def OnData(self, data): for i in self.Securities.Keys: self.Debug(self.macd[i].Current.Value) if self.macd[i].Current.Value > self.macd[i].Signal.Current.Value: self.SetHoldings(i, 1) elif self.macd[i].Signal.Current.Value > self.macd[i].Current.Value: self.Liquidate(i) def OnSecuritiesChanged(self, changes): # Clean up data for removed securities and Liquidate for security in changes.RemovedSecurities: pass for security in changes.AddedSecurities: if security.Symbol not in self.macd: self.macd[security.Symbol] = MovingAverageConvergenceDivergence(12, 26, 9, MovingAverageType.Exponential) history = self.History(security.Symbol, 100, Resolution.Daily).loc[security.Symbol] for idx, row in history.iterrows(): self.macd[security.Symbol].Update(idx, row['close']) self.RegisterIndicator(security.Symbol, self.macd[security.Symbol], Resolution.Daily)