optimization and the performance analyzer



  • My code is like this:

        strats = cerebo.optstrategy(TestStrategy, maperiod=range(10,31))
        
        
        result = cerebo.run()      
        
        xx = result[0]
        
        print(len(result))
        print('length of xx', len(xx), ' type of xx=', type(xx))
        print('xx=', xx)
       
        analysis = xx.analyzers.drawdown.get_analysis()
        print("dd", xx.analyzers.drawdown.get_analysis())
        print("dd=", analysis['max']['drawdown'])
    

    the result runs like the following:
    0_1491967422122_upload-5a44435d-6fa5-4ffb-b1a0-6d5b2fff027c

    I am very confused about how this works. xx as returned an OptReturn object but when I check its type, it is given that it's a list.

    From the documents Optimization improvements,
    0_1491967627885_upload-08567777-3664-412a-bfe4-65413fcd9a78

    it seems the OptReturn object should contain analyzers attribute as well as a parameter attribute to identify which parameter group is being used in the optimization
    But from the output, I can't really access anything from the resulted variable XX.

    How to access those information please?

    Thanks



  • I get it solved.


  • administrators

    OptReturn instances are returned instead of Strategy instances. The results from cerebro.run are documented here: Docs - Cerebro in the section Returning the results

    cerebro returns the instances of the strategies it created during backtesting. This allows to analyze what they did, because all elements in the strategies are accessible:

    result = cerebro.run(**kwargs)
    

    The format of result returned by run will vary depending on whether optimization is used (a strategy was added with optstrategy):

    • All strategies added with addstrategy

      result will be a list of the instances run during the backtesting

    • 1 or more strategies were added with optstrategy

      result will be a list of list. Each internal list will contain the strategies after each optimization run


Log in to reply
 

Looks like your connection to Backtrader Community was lost, please wait while we try to reconnect.