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

cerebro.plot() ValueError: Maximum allowed size exceeded error

  • Hello,
    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!

    my code:

    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[0]
            print('%s, %s' % (dt.isoformat(), txt))
        def __init__(self):
            # Keep a reference to the "close" line in the data[0] dataseries
            self.dataclose = self.datas[0].close
        def next(self):
            # Simply log the closing price of the series from the reference
            self.log('Close, %.2f' % self.dataclose[0])
    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  # run it all
    print('Final Portfolio Value: %.2f' %
    cerebro.plot(style='candlestick', barup='green', bardown='red')  # and plot it with a single command

    Any help/idea what I'm doing wring?

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

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

Log in to reply