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/

    'Cerebro' object has no attribute '_exactbars' [pandas/.csv]

    General Code/Help
    2
    3
    4019
    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.
    • fbleaux
      fbleaux last edited by backtrader

      from datetime import datetime
      import argparse
      import backtrader as bt
      import backtrader.feeds as btfeeds
      import pandas
      
      class SmaCross(bt.SignalStrategy):
          params = (('pfast', 10), ('pslow', 30),)
          def __init__(self):
                  sma1, sma2 = bt.ind.SMA(period=self.p.pfast), bt.ind.SMA(period=self.p.pslow)
                  self.signal_add(bt.SIGNAL_LONG, bt.ind.CrossOver(sma1, sma2))
          
      cerebro = bt.Cerebro()
      
      args = parse_args()
      datapath = ('/Users/rf/Documents/DSC/Datasets/abn.csv')
      skiprows = 1 if args.noheaders else 0
      header = None if args.noheaders else 0
      
      dataframe = pandas.read_csv(datapath,
                                  skiprows=skiprows,
                                  header=header,
                                  parse_dates=True,
                                  index_col=0)
      
      if not args.noprint:
          print(dataframe)
      
      data = bt.feeds.PandasData(dataname=dataframe)
      cerebro.addstrategy(SmaCross)
      cerebro.run()
      cerebro.plot()
      

      Gives me the output:

      
        File "<ipython-input-28-82fff6a4d3c7>", line 34, in <module>
          cerebro.plot()
      
        File "/anaconda/lib/python3.6/site-packages/backtrader/cerebro.py", line 978, in plot
          if self._exactbars > 0:
      
      AttributeError: 'Cerebro' object has no attribute '_exactbars' 
      

      Where do I go or do wrong?

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

        @fbleaux said in 'Cerebro' object has no attribute '_exactbars' [pandas/.csv]:

        data = bt.feeds.PandasData(dataname=dataframe)
        cerebro.addstrategy(SmaCross)
        cerebro.run()
        

        That's a bug not triggered ever before. But due to an obvious user code bug in those 3 lines.

        • The data has not been added to the system, neither directly with adddata nor indirectly with other methods like resampledata, replaydata and some others.
        1 Reply Last reply Reply Quote 2
        • fbleaux
          fbleaux last edited by

          How could I miss that. Thank you.

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