I want to operate in continuos future market 6E using AddFuture method, but my system nevers operate. I know that continuos contract can't use for operate, I use the future.Mapped to operate. I manage the contracts in the following way:
def Initialize(self):
...
self.continuous_futureEC = self.AddFuture(
ticker = Futures.Currencies.EUR,
resolution = Resolution.Minute,
market = "CME",
extendedMarketHours = True,
dataNormalizationMode = DataNormalizationMode.Raw,
dataMappingMode = DataMappingMode.OpenInterest,
contractDepthOffset = 0
)
self.continuous_futureEC.SetFilter(lambda future_filter_universe: future_filter_universe.StandardsOnly().FrontMonth())
self.contract = None
def OnData(self, slice):
if self.contract is None:
self.contract = self.continuous_futureEC.Mapped
if not self.ec.contract: return
if slice.SymbolChangedEvents.ContainsKey(self.continuous_futureEC.Symbol) and self.continuous_futureEC.Mapped.SecurityType == SecurityType.Future:
if self.Portfolio.Invested:
self.Debug("Liquidamos posiciones")
self.Liquidate(self.contract, tag="Cambio de vencimiento")
self.contract = self.continuous_futureec.Mapped
...
Mia Alissi
Based on the information provided in the extracts, it seems like you are on the right track with using the
Mapped
property of the continuous future for trading. TheMapped
property references the currently selected contract in the continuous contract series. As the contracts roll over, theMapped
property references the next contract in the series.However, there might be a few issues with your code.
Firstly, in your
OnData
method, you are checking ifself.ec.contract
exists, butself.ec
is not defined anywhere in the provided code. You might want to replaceself.ec.contract
withself.contract
.Secondly, in the
OnData
method, you are checking ifself.continuous_futureEC.Mapped.SecurityType == SecurityType.Future
, butself.continuous_futureEC.Mapped
is aSymbol
object, not aSecurity
object. You should useself.Securities[self.continuous_futureEC.Mapped].SecurityType
instead.Here is the corrected code:
Please note that this answer is based on the information provided in the extracts and there might be other issues with your code that are not covered by the extracts.
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.
Francisco Javier Saladich
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!