backtrader2 / backtrader

Python Backtesting library for trading strategies
https://www.backtrader.com
GNU General Public License v3.0
238 stars 54 forks source link

cerebro will break if having non resampled data mixed with resampled data in _runnext #32

Closed happydasch closed 4 years ago

happydasch commented 4 years ago

When having different feeds:

and _runnext is called because dt for resampled feed moved forward, Cerebro will break at the following block:

https://github.com/backtrader2/backtrader/blob/d465c77f7a8221900d1635dfe63fd04e9632e01b/backtrader/cerebro.py#L1557

since the code:

(d for i, d in enumerate(dts) if d is not None and i not in rsonly)

will sometimes not return any data feeds (resampled feed is in rsonly)

i fixed this by changing it to the code below, but I am not sure about the consequences of this.

(d for i, d in enumerate(dts) if (d is not None and (i not in rsonly or not onlyresample)))

happydasch commented 4 years ago

I tried to write some code to reproduce the issue but its hard to reproduce it. I will open another issue when having some testing code.

happydasch commented 4 years ago

I add this as a reference here, since this may look like the issue i encounter.

https://community.backtrader.com/topic/1367/error-__len__-should-return-0-on-livefeed/4 https://community.backtrader.com/topic/642/iqfeed-store-and-feed-help-needed/12