Interactive Brokers historical data error when resampling into daily bars.
-
I have been working with backtrader for a while now and I love the platform but I have just recently started working with Interactive brokers and backtrader. I have found that the data feed seems to get stuck whenever I resample into daily bars. I have 5, 15, and 60 minute data and I am trying to add daily resampling. However, when I add the resample line, my script seems to get through a few bars, then just stops working and I have to close my terminal altogether. When the daily resample is removed, it works like a dream. I have also tried making separate requests for intraday and daily bars but when I do that, I get the data notification then the error in the dt0 = min(dt0 for dt0 in enumerate(dts)), min() is an empty argument.
My code for resmapling:
datakwargs = dict(dataname = epic, historical = historical, latethrough = False, fromdate = dt.datetime.strptime(fromdate, '%Y-%m-%d'), qcheck = 0.5) data = IBDatafactory(**datakwargs) cerebro.resampledata(data, timeframe = bt.TimeFrame.Minutes, compression = interval) cerebro.resampledata(data, timeframe = bt.TimeFrame.Minutes, compression = 15) cerebro.resampledata(data, timeframe = bt.TimeFrame.Minutes, compression = 60) cerebro.resampledata(data, timeframe = bt.TimeFrame.Days, compression = 1)
Please let me know if I am an idiot or if there is something wrong in the system. Also, the code is inside of a function, but I have attached what is pertinent.
Thank you so much!
-
@sullyai Couple of points that may or may not be useful: resampledata is done in-place so you are resampling four times in-place above. Ie. if your "day" has a half an hour bar during the real time hours, then you may get stuck resampling from 60 minutes to 1 day. Resample from 1 minute to daily instead.
Another thought is that your source data may be missing some bars due to it not being traded. For example, at the 4:00pm bar there may not be a "tick" yet so it may be missing and thus cannot be resampled. Especially with ibdata which isn't real tick data.
-
Thank you so much! I changed the datakwargs from:
datakwargs = dict(dataname = epic, historical = historical, latethrough = False, fromdate = dt.datetime.strptime(fromdate, '%Y-%m-%d'), qcheck = 0.5)
to this:
datakwargs = dict(dataname = epic, timeframe = bt.TimeFrame.Minutes, historical = historical, latethrough = False, fromdate = dt.datetime.strptime(fromdate, '%Y-%m-%d'), qcheck = 0.5)
with the obvious import of
import backtrader as bt
Thank you again!