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 can I inherit params from a parent class and append on the child class?

    Indicators/Strategies/Analyzers
    3
    4
    75
    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.
    • André Tavares
      André Tavares last edited by

      How can I inherit params from a parent class and append on the child class?
      I have tried the code below, but received an error.

      class Parent(bt.Strategy):
      params = {
      'p1': '',
      'p2': '',
      }

      class Child(Parent):
      params = Parent.params
      params.update({
      'p3': '',
      'p4': '',
      })

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

        would be nice to have the error posted also.

        1 Reply Last reply Reply Quote 0
        • André Tavares
          André Tavares last edited by

          C:\Users\SERVER_OPT1\anaconda3\envs\Denali\python.exe D:/onedrive/AndreTavares/Fundo/Denali/strats/momentumfactor.py --symbols PETR4 BBAS3 ABEV3 "--strat={'symbols_idx': 'ibrx100'}" --start_date=2019-03-01
          Traceback (most recent call last):
          File "D:/onedrive/AndreTavares/Fundo/Denali/strats/momentumfactor.py", line 40, in <module>
          class MomentumFactor(strategy.Strategy):
          File "D:/onedrive/AndreTavares/Fundo/Denali/strats/momentumfactor.py", line 44, in MomentumFactor
          params.update({
          AttributeError: type object 'AutoInfoClass_LineRoot_LineMultiple_LineSeries_Lin' has no attribute 'update'

          Process finished with exit code 1

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

            @André-Tavares said in How can I inherit params from a parent class and append on the child class?:

            params.update({

            No need to update the params dict. The parameters from the base classes are fused automagically by metaclass during the instantiation. You may take a look at the following post as well: https://community.backtrader.com/topic/2379/difference-between-params-and-p/2

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