@run-out Amazing, thank you!
Latest posts made by appypollyloggies
Cerebro forloop reuse?
I'm trying to reuse cerebro inside a for loop, something like this:
for item in x: cerebro = bt.Cerebro() strategy = SmaCross(item,item) cerebro.addstrategy(strategy) data0 = bt.feeds.YahooFinanceData(dataname='MSFT', fromdate=datetime(2018, 1, 1), todate=datetime(2020, 12, 31)) cerebro.adddata(data0) cerebro.run()
However im arriving at a strange error:
_obj._id = cerebro._next_stid() AttributeError: 'NoneType' object has no attribute '_next_stid'
Which is fine, since only one strategy gets passed (before we're supposedly creating a new obj of cerebro) - it shouldnt have an id for a next strategy. I've read up on the reuse, and im not sure the Strategy Factory approach i read in the other thread will help, as the strategy inputs need to be dynamic and not predefined like in the example. Meaning, the inputs for the SMA need to change after every iteration of the loop.
Any help with this? Loving the lib so far :)