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/

    Multicore optimization cause performance degradation.

    Indicators/Strategies/Analyzers
    2
    6
    293
    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.
    • Y
      yacc2000 last edited by

      I must code in some wrong way, multicore optimization cause performance degradation.

      Here is my code framework:
      10 strategy, 10 stock asset, 10 cpu cores
      Each strategy only trade one stock asset.
      preload=False, runonce=False

      corenum = 10
      stocknum = 10
      
      class UserStockStrategy(bt.Strategy):
          def __init__(self):
              self.ind = MACD(self.datas[self.p.instance])
          def next(self):
              if time_is_right:
                 self.buy(self.datas[self.p.instance])
      
      cerebro = bt.Cerebro(preload=False, runonce=False, optdatas=False, maxcpus=corenum)
      for i in range(corenum):
              params = (
                  ('instance', i),
              )
              mydict = dict(params=params)
              MyStrategy = type( f'MyUserStockStrategy{i}', (UserStockStrategy,), mydict )
              setattr(bt.metabase, f'MyUserStockStrategy{i}', MyStrategy)
              cerebro.optstrategy(MyStrategy)
      
      for i in range(stocknum):
              cerebro.adddata(pandas_data[i])
       
      cerebro.run()
      

      If not using multicore optimization, it need 50s to finish the task, if using muticore optimization, it need 60s.

      Is there anything wrong in my code?

      Thanks ind advance.

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

        Any particular reason for not using preload and runone options?

        1 Reply Last reply Reply Quote 0
        • Y
          yacc2000 last edited by

          The "Reply" button works finally :)

          I my previous post, I have mentioned that I want to change asset dynamically
          https://community.backtrader.com/topic/3422/how-to-change-asset-dynamically?_=1614960377004

          So I cannot use preload=True, and Runonce=True.

          Is preload=True and Runonce=True cause multicore optimization not working?

          Y 1 Reply Last reply Reply Quote 0
          • Y
            yacc2000 @yacc2000 last edited by

            @yacc2000 said in Multicore optimization cause performance degradation.:

            Is preload=True and Runonce=True cause multicore optimization not working?

            Mistake

            Is preload=False and Runonce=False cause multicore optimization not working?

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

              @yacc2000 said in Multicore optimization cause performance degradation.:

              Is preload=False and Runonce=False cause multicore optimization not working?

              It will work, just much slower. Preloading the data is one of the technics to allow running the optimization at full speed. Technically it means that pre-loaded data's memory is shared between multiple working processes instead of being reloaded to the internal buffers for each run of the engine (for each permutation of optimized parameters).

              As in my answer to your previous post - the framework wasn't designed to dynamically change the data feeds during the backtest and/or optimization. You may fight against the framework ( wish you luck), change your design ( by preloading all your data feeds once) or just try a different framework

              Y 1 Reply Last reply Reply Quote 4
              • Y
                yacc2000 @vladisld last edited by

                @vladisld Thanks

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