Sitemap

Faster Backtesting With An Index Trick (Algorithmic Trading)

8 min readOct 23, 2023
Press enter or click to view image in full size

Hi, I’m Andy!

In this article, I’m going to show you some code optimizations that can speed up your backtesting of trading algorithms by a factor of 10+.

Press enter or click to view image in full size

Background on Backtesting

When someone comes up with a new trading algorithm, they never deploy it immediately onto the real markets — that would be like throwing money away!

Instead, the strategy is first evaluated on historical price data to check if it actually works, and in what conditions it does well or poorly. This process is known as backtesting. Once an algorithm performs well on historical data, its parameters are typically tuned to further optimize performance, necessitating even more backtesting.

During the development and backtesting phase, ease-of-use takes precedent over speed, so most trading algorithms start their lives written and tested in Python. While Python is a fantastic language with many graphing and data science libraries, these affordances come at a hefty computational cost — Python is slow. This isn’t something you’d want when testing a trading model that uses many combinations…

--

--

Responses (3)