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/

    Is it possible to use multiprocessing during backtesting (not optimization)?

    General Discussion
    3
    4
    34
    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.
    • C
      csibi.levente14 last edited by

      This backtrader article from 2015 explains the process of using multiprocessing very well but it only discusses its use for strategy optimization. I was wondering if there is support (or if it is even feasible in any way) to apply multiprocessing when running a single trading strategy across multiple assets.

      The basic structure of my code is:

      cerebro = bt.Cerebro(maxcpus = None)
      cerebro.addstrategy(TestStrategy)
      for csv_path in csv_file_list:
              if os.path.isfile(csv_path):
                  data = GenericCSVData(dataname=csv_path)
                  cerebro.adddata(data)
      
      cerebro.run()
      

      Changing the maxcpus parameter's value didn't cause any change in execution speed.

      vladisld 1 Reply Last reply Reply Quote 0
      • vladisld
        vladisld @csibi.levente14 last edited by

        @csibi-levente14 AFAIU, currently the multiprocessing module is used only for optimization.

        Unfortunately even in multiple assets scenario, where one would expect each assets historical date could be pre-loaded simultaneously - it is still done serially:

        https://github.com/mementum/backtrader/blob/0fa63ef4a35dc53cc7320813f8b15480c8f85517/backtrader/cerebro.py#L1166

        C 1 Reply Last reply Reply Quote 2
        • C
          csibi.levente14 @vladisld last edited by

          @vladisld thanks a ton, that's definitely useful to know. Then I'll focus on other aspects of the code and will leave multiprocessing aside for the time being :)

          run-out 1 Reply Last reply Reply Quote 1
          • run-out
            run-out @csibi.levente14 last edited by

            @csibi-levente14 You can use multi processing but I believe you must run a full backtest for each run. @vladisld I believe is correct in saying you would have to load the data each time. However, if doing a lot of test, this still saves much time.

            1 Reply Last reply Reply Quote 0
            • 1 / 1
            • First post
              Last post
            Copyright © 2016, 2017, 2018 NodeBB Forums | Contributors
            $(document).ready(function () { app.coldLoad(); }); }