I want to use in my system 3 different trade bars (30, 60, 1440 min) about a Dow30EMini continuos future. I am decided use 3 consolidators for this task and I want to know if I am using the consolidators correctly.
...
def Initialize(self):
self.SetStartDate(2010, 1, 1)
self.SetEndDate(2015, 1, 1)
self.SetAccountCurrency("EUR")
self.SetCash(500000)
self.continuous_futureYM = self.AddFuture(Futures.Indices.Dow30EMini,
resolution = Resolution.Minute,
extendedMarketHours = True,
dataNormalizationMode = DataNormalizationMode.Raw,
dataMappingMode = DataMappingMode.OpenInterest,
contractDepthOffset = 0)
self.continuous_futureYM.SetFilter(lambda future_filter_universe: future_filter_universe.StandardsOnly().FrontMonth())
self.symbol = self.continuous_futureYM.Symbol
self.contract = None
self.consolidator30m = self.Consolidate(self.symbol, timedelta(minutes=30), self.YM30MinHandler)
self.consolidator60m = self.Consolidate(self.symbol, timedelta(minutes=60), self.YM60MinHandler)
self.consolidator1d = self.Consolidate(self.symbol, timedelta(minutes=1440), self.YM1DayHandler)
def OnData(self, slice):
if self.contract is None:
self.contract = self.continuous_futureYM.Mapped
if not self.contract: return
if slice.SymbolChangedEvents.ContainsKey(self.continuous_futureYM.Symbol):
self.Liquidate(self.continuous_futureYM.Symbol, tag="Cambio de vencimiento")
self.contract = self.continuous_futureYM.Mapped
def YM30MinHandler(self, consolidated_bar: TradeBar) -> None:
...
def YM60MinHandler(self, consolidated_bar: TradeBar) -> None:
...
def YM1DayHandler(self, consolidated_bar: TradeBar) -> None:
...
Mia Alissi
Based on the provided extracts, your usage of consolidators seems correct. You have created three consolidators with different timeframes (30 minutes, 60 minutes, and 1 day) for the Dow30EMini continuous future. Each consolidator has its own handler method (
YM30MinHandler
,YM60MinHandler
,YM1DayHandler
), which is the correct way to handle different consolidations.Here are some key points to remember when using consolidators:
The consolidator's output data format is usually the same as the input data format. They aggregate small
TradeBar
objects into a largeTradeBar
.When defining the consolidation handler, avoid putting parenthesis
()
at the end of your method name when setting the event handler of the consolidator. If you use parenthesis, the method executes and the result is passed as the event handler instead of the method itself. So, it should beself.YM30MinHandler
, notself.YM30MinHandler()
.You can automatically update the consolidator with data from the security subscription. However, the provided extracts do not include information on how to do this for futures. For equities, you would use the
AddConsolidator
method of the Subscription Manager, like so:self.SubscriptionManager.AddConsolidator(self.symbol, self.consolidator)
. Please refer to the QuantConnect documentation for the correct method to use for futures.Remember, the provided extracts do not include all possible information about consolidators. For more detailed information, please refer to the QuantConnect documentation.
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.
Louis Szeto
Hi Victor
I'm not sure I understand you correctly, but I'm guessing you want to
I would suggest doing it with this:
Best
Louis
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.
Victor Vicent Babiloni
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!