For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See:

optimization and the performance analyzer

  • My code is like this:

        strats = cerebo.optstrategy(TestStrategy, maperiod=range(10,31))
        result =      
        xx = result[0]
        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:

    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,

    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?


  • I get it solved.

  • administrators

    OptReturn instances are returned instead of Strategy instances. The results from 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 =**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