Back

Continuous Future Prices

Hi, is it possible in a Research Notebook to query for continuous future prices?  For example, is it possible to filter the dataframe returned by the following code down to data represented only by the actively traded futures contracts.  So the rows for the June 2019 contract would not contain any data for January through March 2019 OpEx.  

qb = QuantBook()
es = qb.AddFuture(Futures.Indices.SP500EMini)
es.SetFilter(timedelta(-360), timedelta(360))

start_time = datetime(2019, 1, 1, 0, 0)
end_time = datetime(2019, 3, 31, 23, 59)
future_history = qb.GetFutureHistory(es.Symbol, start_time, end_time)
history = future_history.GetAllData()
history

Update Backtest







0

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.


Hi Jason,

The reason we see data for June contracts many months before June is because the June contract, as well as other expiration months, are being traded alongside the contract for the current month. I think what you are looking for is the data for the front-month contract which is the contract of the closest to expiry on a given day. So keep trading data only for the front-month contract on a given day, we can add the following lines of code:

hist_copy = history.copy() # just in case we want to keep the og history DataFrame
hist_copy = hist_copy[~hist_copy.index.get_level_values(2).duplicated()]

Best,
Shile Wen

2

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.


Update Backtest





0

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.


Loading...

This discussion is closed