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/

    How to pass a list of dicts to optstrategy?

    Indicators/Strategies/Analyzers
    2
    3
    97
    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.
    • S
      soulmachine last edited by

      I want to optimize my strategy with customized parameters, for example:

      cerebro.optstrategy(bt.strategies.MA_CrossOver, fast=range(2,8), slow=range(4, 16))
      

      The above configuration generates a lot of parameters that I don't want.

      Instead, I want to specify parameters manually as the following:

      cerebro.optstrategy(bt.strategies.MA_CrossOver, myparams=[
        {'fast': 2, 'slow': 4},
        {'fast': 4, 'slow': 8},
      {'fast': 3, 'slow': 7},
      ])
      

      How can I achieve this? Thanks

      1 Reply Last reply Reply Quote 0
      • A
        ab_trader last edited by

        Pass parameters to cerebro as you shown above. In the strategy:

        ...
        params = ((`myprams`, {'fast': 1, 'slow': 5}),)
        ...
        p1 = self.p.myparams['fast']
        p2 = self.p.myparams['slow']
        ...
        self.ind1 = bt.Indicators.SMA(period=p1)
        self.ind2 = bt.Indicators.SMA(period=p2)
        ...
        

        I didn't test it, but I don't see any reasons that this should not work.

        1 Reply Last reply Reply Quote 2
        • S
          soulmachine last edited by

          @ab_trader Good idea, I'll try it, thanks!

          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(); }); }