I used to use the AddFuture() function to request Future data. But I found the AddFutureContract() function and thought it will be more straightforward to use it if I only want to get the data of the front month contract. To use it, I have to create the Symbol object of the front month contract but I cannot find any sample code about it. Say, I want to trade the front month contract of CL (WTI crude oil), how can I create the Symbol object for the front month contract given the future symbol string 'CL'?
Alexandre Catarino
Hi Wiston Juliac ,
It's more straightforward to use AddFuture in this case:
var future = AddFuture(ticker, Resolution.Minute); future.SetFilter(x => x.FrontMonth().OnlyApplyFilterAtMarketOpen());
since you would need to know the exact expiry date to create the right future contract symbol.
Wilson Tang
Hi Alexandre Catarino,
Thanks for your response. What is the function OnlyApplyFilterAtMarketOpen() used for? If I omit it, will I sometimes get more than one front month contract's data within one trading day?
Derek Melchin
Hi Wilson,
The OnlyApplyFilterAtMarketOpen method instructs the engine to only filter options contracts on the first time step of each market day. Using it improves performance. See the source code and comments here.
Best,
Derek Melchin
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.
Wilson Tang
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!