Backtests : Separating luck from skill

Introduction

In our previous post, we say that, when running a screen it shows the stocks that pass our current filters. But how do we distinguish between whether using that same approach with the same criteria would have really worked in the past, or was just a result of luck and repetition from trying many rules till we found a winner?

First let’s see what role luck even has here. Imagine the Texas Sharpshooter fallacy: A sharpshooter fires multiple shots at a barn, before walking up, painting a target ring around the densest cluster of holes and calling himself a master. This is our first mistake: peeking at results and then choosing rules does not give accurate results.

Another mistake occurs when we only study the companies that still exist, also called survivorship bias. This same scenario occurred during World War II, when military analysts of the Allied forces studied returning bomber planes to identify which areas had to be reinforced with armour. Naturally, they settled on the spots with the most bullet holes, namely the wings, fuselage and tails. However, they made a crucial mistake, as pointed out by statistician Abraham Wald: They were only considering the planes that had returned, meaning planes could take damage in these spots and still fly. On the contrary, planes that had been hit in other areas (such as the engines, fuel tanks and cockpits) didn’t survive and make it back, making those the areas that actually needed reinforcing.

Similar mistakes are prone to occur when we run screeners, making backtests a verification requirement. Let’s see how they work.

A backtest works by replaying the filtering criteria we have using past data, in order to model what stocks would have passed if the same screen had been run at that date using data only available at the time. This allows us to see how a screener would have performed in the past without actually risking capital. It also follows those stocks through the years to see what they earned compared to the market.

A backtest can be broken into 3 steps: Collecting past data, running the screen on the data and analysing the results. Each step is deceptively hard, which I experienced when I tried to build my own backtest model.

For the first step, this involved collecting past data. I used Trendlyne, for which I already had a paid subscription, to rewind to the end of September of each year from 2012 to 2025. The data for each year comprises a list of passers, which I downloaded as a csv. However, the limits imposed by the rewind tool in Trendlyne capped my export data, allowing me to collect only the data of stocks that passed and not all stocks in the stock universe at a given date. Data collection mistakes such as mislabelling a September 2016 data file as 2026 and having mismatching columns did occur, but they were luckily fixed during the data check.

The principal risk we face here when collecting data is survivorship bias. This comes mainly in the form of not counting firms that had been delisted, merged or become insolvent. However, since whether or not Trendlyne drops delisted firms hasn’t been established, this will have to be checked by counting how many firms known to be delisted have appeared in earlier lists. This will be hard to do completely due to the lack of complete data on delisted firms.

Just like Abraham Wald and his discovery, the Texas sharpshooter fallacy and luck are traps for our other steps in similar ways, which we will cover next.

Glossary

Backtest : A model that tests rules on past data to see how it would have performed.
Benchmark : A stock index or or standard you use to compare your stocks against (eg: Nifty 50, S&P 500).
Excess return : Portfolio’s return – benchmark’s return ( the excess amount you earn from your screen with respect to how much you would have earned had you just invested the same amount in a stock index.)
CSV : Comma separated values, a plain text file format where tabular data is stored with comma separators.
Delisting : Permanently removing stocks of a listed company from a stock exchange.

Note: This is a learning project, not investment advice.