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/

    Memory Error

    General Code/Help
    3
    5
    1620
    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.
    • E
      Emin Ozkan last edited by

      I saw some old posts in this topic and I was wondering if there is anything new. I have a 32GB windows 10 machine with 8 cores. The data itself is about 20 MB on a csv. My machine did about 400 optimization runs before Python crashing due to a memory error. My question is that what are some strategies to prevent a memory error? In theory I don't need anything more than a few statistics after each run, should I use a for loop?

      I had

      cerebro = bt.Cerebro(stdstats=True,optreturn=False)

      does turning off stdstats usually help?

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

        One point is to make sure to use 64bit version of python.

        1 Reply Last reply Reply Quote 0
        • E
          Emin Ozkan last edited by

          I haven't seen this page before, hopefully will hep

          https://www.backtrader.com/docu/optimization-improvements.html

          1 Reply Last reply Reply Quote 0
          • B
            backtrader administrators last edited by backtrader

            Setting stdstats=False disables the standard observers, which are mostly meant for easy visual inspection in a simple plot. Plotting in optimization scenarios doesn't really make sense (though one user wanted it)

            It is going to save some memory. Your other option is to use exactbars (Docs - Cerebro)

            But the underlying problem has a name: Python. The threading model has the GIL (Global Interpreter Lock, let's not enter into the esoterics as to why it is there), which effectively makes CPU-bound multithreading in Python a useless thing. IO-bound multithreading can still be used.

            The consequence, because you are in a CPU-bound scenario, is that the only way to profit from the cores is to use multiprocessing, which effectively means copying data back and forth, which takes time and adds to the memory usage.

            Furthermore, the only way to fully avoid running out of RAM would be to write the results to storage and discard everything.

            1 Reply Last reply Reply Quote 0
            • E
              Emin Ozkan last edited by

              Thanks a lot. Simply doing this
              cerebro = bt.Cerebro(stdstats=False,optreturn=True,optdatas=True)
              solved all of my problems. Backtrader is a powerful tool. I was able to complete 800 rounds in 2.5 hours.

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