Backtrader Community

    • 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/

    Get params trought superClass

    Indicators/Strategies/Analyzers
    1
    1
    33
    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.
    • Federico Bld
      Federico Bld last edited by

      Developing several strategies i have to combine them. So I wrote superclasses, i.e:

      class BaseStrategy(bt.Strategy):
          params = (
              ('loShBo', 2),
              ('isBacktesting', False),       
              ("sizerType", None),  # Must be specified otherwise will be rised an Exception
              ("sizerDictParameters", {"amount": '', "retint": ""}), # Must be specified otherwise will be rised an Exception
          )
      
      class OverBaseStrategy(BaseStrategy):
          params = (
              ('sma',26),
              ('roc',50),
              ('smaRoc',50),
              ('ema',26),
          )
      
      class MyStrategy_01(OverBaseStrategy):
          params = dict(
              stop_loss=0.05,
              trail=0.07, 
          )
      

      When I call:

      cerebro = bt.Cerebro()
      params = {
          'trail': 0.02,
          'smaRoc': 20,
          'isBacktesting': True}
              cerebro.addstrategy(strategy=MyStrategy_01, **params)
      pprint(cerebro.strats[0][0][0].params.__dict__)
      

      The output is:

      mappingproxy({'__doc__': None,
                    '__module__': 'backtrader.metabase',
                    '_getpairs': <classmethod object at 0x0000024E510751F0>,
                    '_getpairsbase': <classmethod object at 0x0000024E51075190>,
                    '_getrecurse': <classmethod object at 0x0000024E51075250>,
                    'stop_loss': 0.05,
                    'trail': 0.07})
      

      What can I do to retrive all params with superclasses included?
      i.e. :

      mappingproxy({
          '__doc__': None,
          '__module__': 'backtrader.metabase',
          '_getpairs': <classmethod object at 0x0000024E510751F0>,
          '_getpairsbase': <classmethod object at 0x0000024E51075190>,
          '_getrecurse': <classmethod object at 0x0000024E51075250>,
          'loShBo': 2,
          'isBacktesting': True,  # <== NOT False as default
          'sizerType': None,
          'sizerDictParameters': {"amount": '', "retint": ""},
          'sma': 26,
          'roc': 20,
          'smaRoc': 20,  # <== NOT 50 as default
          'ema': 26,
          'stop_loss': 0.05,
          'trail': 0.02,  # <== NOT 0.07 as default
      })
      
      1 Reply Last reply Reply Quote 0
      • 1 / 1
      • First post
        Last post
      Copyright © 2016, 2017, 2018, 2019, 2020, 2021 NodeBB Forums | Contributors