The below code is what I come up with, but I get an error “Runtime Error: ArgumentException : Please subscribe to this symbol before adding a consolidator for it. Symbol: YM19H21”
from AlgorithmImports import *
#Futures.Indices.Dow30EMini NASDAQ100EMini SP500EMini
class BasicTemplateContinuousFutureAlgorithm(QCAlgorithm):
def Initialize(self):
self.SetStartDate(2021, 1, 1)
self.SetEndDate(2021, 12, 31)
self.ym = self.AddFuture(Futures.Indices.Dow30EMini, Resolution.Hour,
dataNormalizationMode = DataNormalizationMode.BackwardsRatio,
dataMappingMode = DataMappingMode.LastTradingDay,
contractDepthOffset= 0)
self.nq = self.AddFuture(Futures.Indices.NASDAQ100EMini, Resolution.Hour,
dataNormalizationMode = DataNormalizationMode.BackwardsRatio,
dataMappingMode = DataMappingMode.LastTradingDay,
contractDepthOffset= 0)
self.consolidator_by_symbol = {}
def OnData(self, data):
currentSymbol = self.ym.Mapped
self.Debug("test: {} ".format(currentSymbol))
if currentSymbol not in self.consolidator_by_symbol:
CountConsolidator = QuoteBarConsolidator(timedelta(hours = 2))
# CountConsolidator.DataConsolidated += self.BarHandler
self.SubscriptionManager.AddConsolidator(currentSymbol, CountConsolidator)
self.consolidator_by_symbol[currentSymbol] = CountConsolidator
def OnOrderEvent(self, orderEvent):
self.Debug("Purchased Stock: {0}".format(orderEvent.Symbol))
def OnSecuritiesChanged(self, changes):
self.Debug(f"{self.Time}-{changes}")
def BarHandler(self, sender, bar):
self.Log(f"Consolidated bar received at {self.Time}")
So What would be the correct way to do it?
Can anyone provide an example?
Thx in advance
Varad Kabade
Hi Will Chau,
We need to use the continuous contract symbol for using the consolidator. Refer to the following backtest for a working example.
Best,
Varad Kabade
Will Chau
thank you so much for you help!
Will Chau
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!