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



  • 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?


  • administrators

    @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.


  • How could I miss that. Thank you.


Log in to reply
 

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