Quant500 Academy

6. Data snooping and p-hacking: overfitting with a proper statistical name

Level 6: Hypothesis testing and its traps in backtesting

You move the backtest start date a few months. Now it does come out significant.

Nobody has lied, nobody has falsified a data point and the backtest engine is impeccable, but the result is now worth absolutely nothing.

The market theory course already introduced overfitting intuitively: a strategy too closely fitted to its particular history, which collapses as soon as it faces new data.

The previous module gave you the exact statistical mechanism explaining why testing many variants generates false "winners" almost by guarantee. This module names, precisely, the process that produces that outcome, sometimes deliberate and sometimes not: data snooping and p-hacking.

Data snooping: the same data for both jobs

Data snooping consists of using the same dataset, repeatedly and exploratorily, for two jobs at once:

And here is the underlying problem. The logic of a hypothesis test assumes the hypothesis was fixed before looking at the data that will be used to put it to the test.

When it is the data itself that suggested the hypothesis, that logic breaks down completely.

The resulting p-value is emptied of any real meaning, because in essence you searched, among many possibilities, for exactly the pattern that was going to score well on that particular sample, which is almost a self-fulfilling prophecy.

P-hacking: the active version

P-hacking is the more active, and sometimes more conscious, version of the same thing. It consists of adjusting the shape of the analysis until the p-value crosses the "significant" line, and then stopping and presenting that particular version as if it were the only analysis performed.

The available adjustments are far more numerous than they seem:

Tactics that show up constantly

It is worth listing concrete p-hacking tactics that show up constantly in amateur backtests, because recognizing them is half the work of avoiding them:

Where legitimate research ends

This practice must be clearly separated from legitimate iterative research, because the boundary matters: exploring, trying things and refining ideas is completely normal and necessary.

What turns that exploration into data snooping or p-hacking is two very specific things:

The garden of forking paths

There is also a more subtle and unintentional version of this problem, known colloquially as "the garden of forking paths".

Even a single researcher, acting in complete good faith, on a single dataset, makes dozens of small and seemingly reasonable decisions throughout the analysis:

Since for each of those decisions there are several equally defensible alternatives, the researcher ends up exploring, unknowingly and with no bad intent whatsoever, a hidden space of multiple comparisons.

That is why data snooping can creep even into the work of careful and honest people.

The antidote, in four steps

The antidote has a concrete structure, which extends the previous module's out-of-sample validation with more procedural discipline:

That last point deserves a sentence of its own, because your own enthusiasm is not evidence. It is usually precisely the warning sign that you should look more closely, not less.

Honest data is not the same as an honest process

One last important clarification for the quant500 context remains, and it is worth reading slowly.

Using an honest backtest engine, built on point-in-time data with no look-ahead bias, eliminates look-ahead bias. But it does not on its own protect you from data snooping.

You can perfectly well data-snoop on a perfectly honest dataset if you iterate and adjust repeatedly against the same historical sample over and over.

The honesty of the data and the honesty of the search process are two different problems, and both have to be solved.

The rest of Quant500

What you are learning, applied to the index every day:

The model portfolio, weekly in your inbox

Every Saturday, its week in one minute: how it went, the best and the worst, and which insiders bought with their own money. Plus, the day the model is rebuilt, which stocks come in and which go out. A simulation, not advice. At most one email a week, no ads, no account; one-click unsubscribe. Made by one person: Pol Gracia.

A model portfolio with simulated results, not a personalized recommendation. Your email is used for this only: privacy.

Behind the Academy and the rest of Quant500 there is one person: Pol Gracia Serrahima.