Navigation

    Backtrader Community

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/

    Exception when running optimize with optreturn=False

    General Code/Help
    4
    6
    609
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • vbs
      vbs last edited by

      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?

      1 Reply Last reply Reply Quote 0
      • B
        backtrader administrators last edited by

        Disable the observers with stdstats=False

        1 Reply Last reply Reply Quote 0
        • vbs
          vbs last edited by

          Thank you, yes I know, but then all observers are gone :)

          1 Reply Last reply Reply Quote 0
          • vbs
            vbs last edited by

            I think I fixed it. Seems to work with the observers.

            1 Reply Last reply Reply Quote 0
            • AiPower Trader
              AiPower Trader last edited by

              Please could you let us know what you did to fix this, I'm having the same issue.

              1 Reply Last reply Reply Quote 0
              • vladisld
                vladisld last edited by

                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.

                1 Reply Last reply Reply Quote 1
                • 1 / 1
                • First post
                  Last post
                Copyright © 2016, 2017, 2018, 2019, 2020, 2021 NodeBB Forums | Contributors