I Let the Future Leak Into the Past

There was a backtest result, early on, that was so good it should have made me happy. Instead, after a few minutes of staring at it, it made me deeply uneasy. The profits in the simulation were large, smooth, and far too clean — the kind of performance that does not happen in a real, noisy, adversarial market. And the reason it did not happen in a real market is that my test, quietly and without my noticing, could see the future.

Not on purpose. I had not written if you know what happens next, cheat. The future had leaked into the past through a dozen tiny, innocent-looking seams, and every one of them was rewarding my system for a kind of clairvoyance it would never, ever have when real money was on the line.

The most seductive bug in backtesting

The general name for this is look-ahead bias, or leakage. It happens whenever a decision in your simulation is allowed to use information that, in real life, would not have existed yet at the moment the decision was made.

This is worth sitting with, because it is more subtle than it sounds. A backtest is supposed to be a faithful re-enactment of history: at each moment, the system may only know what was actually knowable at that moment, and it must act using only that. Leakage is any crack in that wall — any place where a sliver of tomorrow’s information slips into today’s decision. And the moment it does, your backtest stops measuring “how would this have done” and starts measuring “how would this do if it could peek.”

How the future sneaks in

I want to be careful here not to describe the specifics of my own system, so let me keep this at the level of the general shapes these leaks take, because they are remarkably common.

One classic form: using a value in a decision that was only actually finalized after the moment you are pretending to decide. Another: preparing your data by scaling or normalizing it using statistics — an average, a range, a typical size — computed over the entire history, including the portion that, at your simulated moment, had not happened yet. Another: filtering or labeling your data with the benefit of hindsight, quietly excluding cases in a way you could only do if you already knew how they turned out.

Each of these is a single, reasonable-looking line of code. None of them feels like cheating while you write it. And every one of them hands your system a small, steady stream of information from the future.

Why it is so hard to catch

The cruelest thing about leakage is that it does not look like a bug. The code runs without error. Nothing crashes. And the result it produces is not a warning sign — it is a great number. Great numbers do not trigger suspicion in most people. They trigger celebration, a screenshot, a quiet sense that you might be onto something.

That is exactly what makes this class of bug so dangerous. It hides inside results that look like success, which is the single worst place for a bug to hide, because success is the one outcome you are least motivated to interrogate. A crash demands to be fixed. A beautiful equity curve invites you to stop looking.

The tell: results too good to be true

For a long time, the only reliable alarm I had was my own incredulity. When a backtest comes back dramatically better than anything you could reasonably expect — smoother, more profitable, more consistent than the market has any right to allow — the correct first hypothesis is not “I have found something brilliant.” It is “information is leaking somewhere, and I need to find it.”

This is a genuinely useful prior, and I have come to hold it strongly: in a backtest, excellence is far more often a symptom of a bug than evidence of an edge. The market is hard. Results that suggest it is easy are usually telling you about your code, not about the market.

Finding the leaks

The actual work of hunting leakage is tedious and entirely unglamorous, and there is no clever shortcut I have found that replaces it. The discipline is this: take every single value that feeds into a decision, and trace it backward to the precise moment it would have become known in real life. Then ask, plainly, “at the instant I am pretending to act, could I genuinely have had this number yet?”

Most leaks, when you finally corner them, turn out to be one timestamp’s worth of cheating — a value used a moment before it would truly have existed, a calculation that reached one step further into the data than it was allowed to. Small seams. But a small seam, repeated across thousands of decisions, is enough to manufacture an entire imaginary fortune.

The deeper principle: respect the arrow of time

Underneath all of this is a single principle that I now treat as close to sacred: respect the arrow of time. A backtest is, in essence, a promise — a promise that you only ever used the past to act in the present, never the future. Every leak is a small broken promise, a place where your code quietly reached forward in time to help itself.

So building a trustworthy simulation turned out to be much less about clever modeling and much more about defending a boundary: the line between what was known at a moment and what was merely knowable later. Most of the engineering effort, the part nobody writes admiring threads about, is just guarding that boundary against your own code’s constant, casual tendency to peek.

Why I now distrust my best results

The lasting change from all this was that my relationship to good news inverted. A disappointing backtest is just disappointing; I look at it, shrug, and move on. A spectacular one now makes me nervous before it makes me happy. The better the result, the harder I go looking for the leak that produced it.

It sounds joyless, and sometimes it is. But it comes from a hard-won respect for how this particular game punishes self-deception. The most dangerous lies a system will ever tell you are not the ugly failures. They are the gorgeous successes — the ones that look exactly like the thing you were hoping to find, and for that reason are the last ones you think to doubt.

— No signals, no returns, not investment advice.