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/

    Stopping or pausing a backtest

    General Discussion
    2
    5
    793
    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.
    • T
      tw00000 last edited by

      Is it possible to stop or pause a backtest run, whether opt_runs or otherwise early and retain the data?

      My indicators can be a little slow (machine learning) and so backtesting even just 5,000 lines (with no optimization) takes about 5 hours. Sometimes it would be nice to stop this run early (or better yet - pause it so it can be restarted!) and then save the results and take a look at it.

      Anybody know if this is possible?

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

        Nothing prevents you from doing whatever you want inside the next method, like giving control to something else.

        T 1 Reply Last reply Reply Quote 0
        • T
          tw00000 @backtrader last edited by

          @backtrader said in Stopping or pausing a backtest:

          Nothing prevents you from doing whatever you want inside the next method, like giving control to something else.

          OK, so I'm in the middle of a very long opt_runs which has been going for a few days now. I would like to stop it so I can do some tweaks and move it to a cloud server.

          How can I pause it or stop it but still have access to what the best parameters (so far) are?

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

            If you have no provisions in place already in your code, Python is not prepared out of the box to stop execution. (There may be some magic hack in the net, but I don't know if it does exist and if it does, how well it works)

            1 Reply Last reply Reply Quote 0
            • T
              tw00000 last edited by tw00000

              One useful thing could be to dump some pickles at some interval.

              Something like:

              
              def notify_trade(self, trade):
                      date = self.data.datetime.datetime()
                      if trade.isclosed:
              
                          sr_file = open('pickled_opt_runs_{}'.format(sharperatio_analyzer_object), 'wb')
                          sqn_file = open('pickled_opt_runs_{}'.format(sqn_analyzer_object), 'wb')
              
                          pickle.dump(opt_runs, file)
                          pickle.dump(opt_runs, file)
              
                          sr_file()
                          sqn_file()
              
              1 Reply Last reply Reply Quote 0
              • 1 / 1
              • First post
                Last post
              Copyright © 2016, 2017, 2018, 2019, 2020, 2021 NodeBB Forums | Contributors