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/

    analyzers erro: AttributeError: 'list' object has no attribute 'analyzers'

    General Code/Help
    2
    3
    195
    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.
    • Evgeniy
      Evgeniy last edited by

      Hello! When studying this library, I ran into a problem.

      I do everything on the lesson of trade analysis. But I get an error.

      My cod:

      cerebro = bt.Cerebro(stdstats=False)
          data = PandasData(dataname=df, timeframe=bt.TimeFrame.Minutes)
          cerebro.addanalyzer(TradeAnalyzer, _name="ta")
      
          cerebro.adddata(data)
          cerebro.optstrategy(Strategy)
      
          thestrats = cerebro.run()
          strat = thestrats[0]
      
          print(strat.analyzers.ta.get_analysis())
      

      error:

      print(strat.analyzers.ta.get_analysis())
      AttributeError: 'list' object has no attribute 'analyzers'
      

      What is the problem?

      1 Reply Last reply Reply Quote 0
      • vladisld
        vladisld last edited by

        IIRC if optstrategy is used, the 'run' method will return a list of lists. Quoting the docs ( 'Returning the results' section of the cerebro section https://www.backtrader.com/docu/cerebro/):

        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
        ``
        Evgeniy 1 Reply Last reply Reply Quote 0
        • Evgeniy
          Evgeniy @vladisld last edited by

          @vladisld Thanks a lot!

          1 Reply Last reply Reply Quote 0
          • 1 / 1
          • First post
            Last post
          Copyright © 2016, 2017, 2018 NodeBB Forums | Contributors
          $(document).ready(function () { app.coldLoad(); }); }