In the oanda broker, there seems to be a typo.
On line 128 there is:
which should be:
a quick fix would be something like this in the feed src:
o = float(linetokens[next(i)] or 0) h = float(linetokens[next(i)] or 0) l = float(linetokens[next(i)] or 0) c = float(linetokens[next(i)] or 0) v = float(linetokens[next(i)] or 0)
i mean, the data has no volume, so it breaks here, can't really help you with that.
oh, i see.
(110)_loadline() -> v = float(linetokens[next(i)]) (Pdb) linetokens ['2016-07-27', '77.64', '78.8', '77.51', '78.36', '', '1971401.0', '154530852.0', '', '', '']
The feed does not have a volume but the feed expect it to have it.
you did not configure the data feed correctly. you may find some details here:
Like @backtrader said, this is really a mess with yahoo and it is a unreliable source, today i had to set:
yahoo_finance_data = bt.feeds.YahooFinanceData(dataname="BMW.F", fromdate=from_date, todate=to_date, adjclose=True, swapcloses=False, round=False)
to get this lines:
2016-07-27,76.838997,78.705002,76.838997,75.114166,12079 2016-10-13,76.349998,76.500000,75.307999,73.177269,6697 2017-03-20,83.000000,83.000000,82.000000,79.483971,8858 2017-06-09,84.377998,84.610001,84.166000,84.539001,1182 2017-07-14,84.192001,84.317001,83.599998,83.889000,1188
You should try to find a more reliable source. I would like to help, but i have no idea, where you could find it. Anyway, i hope, this helps you a bit. :)
@backtrader hope you don't mind, i added a param to the yahoo feed. this would allow to skip the adjustment of the volume
diff backtrader_orig/feeds/yahoo.py backtrader/feeds/yahoo.py 54a55,58 > > - ``adjvolume`` (default: ``True``) > > Whether to adjust the volume if the values are not adjusted. 82a87 > ('adjvolume', True), 159c164 < else: --- > elif self.params.adjvolume:
there is a adjustment in the volume in the data parsing when adjclose=False, maybe altering the feed would help you.
By commenting line 159-160 in yahoo.py out, i get:
It is this code part:
# in v7 "adjusted prices" seem to be given, scale back for non adj if not self.params.adjclose: o *= adjfactor h *= adjfactor l *= adjfactor c = adjustedclose # v *= adjfactor # except volume which is the same as in v1 else: v /= adjfactor # rescale vol down
i went through your problem.
by changing the data source to
yahoo_finance_data = bt.feeds.YahooFinanceData(dataname="BMW.F", fromdate=from_date, todate=to_date, adjclose=False, swapcloses=True, round=False)
you will get the correct result it seems.
in the yahoo feed, there is an assumption
# In v7, the final seq is "adj close", close, volume
but the data downloaded has the seq close, adj close, volume
this can be reverted by swapcloses=True
At least, thats how i understood the code in the yahoo feed :)
So after playing with live data around, the only solution with oanda data, that seems to be working would be the way below.
If anyone is trying to achieve the same, don't change the session.py as i wrote above since this will most probably generate wrong data.
When doing this, you will need to use data in your strategies.
datakwargs = dict( timeframe=bt.TimeFrame.Seconds, compression=5, qcheck=0.5, bidask=True, backfill_start=True, backfill=True, bar2edge=True, adjbartime=True, rightedge=True, ) data = store.getdata(dataname="EUR_USD", **datakwargs) data.resample(timeframe=bt.TimeFrame.Seconds, compression=5) data_filled = data.clone(filters=[btfilters.SessionFiller], timeframe=bt.TimeFrame.Seconds, compression=5) cerebro.adddata(data) cerebro.adddata(data_filled)