Hi community!
Exited to share that we have shipped continuous futures into production. We have implemented 3 contract rolling methods, 4 price scaling adjustments as well as adding support for back months.
From now on, the canonical future returned by the `AddFuture` calls, is the new continuous future. Through this same `AddFuture` API you can specify which mapping, price scaling and front or back month configuration you want to use. The new continuous future security is setup as tradable and will never expire since it will map underlying future contracts accordingly, these mapping events will be fed into the algorithm (as Equities) through the `SymbolChangedEvent`.
Note that previously by default the addition of the canonical future to the algorithm, would feed data of the future chain contracts who's expiration were in the 0 to 35 day window. We have disabled this behavior making the continuous future the default data feed. Previous behavior can be recovered by specifying the expiration filter `future.SetFilter(timedelta(0), timedelta(35))`/`future.SetFilter(TimeSpan.Zero, TimeSpan.FromDays(35));`.
Price Scalling
- ForwardPanamaCanal: Eliminates price jumps between two consecutive contracts, adding a factor based on the difference of their prices. First contract is the true one, factor 0
- BackwardsPanamaCanal: Eliminates price jumps between two consecutive contracts, adding a factor based on the difference of their prices. Last contract is the true one, factor 0
- BackwardsRatio: Eliminates price jumps between two consecutive contracts, multiplying the prices by their ratio. Last contract is the true one, factor 1.
- Raw: No price adjustment is made.
Contract Mapping
- LastTradingDay: The contract maps on the previous day of expiration of the front month.
- FirstDayMonth: The contract maps on the first date of the delivery month of the front month. If the contract expires prior to this date, then it rolls on the contract's last trading date instead.
- OpenInterest: The contract maps when the back month contract has a higher traded volume that the current front month.
Front and Back Months
From the `AddFuture` API `contractDepthOffset` will allow specifying which contract to use, 0 (default) is the front month, 1 the following back month and so on. Initially we have added support for the first 2 back months contracts.
At the same time Lean internals mapping and scaling refactor has moved us closer to easily supporting other markets that would require these features, like Indian or European markets.
As always please let us know if you have any issues or concerns, and we will look into them ASAP.
Enjoy!
Flame
Tom M - Hi Tom, the easiest way to use indicators with this implementation is to add the indicator you want to the FuturesContract class and then you can access the indicator value from the CurrentContract in the FuturesChain. By default, the FuturesChain class adds contracts that expire in the next 120 days down to the 2 days before expiry. This means as each contract is added it will also begin collecting data for the indicator you added to the contract so that by the time its in the front month it should be fully warmed up.
Hopefully that helps, but let me know if you have any queries.
Tom M
Thanks Flame … I am having other issues with continuous futures at the moment (see attached post), so going to wait until I figure out what's going on before proceeding. I will reference your post when I come back to futures. But conceptually what you sent thru makes sense
Brent Oster
In case others find it useful, this is an example of using NQ futures history to warm up some indicators using custom consolidators and then purchasing one NQ contract.As of when I wrote this it should work on backtests and live, though it does require the 3.0 beta.Enabling the 3.0 beta also required me to turn off the new Firefox privacy feature as it was interfering with the new dev environment.
Joshua Lieberman
I'm curious how I should expect backwards panama series to work in a live trading scenario, as the way I see it:
Is my understanding correct, or is there some trick to avoid this tradeoff I'm missing?
Louis Szeto
Hi Joshua
Your understanding is correct. The last contract data is the true one, and all previous ones will be refactored after an update. But remember, price adjustment of continuous futures is just a data smoothing technique actually, which gives us a more realistic study of the underlying asset's past price changes. So we shouldn't aggregate the raw data for comparison with the previously processed data. Instead, call a History object/dataframe every time you need a study of that.
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.
LukeI
Can anyone help a noob with creating an algorithm to purchase VIX continuous futures? When I tried it said that it's not available to buy but I think there is a continuous VIX futures contract that interactive brokers has available for live trade. I just don't know how to call it out on Quantconnect.
Louis Szeto
Hi Lukel
You have to call .Mapped property and trade the underlying contract. Continuous future is just a method to map over contracts for studying historical data like it was traded continuously under single symbol.
Read the Future Security Master docs for details.
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.
Brian Christopher
I'm having trouble using the continuous contract symbol to access the data in a historical dataframe.
Derek Melchin
Hi Brian,
Use the following snippet:
See the attached backtest for reference.
Best,
Derek Melchin
Want to invest in QuantConnect as we build the Linux of quant finance? Checkout our Wefunder campaign to join the revolution.
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.
Garrison Whipple
How do I access the minimum tick size of the altered tick price. like 0.23222556 instead of 0.25 due to it being mathematically changed. Or how can I access the multiplier of the contract price? future.SymbolProperties.MinimumPriceVariation will only get me 0.25 when I am using open interest and backwards ratio for continuous futures.
Derek Melchin
Hi Garrison,
Please provide an example.
See the attached backtest for reference.
We were able to get the minimum price variation of 0.25 with other data normalization modes and and data mapping modes. See the attached backtest for reference.
Best,
Derek Melchin
Want to invest in QuantConnect as we build the Linux of quant finance? Checkout our Wefunder campaign to join the revolution.
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.
Garrison Whipple
Derek Melchin the contract multiplier you mentioned is 50 which is the dollars to tick multiplier, I am looking for something like the backwards ratio scale on this page: Lean: QuantConnect.Data.Auxiliary.MappingContractFactorRow Class Reference or the backwards ratio scale referenced on this page: Algorithmic Trading Platform - QuantConnect.com .
When I use continuous futures with the backwards ratio and open interest the ticks get altered and in order for me to find out how many ticks away the price has gone the 0.25 default tick does not help me because all the ticks and prices get multiplied by the backwards ratio scale, so they become 0.25 times the scale 0.9914163090128755364806866953 and is now 0.2478…
All I am looking for is a way to quickly get that altered tick size or the backwards ratio scale used for the current futures contract that is selected,
Derek Melchin
Hi Garrison,
It's not currently possible to access the backwards ratio scale of continuous futures. To be notified when it's possible, subscribe to the following GitHub Issue:
Best,
Derek Melchin
Want to invest in QuantConnect as we build the Linux of quant finance? Checkout our Wefunder campaign to join the revolution.
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.
Garrison Whipple
How can I prevent this continuous futures algo from erroring out when using Futures.Energies.CrudeOilWTI contract on 9/22/2020 after the market has closed? is says: “Runtime Error: (,)” Stack Trace: “(<QuantConnect.Symbol object at 0x7fbbd1eaa540>,)”
It errors the same time that the EndofDay function runs
Same thing happens when using Futures.Grains.Corn contracts on 12/14/2020 Stack Trace: “(<QuantConnect.Symbol object at 0x7f94f23bdcc0>,)”
Louis Szeto
Hi Garrison
You only stored the canonical symbol of CL in the dict self.symbolData. It will direct to the current mapped symbol. However, when the symbol mapped is changed, your algorithm is still subscribing to the old contract’s data. So, the old symbol will get called in the OnEndOfDay handler and it is not linked to the canonical symbol. It can be easily solved if you add a if-condition to check whether the symbol is in the dict
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.
Profit
Is there a property or a helper method that returns the current offset factor (the difference between the prices of continuous future and the current mapped contract?). If not, how to compute the proper limit and/or stop prices when placing orders?
Profit
I thought I found a way to compute the offset, but it doesn't work as expected. I'm using ForwardPanamaCanal and expected constant offset for a given mapped contract but instead seeing varying offset which doesn't make sense. Can someone explain what's missing and how to do this properly?
Srk Quant
Martin Molinero This is fantastic news! I recently noticed that TradingView and IB also added this feature. So this will make backtesting much easier. For beginners to learn what all these “panama canal” means, I would love to see some lessons that we could take. What is the plan for adding this to the Futures learning course ?
Louis Szeto
Hi Sri Quant
That would be a great idea, but we currently have not planned to do so yet. Right now, please refer to the continuous contract documentation and Future Security Master‘s dataset page for information. You might also seeks some external sources (e.g. quantpedia) to learn more about the adjustment methods.
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.
Garth McGinley
Hi all,
I've been working with the continuous futures functionality and have been seeing some strange behavior whereby there is a rather large discrepancy between prices passed to onData and those used by order handling. I'm including a simple code example that buys then sells 5 futures. For comparison, this code prints the onData bar prices and the order details. You can see that the prices for the onData bars are consistently about $30-40 higher than the prices returned by the market order fills. I'm hoping this is a subtle configuration issue that maybe I don't understand or am missing regarding this feature, but I haven't been able to pinpoint why these discrepancies are present and I'm hoping someone from the community can help.
Thanks!
Martin Molinero
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!