Exception when running optimize with optreturn=False
-
I am experiencing crashes when trying to run an optimization. I reduced it to quite a simple test case to reproduce the error:
import datetime import backtrader as bt class TestStrategy(bt.Strategy): params = ( ('period', 15), ('printdata', True), ('printops', True), ) if __name__ == '__main__': cerebro = bt.Cerebro(maxcpus=0, optreturn=False) cerebro.optstrategy(TestStrategy, period=[5, 6, 7]) data = bt.feeds.YahooFinanceCSVData( dataname=r"..\datas\nvda-1999-2014.txt", fromdate=datetime.datetime(2000, 1, 1), todate=datetime.datetime(2002, 12, 31), reverse=False, swapcloses=True, ) cerebro.adddata(data) data = bt.feeds.YahooFinanceCSVData( dataname=r"..\datas\orcl-1995-2014.txt", fromdate=datetime.datetime(2000, 1, 1), todate=datetime.datetime(2002, 12, 31), reverse=False, swapcloses=True, ) cerebro.adddata(data) cerebro.run()
This is the result:
(qrawler) C:\Users\Robin\Projects\backtrader\tests>python test_multidata_optimize.py Exception in thread Thread-3: Traceback (most recent call last): File "C:\Users\Robin\Miniconda3\envs\qrawler\lib\threading.py", line 916, in _bootstrap_inner self.run() File "C:\Users\Robin\Miniconda3\envs\qrawler\lib\threading.py", line 864, in run self._target(*self._args, **self._kwargs) File "C:\Users\Robin\Miniconda3\envs\qrawler\lib\multiprocessing\pool.py", line 463, in _handle_results task = get() File "C:\Users\Robin\Miniconda3\envs\qrawler\lib\multiprocessing\connection.py", line 251, in recv return _ForkingPickler.loads(buf.getbuffer()) AttributeError: Can't get attribute 'Lines_LineSeries_LineIterator_DataAccessor_ObserverBase_Observer_DataTrades_32f0d39362e84be2898055ff9eaf034a' on <module 'backtrader.lineseries' from 'c:\\users\\robin\\projects\\backtrader\\backtrader\\lineseries.py'>
My Python:
(qrawler) C:\Users\Robin\Projects\backtrader\tests>python -V Python 3.6.9 :: Anaconda, Inc.
Any idea whats wrong on my end or actually backtrader's fault?
-
Disable the observers with
stdstats=False
-
Thank you, yes I know, but then all observers are gone :)
-
I think I fixed it. Seems to work with the observers.
-
Please could you let us know what you did to fix this, I'm having the same issue.
-
I think the following commit in @vbs fork fixes the issue with pickling the DataTrades observer (together with two commits after it):
https://github.com/verybadsoldier/backtrader/commit/546a2e4bbb80a5ef3edb677f88d28643c35243bb
However, it would be great if @vbs could comment about technical details of the fix.