Bug: cerebro.py generating a type error when importing data.
iHustling last edited by iHustling
Whenever I try to add my own generic CSV data to my code, I get an error:
Starting Portfolio Value: 10000.00 Traceback (most recent call last): File "<ipython-input-17-d193ded4a7a8>", line 1, in <module> runfile('/Users/developer/SleeplessCrossover/Sleeplessv1.1.py', wdir='/Users/developer/SleeplessCrossover') File "/anaconda3/lib/python3.7/site-packages/spyder_kernels/customize/spydercustomize.py", line 786, in runfile execfile(filename, namespace) File "/anaconda3/lib/python3.7/site-packages/spyder_kernels/customize/spydercustomize.py", line 110, in execfile exec(compile(f.read(), filename, 'exec'), namespace) File "/Users/developer/SleeplessCrossover/Sleeplessv1.1.py", line 93, in <module> cerebro.run() File "/anaconda3/lib/python3.7/site-packages/backtrader/cerebro.py", line 1127, in run runstrat = self.runstrategies(iterstrat) File "/anaconda3/lib/python3.7/site-packages/backtrader/cerebro.py", line 1217, in runstrategies strat = stratcls(*sargs, **skwargs) TypeError: 'str' object is not callable
If you guys want to see my strategy, here it is:
# Create Cerebro instance if __name__ == '__main__': # Create a Cerebro identity cerebro = bt.Cerebro() # Add a strategy to cerebro cerebro.addstrategy('SleeplessCrossover') data = btfeeds.GenericCSVData( dataname='BTCUSDT.csv', fromdate=dt.datetime(2019, 3, 23), todate=dt.datetime(2019, 4, 12), nullvalue=0.0, datetime=0, high=2, low=3, open=1, close=4, volume=5, openinterest=-1 ) print('Starting Portfolio Value: %.2f' % cerebro.broker.getvalue()) cerebro.adddata(data) cerebro.run() print('Final Portfolio Value: %.2f' % cerebro.broker.getvalue())
Edit: I finally found the issue. It wasn't importing the data, it was me adding a strategy as a string that caused the issue. What I don't understand is, when the cerebro.addstrategy() function does not have a string as an argument I get an error saying there's no variable called SleeplessCrossover.
ab_trader last edited by
What I don't understand is, when the cerebro.addstrategy() function does not have a string as an argument I get an error saying there's no variable called SleeplessCrossover
If you use only the script you posted here, than there is no such variable (no strategy) in the script.
You may want to read Quickstart first to figure out how
btworks and what should be in the script.