I would like to consolidate the futures data into a 3 minute trading bar for the futures data in the research environment.
I have come across the tutorial section and the respective consolidators, tradingbar doc section but could not make my code to work. Any help would be appreciated, thanks.
start = datetime(2021, 10, 1)
end = datetime(2022, 1, 1)
qb = QuantBook()
future = qb.AddFuture(Futures.Indices.MicroNASDAQ100EMini,Resolution.Minute)
symbol = future.Symbol
continuous_history = qb.History(symbol, start, end)
# Set up a consolidator and a RollingWindow to save the data
consolidator = TradeBarConsolidator(timedelta(3))
window = RollingWindow[TradeBar](20)
# Attach a consolidation handler method that saves the consolidated bars in the RollingWindow
consolidator.DataConsolidated += lambda _, bar: window.Add(bar)
# Iterate the historical market data and feed each bar into the consolidator
for bar in continuous_history.itertuples():
tradebar = TradeBar(bar.Index[2], bar.Index[1], bar.open, bar.high, bar.low, bar.close, bar.volume)
consolidator.Update(tradebar)
Code work till the line above and code below does not work. I fail to convert the rolling window into pandas dataframe.
#Convert the RollingWindows' data into pandas.DataFrame.
dataframe = pd.DataFrame(window).set_index('time')
Thanks.
Tony Tony Tony
The error msg is shown as below for ease reference.
Tony Tony Tony
For others who may encounter the same issue, I have managed to make this work by the following code
Â
Louis Szeto
Hi Tony and QC community
Please refer to this doc for casting RollingWindow into other types. It would still work in research environment by changing self. into qb (python) / adding qb. in front of the RollingWindow object (C#).
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.
Tony Tony Tony
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!