Backtesting 101

Towards informed trading strategies

Keno Leon
9 min readJun 15, 2023


What is backtesting ?

Let’s say you have a “hunch” or theory on investing. While we’ll talk about stocks here, it could be anything (commodities, FX, Pokémons, you name it). You then “execute” your theory by buying, holding, or selling your chosen investments, and… you lose your money! Or worse, you make some money without knowing why !

— — — — — — — — — — — ⭐️ SUBSCRIBE TO MEDIUM ! ⭐️ — — — — — — — — — — —

If only you could have “tested” your strategy in the past (hence the “back” in backtesting), so you could have avoided ruin, found a winning strategy (which is very hard to do), or speak coherently about a strategy (that strategy only works under such and such circumstances). Backtesting allows you to do all this and more.”

Why I am writing this ?
This post falls into a bit of a niche category, but since I am currently
learning about backtesting myself, I wanted to share my insights.
I couldn't find much information on the topic, as trading tends
to be either highly secretive, elitist, and confusing, or presented
by scammy characters.

Why you should read this ?
I assume you have an interest in finance and/or trading and may want
to develop your own strategies or even a custom backtesting pipeline.
However, on a broader level, if you want to make sense of the present
and, perhaps, even forecast the future by examining the past,
this should be of interest to you.

Past performance is not necessarily indicative of future results.
It's important to remember that there is no guarantee
that what worked in the past will work in the future. Unknown unknowns
can and will derail your investing plans, so caveat emptor.
This is not investment advice; it's just a friendly reminder. Yada, yada.


To get started you will need both a trading/investing strategy and historical data related to your chosen instruments and strategy, by necessity we need to start simple, so I’ll use the SPX ( S&P 500) and the ETF that tracks it, the SPY ( ie what you would buy/hold/sell in your execution).

I’ll be using Python which has become the standard ( besides excel ! ) for financial coding, so the first order of business is collecting and plotting…