Why my backtest took a long time to complete?

To explain the possible reasons, I will explain using this (hopefully) simple analogy. Let’s say you are standing at starting line. Standing between you and the finish line are X amount of tables, where X is the number of candles between start and end of your backtest. That means longer backtest timerange gonna give you longer completion time.

Before you move to the first table, you need to prepare for the tools (calculate indicators) needed for you to complete the future tasks. This means more indicators and/or more timeframes would give you longer completion time.

Next, on each tables, there are Y amount of books, where Y is the number of pairs. On each table, you need to complete the tasks on all the books on that table before you move to the next table. That means more pairs gonna give you longer completion time.

On each books, you need to complete several tasks.

  • If you don’t have open trade for that pair, check for entry. More entry logics means more time needed to complete the check. If no entry signal triggered for that table, or there is colliding signal, move to the next book.
  • If you have open trade for that pair, check for exit signals, which means check the exit_long/short signal, roi, stoploss, custom_exit and custom_stoploss. You would also need to check for position adjustment (extra entries and/or partial exits). This means more exit logics and/or position adjustment would give you longer completion time.

So a long completion time is result of several possible causes. You would need to debug yourself and see which are the causes in your case. Possible causes are

  • Too many indicators (cause lags at the start of backtest)
  • Too many pairs (usual cause)
  • Too wide of timerange (personally, you must use a wide timerange)
  • Too many entry logics (rarely a problem imo)
  • Long average trade durations coupled with plenty of custom_exit/stoploss logics (usual cause)

One comment

Leave a Reply

Your email address will not be published. Required fields are marked *