Hello, I am using a dynamic universe and creating a SymbolData object for each new entry to the universe. I am trying to use the algorithm.WarmUpIndicator() helper method to wam up the indicators, but it is doing nothing. I guess I can use a history request, but since it is a little more hassle I wanted to know if I am doing something wrong. Below is my SymbolData class:
#region imports
from AlgorithmImports import *
#endregion
class SymbolData:
def __init__(self, algorithm, symbol, macdFastPeriod, macdSlowPeriod, signalLinePeriod, plot=False):
self.algorithm = algorithm
self.symbol = symbol
self.ticker = symbol.Value
self.plot = plot
# Create indicators
self.stock_value = Identity(symbol.Value)
self.ema_200 = ExponentialMovingAverage(200)
self.macd = MovingAverageConvergenceDivergence(macdFastPeriod, macdSlowPeriod, signalLinePeriod, MovingAverageType.Exponential)
self.macd_window = RollingWindow[float](2)
self.signal_window = RollingWindow[float](2)
# Create a consolidator to update the indicator
self.consolidator = TradeBarConsolidator(1)
self.consolidator.DataConsolidated += self.OnDataConsolidated
# Register the consolidator to update the indicator
algorithm.SubscriptionManager.AddConsolidator(symbol, self.consolidator)
# Warm up the indicators
algorithm.WarmUpIndicator(self.symbol, self.ema_200)
algorithm.WarmUpIndicator(self.symbol, self.macd)
def OnDataConsolidated(self, sender: object, consolidated_bar: TradeBar) -> None:
self.stock_value.Update(consolidated_bar.EndTime, consolidated_bar.Close)
self.ema_200.Update(consolidated_bar.EndTime, consolidated_bar.Close)
self.macd.Update(consolidated_bar.EndTime, consolidated_bar.Close)
if (self.macd.IsReady):
self.macd_window.Add(self.macd.Current.Value)
self.signal_window.Add(self.macd.Signal.Current.Value)
# If you have a dynamic universe, remove consolidators for the securities removed from the universe
def dispose(self) -> None:
self.algorithm.SubscriptionManager.RemoveConsolidator(self.symbol, self.consolidator)
Yuri Lopukhov
Hmm, is it possible that indicators are warmed up with resolution bars when it is done via helper, skipping your consolidator? You could check if self.ema_200.Samples is not 0 after warm up call.
Haakon
self.ema_200.Samples = 0 after the warmup. It does not help running the warmup code before I create and add the consolidator.
Haakon
Nevermind, I realized there were no historical data for the stock I was testing on that given day. My bad! The warm-up helper method works beautifully as far as I can see.
Haakon
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
To unlock posting to the community forums please complete at least 30% of Boot Camp.
You can continue your Boot Camp training progress from the terminal. We hope to see you in the community soon!