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



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



  • ** 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))

  • administrators

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