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/

    optimization and the performance analyzer

    General Code/Help
    2
    3
    1799
    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.
    • A
      asuralm last edited by

      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

      1 Reply Last reply Reply Quote 0
      • A
        asuralm last edited by

        I get it solved.

        1 Reply Last reply Reply Quote 0
        • B
          backtrader administrators last edited by

          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

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