Multiple Datafeeds and multiple Timeframes
-
Hi all,
I am running backtests with multiple feeds (multiple stocks all USA market). So am following recommended approach: sudo codefor stock in stockiist: data = load corresponding csv file into Pandas dataframe cerebro.adddata(data)
Then in next func of strategy:
for stock in self.datas: do whatever
And that is working well for me. However, now I need to use Fibonnaci pivot point indicator which requires monthly data. According to this documentation
https://www.backtrader.com/docu/data-multitimeframe/data-multitimeframe/
I will need to add resampled line after adding the data, something like thisfor stock in stockiist: data = load corresponding csv file into Pandas dataframe cerebro.adddata(data) #Daily sampled data cerebro.resampledata(data,bt.TimeFrame.Months)
My understanding is that now self.datas will have the following:
"stock1 daily line, stock1 monthly line, stock2 daily line, stock2 monthly line, ..etc
Which is not convenient to iterate through in next function of strategy.
I wonder if there is a way to have monthly data added to another feed (other than self.datas) so in next function will have daily data fetched from self.datas and monthly data fetched from this additional feed.
The documentation here
https://www.backtrader.com/docu/data-resampling/data-resampling/
States that
"backtrader has built-in support for resampling by passing the original data through a filter object. Although there are several ways to achieve this, a straightforward interface exists to achieve this"
The straightforward it is referring to is to add "cerebro.adddata(data)" but nothing is said about other approaches. Would appreciate if anybody has done this and can provide help
Thanks -
@FaiqS said in Multiple Datafeeds and multiple Timeframes:
Which is not convenient to iterate through in next function of strategy.
It may not be convenient for you. Don't mix them in such a way then. Add first the lower timeframes and later the higher timeframes. You will have two clear partitions.
Or iterate using
steps
other than 1 and with different starting indices.@FaiqS said in Multiple Datafeeds and multiple Timeframes:
The straightforward it is referring to is to add "cerebro.adddata(data)"
No. It is referring to
resampledata(data, ...)
. Using any other approach won't change the order in which things are in the system and where. -
Thanks @backtrader. Yes that is an option to do it but I just wish it was more flexible.
I guess I will have to live with it.