Navigation

    Backtrader Community

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/

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

    General Code/Help
    3
    4
    408
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • A
      avys last edited by

      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].datetime.date(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
      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?
      Thanks
      Avy

      1 Reply Last reply Reply Quote 0
      • J
        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..

        1 Reply Last reply Reply Quote 1
        • A
          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....
          Avy

          1 Reply Last reply Reply Quote 0
          • frontline
            frontline last edited by

            Experiencing the same issue. For some Python/Matplotlib versions the issue seems to be triggered by bt.observers.Trades - see https://community.backtrader.com/topic/3310/recommended-python-version-plotting-issues-on-3-8-5/2

            This is NOT a memory issue.

            1 Reply Last reply Reply Quote 0
            • 1 / 1
            • First post
              Last post
            Copyright © 2016, 2017, 2018, 2019, 2020, 2021 NodeBB Forums | Contributors