Member-only story

Faster Backtesting With An Index Trick (Algorithmic Trading)

Andy Kong
8 min readOct 23, 2023

--

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+.

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…

--

--

Andy Kong
Andy Kong

Responses (3)