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

KeyError: '__restricted__'

  • I am trying to load data into cerebro, and the data is in the form of a pandas dataframe.

    import pandas as pd
    import backtrader as bt 
    import backtrader.feeds as btfeeds
    df = pd.read_csv('csvfile.csv', index_col=0)
    df['datetime'] = pd.to_datetime(df['datetime'])
    data = PandasData(dataname=df)
    cerebro = bt.Cerebro()
    class PandasData(btfeeds.PandasData):
    	params = (
    	datafields = [
            'datetime', 'open', 'high', 'low', 'close', 'volume'
    class TestStrategy(bt.Strategy):
    	def log(self, txt, dt=None):
    		dt = dt or self.datas[0]
    		print('%s, %s' % (dt.isoformat(), txt))		
    	def __init__(self):
    		self.ma10 = bt.talib.SMA(, 10)
    	def next(self):
    		if > self.ma10:
    			self.log('Close, %.2f' % self.dataclose[0])
    		elif < self.ma10:
    			self.log('Close, %.2f' % self.dataclose[0])

    I have looked up the community for answers but I did not manage to find a solution to this error:

    File "/controllers/", line 10, in index
        data = PandasData(dataname=df)
    File "/modules/backtrader/", line 86, in __call__
        _obj, args, kwargs = cls.donew(*args, **kwargs)
    File "/modules/backtrader/", line 419, in donew
        _obj, args, kwargs = super(MetaLineSeries, cls).donew(*args, **kwargs)
    File "/modules/backtrader/", line 48, in donew
        _obj, args, kwargs = super(MetaLineRoot, cls).donew(*args, **kwargs)
    File "/modules/backtrader/", line 244, in donew
        clsmod = sys.modules[cls.__module__]
    KeyError: '__restricted__'

    Kindly advise. Thank you!

Log in to reply