Backtesting multiple symbols with different date ranges - backtest won't start until all data feeds have data
Hi i have been researching backtesting systems and i read that Backtrader won't start a backtest until all data feeds have data.
For example if if i have AAPL from 2000-2017 and GOOG from 2012-2017, the backtest won't start until 2012 (first day of GOOG data)
Is this true is there anyway to fix?
Just for some background info: i have a database of thousands of stocks (survivorship bias free) so some of the stocks have varied date ranges and no longer trade, i want to backtest over the whole universe of stocks.
ab_trader last edited by ab_trader
I believe it is possible with certain basic code improvements. I think this was also discussed on the forum, but I was not able to find the topic.
PS You will need to do operations in both
next()functions as well as need to check what data is already delivered and what doesn't.
Thanks ab_trader, i'm surprised as i thought there would be many people wanting to backtest multiple symbols at once, and naturally some symbols will have a longer history than others.
I'll look into prenext to see if there is anything that can solve this problem.
looks like prenext might be a good solution, run the strategy in prenext and deal with min bars for my indicators in my own code.
I do my heavy analysis and backtesting in quantstrat (R framework) which handles this issue i'm talking about. But "backtester" looks promising so being able to backtest and go live in the same framework would be cool. I can't see myself fully doing a way with R though.
Paska Houso last edited by
def prenext(self): self.next() def next(self): feeds_with_data = [(i, d) for i, d in enumerate(self.datas) if len(d)] ...
That should give you the data feeds which actually have data. The 2nd feat is to keep the indicators associated to the data. That's what
enumerateis doing by giving you the index, which you can use into arrays which keep the indicators for the data.
You should bear in mind that even if the feed has already data, that doesn't mean the indicators are ready yet. A similar scheme (
lencheck) for each indicator is therefore needed.