Multi-threaded Backtesting in Python

Chad-Thackray

Multi-threaded Backtesting in Python by Chad-Thackray

The video demonstrates how to use multi-processing in Python to speed up backtesting. The presenter explains how most Python programs are single-threaded but with the multi-processing module, it is possible to run several back tests at once resulting in significant performance improvement. The implementation of multi-processing is straightforward and the presenter shares a sample backtester using the backtesting.py module to run a simple RSI crossover strategy. He illustrates how to run the backtest function in parallel using multi-processing and shows how it is much faster than doing it serially. The presenter advises being cautious when running multi-processing on different platforms and environments and recommends guarding significant code with an if name equals main statement to avoid changes in backtesting results.

00:00:00

In this section of the video, the presenter explains how using the multi-processing module in Python can help run back tests in parallel and improve performance significantly. By default, most Python programs are single-threaded, but with the multi-processing module, it is possible to run several back tests at once, which can result in a factor of 8 or 16 improvement in performance on modern processors with 8 or 16 threads. The presenter also explains that the implementation of multi-processing is straightforward with only around ten lines of code, making it simple to integrate into any custom or off-the-shelf back testing system. The presenter shares a sample back tester that uses backtesting.py to run a simple RSI crossover strategy and illustrates how to run the back test function in parallel using the multi-processing module.

00:05:00

In this section, the video presenter demonstrates how to use multi-processing in Python to speed up backtesting. After creating a pool of processes, the presenter uses the "p.map()" function to apply the backtesting function to a list of file names for the data sets. The presenter shows how to print the file names and the results of the backtesting function for each file. The multi-processing approach is much faster than the serial approach, with eight seconds for the full backtest when using multi-processing compared to 32 seconds when doing it serially. The presenter also shows how to fix an issue with the "map()" function when taking in more than one variable by switching to "star map()" and passing in a list of iterables.

00:10:00

In this section, the presenter demonstrates how to run a function with multiple parameters using zip. He also discusses the max tasks per child parameter and how setting it to none could cause worker processes to continue consuming more memory, making it slower than doing things serially. Lastly, he advises being cautious when running multi-processing on different platforms and environments as it may behave differently and recommends keeping significant code guarded by an if name equals main statement to avoid possible changes in backtesting results.

More from
Chad-Thackray

No videos found.

Related Videos

No related videos found.

Trending
AI Music

No music found.