cerebro.plot() ValueError: Maximum allowed size exceeded error
avys last edited by
I'm trying just to plot the candles, and get bombed by a "ValueError: Maximum allowed size exceeded" out of cerebro.plot().
same code with strategy that actually byes and sells plots just fine!
from datetime import datetime import backtrader as bt class testStrategy(bt.Strategy): def log(self, txt, dt=None): ''' Logging function for this strategy''' dt = dt or self.datas.datetime.date(0) print('%s, %s' % (dt.isoformat(), txt)) def __init__(self): # Keep a reference to the "close" line in the data dataseries self.dataclose = self.datas.close def next(self): # Simply log the closing price of the series from the reference self.log('Close, %.2f' % self.dataclose) cerebro = bt.Cerebro() # create a "Cerebro" engine instance # Create a data feed data = bt.feeds.YahooFinanceData(dataname='MSFT', fromdate=datetime(2011, 1, 1), todate=datetime(2011, 1, 31)) cerebro.adddata(data) # Add the data feed cerebro.addstrategy(testStrategy) # Add the trading strategy cerebro.run() # run it all print('Final Portfolio Value: %.2f' % cerebro.broker.getvalue()) cerebro.plot(style='candlestick', barup='green', bardown='red') # and plot it with a single command
Any help/idea what I'm doing wring?
jay last edited by
I can run that code without issues on cli and on ipython nb. that error typically means something does not fit in memory allocated for it. it could be an array exceeding the size or you system running out of memory. I would test in a different machine or update to latest python version etc..
avys last edited by
Thanks. Forgot to mention - I'm using PyCharm.
The funny thing it that the code breaks only when there is no single completed transaction (i.e. no self.buy() and self.sell() in the strategy). Adding even a single transaction that is getting executed 'cures' the problem. This is a 'poor man's workaround' I'm now using....