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.

  1. start = datetime(2021, 10, 1)
  2. end = datetime(2022, 1, 1)
  3. qb = QuantBook()
  4. future = qb.AddFuture(Futures.Indices.MicroNASDAQ100EMini,Resolution.Minute)
  5. symbol = future.Symbol
  6. continuous_history = qb.History(symbol, start, end)
  7. # Set up a consolidator and a RollingWindow to save the data
  8. consolidator = TradeBarConsolidator(timedelta(3))
  9. window = RollingWindow[TradeBar](20)
  10. # Attach a consolidation handler method that saves the consolidated bars in the RollingWindow
  11. consolidator.DataConsolidated += lambda _, bar: window.Add(bar)
  12. # Iterate the historical market data and feed each bar into the consolidator
  13. for bar in continuous_history.itertuples():
  14. tradebar = TradeBar(bar.Index[2], bar.Index[1], bar.open, bar.high, bar.low, bar.close, bar.volume)
  15. consolidator.Update(tradebar)
+ Expand

Code work till the line above and code below does not work. I fail to convert the rolling window into pandas dataframe.

  1. #Convert the RollingWindows' data into pandas.DataFrame.
  2. dataframe = pd.DataFrame(window).set_index('time')

Thanks.

Author

Tony Tony Tony

July 2022