I am trying to get future selection to work. I want to select the nearest expiry that is at least 7 days away, for multiple futures. For example:
// In Initialize
futureGold = AddFuture(Futures.Metals.Gold, resolution);
futureEs = AddFuture(Futures.Indices.SP500EMini, resolution);
futureGold.SetFilter(TimeSpan.FromDays(7), TimeSpan.FromDays(366 / 2 + 2));
Then in OnSecuritiesChanged(SecurityChanges changes) I want to extract the underlying futures, but all of the following do not provide the underlying (either exception or null):
- Future.Symbol.Underlying,
- Future.Symbol.ID.Underlying,
- Future.Underlying
Alexandre Catarino
At the moment, we do not have the underlying of the futures in our database. For that reason, we get the null value.
Bart van den Broek
I guess i have the definition of underlying wrong.
I request the expiries of the future with symbol (a String) Futures.Indices.SP500EMini within a time range (7 days to 1/2 year). I get expiries via OnSecuritiesChanged and i want to link them back to that symbol. The symbol must be in the database somewhere, as i am getting the expiries for that symbol.
I can use string operations to obtain the link, as the base Future is "/ES" and the expiries are ESU17, ESM17, ESH17, ESZ17, etc. This is similor for CL and GC
Alexandre Catarino
Bart van den Broek, could you please rephrase your question?
I don't know whether you want the underlying or the expire date.
Jared Broad
You can buy and sell the contract with the symbol provided in the Securities changed event. In LEAN there is one "canonical" security which acts as a holder/helper for the "ES" ticker but has fake expiry dates etc; but then all the futures contracts are separate individual securities which live in the securities dictionary.
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.
Bart van den Broek
Jared, thank you for that clarification.
Alexande, want to retrieve the holder/helper for the "ES" ticker of the individual securities / futures contracts so i can perform a selection on the expiry. The intent is to select the most current (highest trading volume) expiry. Since I see a consistent pattern here, for example, 7 days before the expiry of the nearest ES (S&P500 mini future), the next expiry has the highest volume.
And of course, I need this because of multiple futures: "ES", "CL", "GC" etc.
Bart van den Broek
Turns out easy to solve:
public static String GetFutureBaseName(Future fut)
{
return fut.Symbol.ID.Symbol;
}
Bart van den Broek
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!