Building & Backtesting It in TEPLab
Objectives
- Translate a falsifiable directional thesis into an explicit signal rule in the TEPLab formula engine, with the entry, exit, and holding period fixed in advance.
- Run a point-in-time backtest that obeys the no-look-ahead rule, and read the resulting equity curve and per-trade record as evidence rather than as a verdict.
- Defend a backtest against the three failures that fake an edge — look-ahead, survivorship, and overfitting — and state the out-of-sample test that would falsify your thesis.
In the last chapter you wrote down a thesis you could be wrong about. That sentence — a clean, falsifiable claim that some observable condition is genuine evidence an asset will move — is the whole point of the capstone. Now you have to make it bleed, because a thesis you cannot test is just a feeling with good grammar.
This chapter is about the machinery that tests it: the TEPLab formula engine, which turns your sentence into a rule, and the backtest engine, which marches that rule through history and writes down what would have happened. Let us build the intuition before we touch a single formula.
A backtest is a simulation of your strategy against the past. You take a rule — buy when this signal fires, hold for some period, then exit — and you replay it across years of data as if you had been trading it the whole time. At the end you have an equity curve, the running record of what one unit of capital would have become, and a ledger of every individual trade. The promise is seductive: history is the one dataset where you already know the answer. The danger is exactly the same thing — because if you are not disciplined, the past will tell you whatever you went looking for.
So the first move in TEPLab is to write the thesis as a formula, and the discipline starts there. In the formula engine you do not describe a chart you remember; you write an expression that evaluates on each bar using only information available on that bar. Your signal is a boolean — true or false — built from primitives the engine exposes: the return series, a moving average, a z-score of some indicator, a volatility estimate, a skew reading pulled from the SVQ surface. The rule might read: signal is true when the twenty-day z-score of realized-minus-implied volatility falls below negative one. That is it. The engine demands you state the entry condition, the exit condition, and the holding period before it will run anything, which is the platform quietly forcing you to commit to a hypothesis instead of discovering one mid-flight.
Now the single most important word in this entire course: point-in-time. When the backtest engine evaluates your formula on the bar dated, say, the third of March, it is allowed to use only data that existed at the close of the third of March. Not the fourth. Not a revised data point that was published a week later. Not a moving average that secretly includes tomorrow. This is the no-look-ahead rule, and violating it is the most common way a worthless strategy looks brilliant. If your signal can peek even one bar into the future, your equity curve will soar, and it will mean absolutely nothing. TEPLab enforces the boundary for you by feeding the formula a strictly expanding window, but you must understand why it exists, because the subtler look-ahead leaks — using a closing price to decide a trade you claim to enter at that same close, or using a statistic computed over the full sample — are ones you can still write by accident.
Once the rule runs cleanly, you read the output as evidence, not as a verdict. The equity curve tells you the shape of the bet — smooth and grinding, or lumpy and dependent on three lucky months. The trade ledger tells you the honest detail: how many trades, the win rate, the average win against the average loss, the worst drawdown you would have had to sit through. A strategy that made money on four trades has told you nothing; a strategy that made money on four hundred, with a drawdown you could actually have survived, is starting to look like evidence. This is the throughline of the whole institute restated in the language of strategy: you are deciding whether a number is genuine evidence an asset will move, and a single equity curve, by itself, is weak evidence until it survives interrogation.
That interrogation has three named enemies. The first is look-ahead, which we have met. The second is survivorship bias — backtesting only on the assets that still exist today, which silently deletes every company that went to zero and inflates your result by hiding the losers. The third, and the one that will get you, is overfitting. Give yourself enough parameters — a threshold here, a lookback there, a filter to skip the bad months — and you can fit any past perfectly. You have not found a signal; you have memorized the noise. The defense is brutal and simple. You split your history. You build and tune on an in-sample segment, and you hold an out-of-sample segment that your eyes never touch until the rule is frozen. The strategy's performance on that untouched data is the only number that counts as evidence. Everything else is rehearsal.
That is what makes this a falsification exercise rather than a fishing trip. You are not running the backtest to find a strategy that works. You are running it to give your already-stated thesis a fair chance to fail.
Open TEPLab and write your thesis as a signal in the formula engine. Suppose your chapter-one thesis was that a deeply positive variance-risk-premium reading — implied volatility rich relative to realized — precedes a short-volatility opportunity. You encode the entry as a boolean — true when the twenty-day z-score of realized-minus-implied vol drops below negative one — set the exit to a fixed ten-trading-day hold, and press run. The backtest engine replays it point-in-time across the sample and returns an equity curve plus the full trade ledger: ninety-one trades, a fifty-eight percent win rate, average win one-point-three times the average loss, worst drawdown eleven percent. Now reserve the most recent two years as out-of-sample, retune nothing, and run again. If the out-of-sample curve holds its shape, you have evidence. If it collapses, the formula engine just saved you from trading your own overfitting — which is exactly what it is for.
Build it in TEPLab. State your chapter-one thesis as a single boolean entry condition, a single exit condition, and a fixed holding period — no free parameters added after you have seen the result. Hypothesis: the strategy's risk-adjusted return on a held-out, point-in-time out-of-sample window is statistically indistinguishable from the in-sample window. Falsify it: tune only on the in-sample segment, freeze the rule, then run once on the untouched out-of-sample data. If the out-of-sample Sharpe collapses toward zero while the in-sample Sharpe stayed high, you have not found an edge — you have found an overfit, and your thesis is rejected.