J
Hi, @backtrader and Bactraders!
I tried the second option but it didn't go as expected. I read the documentation and review every post about the backfill_from and tried several things from there without success.
The issue is that the timestamp I get from the data when the next() is called jump from 12:00 to 5:00 of the other day instead of continue to 12:01 and so on until 16:00 and then 9:30 of the next day. Here an extract of my prints:
2018-10-01T11:56:00
2018-10-01T11:57:00
2018-10-01T11:58:00
2018-10-01T11:59:00
2018-10-01T12:00:00
2018-10-02T05:31:00
2018-10-02T05:32:00
2018-10-02T05:33:00
2018-10-02T05:34:00
2018-10-02T05:35:00
2018-10-02T05:36:00
2018-10-02T05:37:00
I'm very sure that my local CSVs have data only between 9:30 and 16:00 hrs.
Let me detail about my code. This is how I'm connecting to IB:
cerebro = bt.Cerebro()
store = bt.stores.IBStore(host='127.0.0.1',port=4002, clientId=36, reconnect=-1)
My data is in minute bars and I'm reading it as follow:
data0 = btfeed.GenericCSVData(
dataname=file_path,
fromdate=datetime.datetime(2018, 10, 1, 9, 30, 0),
todate=datetime.datetime(2018, 12, 12, 9, 30, 0),
timeframe=bt.TimeFrame.Minutes,
compression=1,
dtformat='%Y%m%d',
tmformat='%H:%M:%S',
datetime=0,
time=1,
open=3,
high=4,
low=5,
close=6,
volume=8,
openinterest=-1,
)
Then, adding the data:
contract = 'TWTR-STK-SMART-USD'
data = store.getdata(dataname=contract, rtbar=True,
timeframe=bt.TimeFrame.Ticks, historical=False,
#todate=datetime.datetime.now(),
fromdate=datetime.datetime(2018, 10, 1, 9, 30, 0),
tz=pytz.timezone('US/Eastern'),
backfill_from=data0,
#sessionstart=datetime.time(9, 30, 0),
#sessionend=datetime.time(16, 0, 0),
)
cerebro.resampledata(data, timeframe=bt.TimeFrame.Minutes, compression=1)
Finally, I run cerebro as:
cerebro.broker = store.getbroker()
cerebro.addstrategy(TestStrategy)
cerebro.run(exactbars=1, runonce=False)
I have tried several combinations of parameters both, in store.getdata() and in btfeed.GenericCSVData() but none of them work. So, any help will be appreciated.
Thanks in advance.