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/

    Strategy Selection - Passing dynamic strategy name

    General Code/Help
    2
    3
    746
    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.
    • B
      blonc last edited by

      with in the strategy selection pattern, the last bit of code pushes out the analyzers data:

      for i, strat in enumerate(strats):
          rets = strat.analyzers.returns.get_analysis()
          print('Strat {} Name {}:\n  - analyzer: {}\n'.format(
              i, strat.__class__.__name__, rets))
      

      the last line specifically strat.__class__.__name__ pulling the class name to distinguish the analyzer data. However, I am using the same class for all of my strategies and just pushing new data to the object. Is it possible to pull a variable that is contained with in that single strategy class. Such as say self.datas0_.name . I have searched endlessly with in strat.__class__.__dict__.keys but can not seem to find a way.

      1 Reply Last reply Reply Quote 0
      • B
        blonc last edited by

        ** solved **

        passing a variable to the strategy params() I can then pull that that variable in my print line. The variables sit under strat.params. . or looking something like the following:

        results = cerebro.run()
        
        strats = [x[0] for x in results]  # flatten the result
        
        for i, strat in enumerate(strats):
            rets = strat.analyzers.returns.get_analysis()
            print('Strat {} Name {}:\n  - analyzer: {}\n'.format(
                i, strat.params.example_param, rets))
        
        1 Reply Last reply Reply Quote 1
        • B
          backtrader administrators last edited by

          That would have been the suggestion. Glad you could solve it quickly.

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