What is the QuantConnect way to do Futures Rollover?
Querying for the first contract of the chain gives you the front month contract but it doesn't give you the contract you should rollover into *before* the current contract expires.
What we need to know is the date of expiration and do the rollover into the next symbol.
When I debug the symbol and the symbol value, I noticed that the symbol value has 2 extra digits.
For example, ES20U19, is a ES futures contract that expires in the month of Sept in 2019, but what does the "20" represent? It turns out that the 3rd and 4th digits is the date of expiration in the given month and year of the symbol.
2019-07-07T18:00:00.0000000 ES X80C8BOXQZUP ES20U19
2019-09-22T18:00:00.0000000 ES XAHXWTZAPNGH ES20Z19
2019-12-22T18:00:00.0000000 ES XCZJLC9NOB29 ES20H20
2020-03-22T18:00:00.0000000 ES XFH59UK0MYO1 ES19M20
2020-06-21T23:59:00.0000000 ES XHYQYCUDLM9T ES18U20
So then, my question is, do you have an API to extract the expiration date of the given symbol? Or, do I need to create a function to extract the expiration date from the given symbol?
Shile Wen
Hi Michael,
Instead of trying to extract the expiration date from the Symbol we can get the expiration date from the FuturesContract object through the .Expiry field. I’ve shown how to do this in the attached backtest.
Best,
Shile Wen
Michael Bloomfield
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!