FeaturesLearnNISMGalleryFaqPricingAboutWeb Terminal (Desktop & iOS)Get Mobile App
Algorithmic Trading 101: Strategies, Backtesting & Risk Management
πŸ“š Course Β· 10 chaptersIntermediate 3.5 hours

Algorithmic Trading 101: Strategies, Backtesting & Risk Management

A practitioner-oriented course covering the core building blocks of systematic trading: how to backtest without fooling yourself, the statistics behind mean-reversion and momentum strategies, and how to size positions and manage risk so a good strategy doesn't blow up your account.

Algorithmic Trading

Course Syllabus

4 / 10
Chapter 4 of 10

Chapter 4: The Statistics of Mean Reversion

4/10

Chapter 4: The Statistics of Mean Reversion

So far in this course, we've focused on process β€” how to backtest honestly (Chapter 1), how to know if a result is statistically real (Chapter 2), and how to build the right infrastructure (Chapter 3). Starting with this chapter, we shift to strategy β€” and specifically, to the first of the two great families of trading strategies covered in this course: mean reversion.

Mean reversion is the intuitive idea that when a price strays too far from its 'normal' level, it tends to drift back. Buy low, sell high. It sounds simple β€” almost too simple to need an entire chapter of statistics. But here's the catch: most price series are not actually mean-reverting. Most stocks, most indices, most currency pairs behave like a random walk β€” wandering without any pull back toward a fixed center. If you build a mean-reversion strategy on a series that doesn't actually mean-revert, you are not trading an edge; you are gambling with extra steps.

This chapter gives you the statistical toolkit to answer one essential question before you risk a single rupee: does this price series actually mean-revert, and if so, how strongly and how quickly?

Why this chapter matters: Every mean-reversion strategy in this course β€” Bollinger bands, pairs trading, cross-sectional reversal β€” rests on the assumption that the underlying series (or a combination of series) is genuinely mean-reverting. Skipping this statistical foundation is how traders end up 'catching a falling knife' repeatedly, mistaking a trending stock for a mean-reverting one.


1. Random Walks vs. Mean-Reverting Series

The Random Walk

A random walk is a price series where each day's change is independent of the past β€” today's move tells you nothing about tomorrow's direction. Over time, its uncertainty (variance) grows linearly with time. Most individual stock prices β€” think of Reliance Industries or Infosys over a multi-year window β€” behave much closer to a random walk than to a mean-reverting series. Once they move to a new level, they tend to stay there (or keep drifting), rather than snapping back to some fixed anchor price.

The Mean-Reverting Series

A mean-reverting (or stationary) series, by contrast, has a pull back toward a central value. Mathematically, the expected change in price is proportional to the distance between the current price and its long-run mean: the further away the price has strayed, the stronger the expected pull back.

Classic Example: Consider the spread between the prices of two very similar PSU banks, say State Bank of India (SBI) and Bank of Baroda (BOB). Individually, both stock prices behave close to random walks, drifting up or down over years. But if their businesses are similarly exposed to the same macro forces (interest rates, credit growth, NPA cycles), the difference between their prices β€” or more precisely, a specific weighted combination of the two β€” might behave in a far more mean-reverting way than either stock alone. This is the seed idea behind pairs trading, which we'll formalize later in this chapter as cointegration.

Important distinction: Don't confuse mean reversion of prices with mean reversion of returns. Daily returns of almost any stock β€” Nifty included β€” tend to randomly scatter around a small average value close to zero. That is completely different from the price itself reverting to a fixed level. We cannot trade on 'returns reverting to their average' directly β€” what we need is genuine mean reversion (or cointegration) in the price series itself.

A side-by-side line chart comparison titled 'Random Walk vs. Mean-Reverting Series', with the left panel labeled 'Reliance Industries Stock Price (2019-2024)' showing a wandering, trending price line that drifts to new highs and lows without returning to a fixed level, and the right panel labeled 'SBI-BOB Weighted Price Spread (2019-2024)' showing a choppy, range-bound line that repeatedly oscillates around a flat horizontal dashed 'mean' line
πŸ“· A side-by-side line chart comparison titled 'Random Walk vs. Mean-Reverting Series', with the left panel labeled 'Reliance Industries Stock Price (2019-2024)' showing a wandering, trending price line that drifts to new highs and lows without returning to a fixed level, and the right panel labeled 'SBI-BOB Weighted Price Spread (2019-2024)' showing a choppy, range-bound line that repeatedly oscillates around a flat horizontal dashed 'mean' line

2. Stationarity: The Formal Statistical Property

Stationarity is the formal statistical concept underlying mean reversion. A price series is called stationary if its statistical properties β€” particularly, how fast its uncertainty grows over time β€” don't behave like a random walk.

For a pure random walk, the variance of the price change over a time interval grows linearly with that interval β€” wait twice as long, and the typical range of price movement grows by roughly the square root of 2. For a stationary series, this growth in variance is slower than linear β€” the price is, in a sense, held back by its tendency to revert.

This distinction gives rise to two complementary families of statistical tests:

  • Tests based directly on the mean-reversion equation (does the next price change depend on the current distance from the mean?) β€” the Augmented Dickey-Fuller (ADF) test.
  • Tests based on how quickly variance grows with time β€” the Hurst exponent and the related Variance Ratio test.

Both approaches examine the same underlying phenomenon from different mathematical angles, and in practice, traders often check both for confirmation.


3. The Augmented Dickey-Fuller (ADF) Test

The Intuition

The ADF test asks a very direct question: does today's price level help predict tomorrow's price change? If a series is mean-reverting, then when the price is above its long-run mean, the next move should tend to be downward β€” and when it's below the mean, the next move should tend to be upward.

The test works by running a regression of the day-to-day price change against the current price level. If the resulting coefficient is reliably negative, it means higher-than-average price levels are indeed followed by downward moves (and vice versa) β€” evidence of mean reversion. If this coefficient is statistically indistinguishable from zero, the series behaves like a random walk.

Reading the Result

The ADF test produces a test statistic, which is compared against known critical values (much like the hypothesis testing framework from Chapter 2) to determine a confidence level β€” commonly 90%, 95%, or 99%.

Classic Example: Suppose you run the ADF test on the USD/INR exchange rate over a multi-year window. Because the Reserve Bank of India actively manages currency volatility and the rupee's long-run trajectory has historically drifted (rather than oscillating around a truly fixed level), you would likely find the ADF test statistic falls short of the 90% confidence threshold β€” meaning we cannot confidently reject the possibility that USD/INR behaves like a random walk (with a mild drift) rather than a genuinely mean-reverting series. This doesn't mean currency trading is hopeless β€” it simply means a naive 'buy the dip in the rupee' style mean-reversion strategy on the raw USD/INR rate alone lacks strong statistical backing.

Note & Warning: A negative ADF coefficient that still fails to clear the 90% or 95% confidence bar doesn't necessarily mean you should throw the idea away entirely. It often means the mean-reverting tendency exists but is weak, slow, or partially obscured by trending noise β€” which is exactly why we look at a second, complementary measure: the half-life (Section 5), which tells us whether a weak-but-real mean reversion could still be practically tradable.


4. The Hurst Exponent and Variance Ratio Test

What the Hurst Exponent Measures

The Hurst exponent (H) measures how a price series' variance grows over different time lags, giving a single number that characterizes the series' overall 'personality':

  • H = 0.5 β†’ the series behaves like a pure random walk (variance grows exactly linearly with time).
  • H < 0.5 β†’ the series is mean-reverting β€” variance grows more slowly than a random walk, because deviations tend to get pulled back.
  • H > 0.5 β†’ the series is trending β€” variance grows faster than a random walk, because moves tend to be followed by more moves in the same direction (a form of momentum, the subject of a later chapter).

The closer H is to 0, the more strongly mean-reverting the series; the closer H is to 1, the more strongly trending.

Classic Example: If you calculated the Hurst exponent for Nifty 50's daily closing price over a long historical window, you would very likely find a value close to 0.5 β€” consistent with the broad market index behaving approximately like a random walk with a long-term upward drift, which is exactly what we'd expect from a diversified, growing economy's benchmark index. This is precisely why a simple 'sell high, buy low' contrarian strategy on the raw Nifty index level, without any other edge, tends not to be reliably profitable β€” the index itself doesn't have a strong enough mean-reverting personality to exploit directly.

The Variance Ratio Test

Because any estimated Hurst exponent from a finite historical sample carries some uncertainty (remember the sample-size lessons from Chapter 2), the Variance Ratio test provides the formal hypothesis test: it checks whether an estimated H is statistically distinguishable from exactly 0.5, given the amount of data available, and reports a confidence level (or p-value) just like the ADF test does.

A conceptual number line titled 'The Hurst Exponent Spectrum', ranging from 0 to 1, with the zone from 0 to 0.5 shaded blue and labeled 'Mean-Reverting (e.g., a well-chosen stock pair spread)', the point at exactly 0.5 marked with a dashed line labeled 'Random Walk (e.g., Nifty 50 index level)', and the zone from 0.5 to 1 shaded orange and labeled 'Trending / Momentum (e.g., a stock in a strong sustained uptrend)'
πŸ“· A conceptual number line titled 'The Hurst Exponent Spectrum', ranging from 0 to 1, with the zone from 0 to 0.5 shaded blue and labeled 'Mean-Reverting (e.g., a well-chosen stock pair spread)', the point at exactly 0.5 marked with a dashed line labeled 'Random Walk (e.g., Nifty 50 index level)', and the zone from 0.5 to 1 shaded orange and labeled 'Trending / Momentum (e.g., a stock in a strong sustained uptrend)'

5. Half-Life of Mean Reversion: The Practical Trader's Metric

Why We Need It

Both the ADF test and the Variance Ratio test demand fairly high statistical confidence (often 90% or above) before declaring a series 'officially' mean-reverting. But in real trading, you don't necessarily need textbook-level statistical proof β€” you need a series that reverts often enough and fast enough to generate profitable round-trip trades within a reasonable time frame.

This is where half-life comes in: a direct, practical measure of how long it takes a price deviation to shrink back by half, derived from the same mean-reversion regression coefficient used in the ADF test.

Why Half-Life Matters for Strategy Design

  • If the regression coefficient is positive (rather than negative), the series is not mean-reverting at all β€” don't build a mean-reversion strategy on it, regardless of what any single backtest might suggest.
  • If half-life is very long (say, several hundred trading days), the series may be technically mean-reverting, but so slowly that you won't complete enough round-trip trades in a practical time frame to generate meaningful profit β€” capital would sit tied up for a long time between entries and exits.
  • If half-life is short and reasonable (say, 5 to 20 trading days), the series is a strong candidate for an actively tradable mean-reversion strategy.

Classic Example: Suppose you calculate a half-life of roughly 12 trading days for a well-constructed spread between two large private-sector banks, such as a weighted combination of HDFC Bank and ICICI Bank prices. This tells you two extremely useful things: first, that a mean-reversion strategy on this spread has a realistic chance of generating frequent round-trip trades over a typical month; and second β€” critically β€” it tells you what look-back window to use for your moving average and standard deviation calculations in your trading rule. As a rule of thumb, using a look-back period set to roughly the half-life itself (rather than an arbitrarily chosen number like '20 days' or '50 days') gives you a principled, non-arbitrary parameter choice β€” directly helping you avoid the data-snooping bias trap from Chapter 1, where you'd otherwise be tempted to try dozens of look-back values until one happened to backtest well.

Note: Half-life doesn't just apply to single price series β€” it applies equally well to the spread of a cointegrated pair or basket, which is usually the more practically useful application, as we'll see next.


6. Cointegration: Manufacturing Mean Reversion

The Core Idea

Here's the pivotal insight of this chapter: even though very few individual price series are truly stationary, we can often combine two or more non-stationary series into a single portfolio whose combined value IS stationary. This is the concept of cointegration, and it is the mathematical foundation of classic pairs trading.

Classic Example: Individually, Titan Company (a major consumer jewelry retailer, heavily exposed to gold prices) and a Gold ETF (tracking domestic gold prices) each behave close to random walks over time β€” both can trend up or down for extended periods based on entirely different combinations of factors (consumer demand, import duties, global gold prices, company-specific execution). But because Titan's core business economics are structurally linked to gold prices, a carefully weighted combination β€” long a certain quantity of the Gold ETF, short a certain quantity of Titan shares (or vice versa, depending on the relationship) β€” might produce a spread that behaves in a far more mean-reverting way than either instrument alone. If we can find the right weighting (called the hedge ratio), we've effectively manufactured a stationary, tradable series out of two non-stationary ones.

This is a genuinely powerful idea: instead of being limited to the handful of 'naturally' mean-reverting price series that exist in the market, cointegration lets us construct as many candidate mean-reverting portfolios as we can find sensible economic relationships to test.

Testing for Cointegration: The CADF Test

The Cointegrated Augmented Dickey-Fuller (CADF) test extends the ADF test to a pair of price series. The process:

  1. Run a regression between the two price series to estimate the optimal hedge ratio β€” how many units of one instrument to hold per unit of the other.
  2. Construct the resulting spread (or residual) series using that hedge ratio.
  3. Run the standard ADF test on this spread series to check whether it's stationary.

Warning: The CADF test is not symmetric β€” the hedge ratio (and the resulting test result) can differ depending on which of the two instruments you treat as the 'independent' variable in the regression. In practice, this means testing the pair both ways (Gold ETF regressed on Titan, and Titan regressed on Gold ETF) and using whichever ordering gives the stronger (more statistically significant) result.

Testing for Cointegration Among Three or More Instruments: The Johansen Test

When you want to test whether three or more instruments together form a stationary combination β€” for example, a basket combining a Gold ETF, Titan, and a jewelry sector peer β€” the two-instrument CADF test isn't sufficient. The Johansen test generalizes this idea to any number of instruments, and as a useful byproduct, it directly hands you the optimal weightings (hedge ratios) for each instrument in the basket, along with a ranking of how quickly each possible combination reverts to its mean.

A scatter plot titled 'Cointegration Illustrated β€” Gold ETF vs. Titan Company', with the x-axis labeled 'Gold ETF Price' and y-axis labeled 'Titan Company Share Price', showing a tight cluster of data points falling close to a single upward-sloping straight regression line, with a small inset panel below showing the resulting 'spread' (residual distance from the line) as a separate time-series chart that oscillates in a clearly range-bound, mean-reverting pattern around a horizontal dashed mean line
πŸ“· A scatter plot titled 'Cointegration Illustrated β€” Gold ETF vs. Titan Company', with the x-axis labeled 'Gold ETF Price' and y-axis labeled 'Titan Company Share Price', showing a tight cluster of data points falling close to a single upward-sloping straight regression line, with a small inset panel below showing the resulting 'spread' (residual distance from the line) as a separate time-series chart that oscillates in a clearly range-bound, mean-reverting pattern around a horizontal dashed mean line

7. Putting It All Together: A Practical Screening Workflow

Before committing to build a full mean-reversion trading strategy (which we'll cover in the next chapter), use this statistical screening workflow to decide whether a series or pair is even worth pursuing:

  1. Single series? Run the ADF test. If the confidence level is reasonably high (ideally 90%+), proceed. If not, don't discard the idea immediately β€” check the Hurst exponent and half-life too, since a series can be weakly mean-reverting without clearing a strict ADF threshold.
  2. Pair of series? Run the CADF test in both directions and use the stronger result. Confirm using a scatter plot β€” do the two prices visually track a consistent linear relationship over time, or does the relationship appear to drift and break down?
  3. Three or more series? Use the Johansen test to identify which combinations (if any) are cointegrated, and extract the suggested hedge ratios.
  4. In all cases, calculate the half-life. A statistically significant but very slow-reverting series (half-life of 200+ trading days) is a poor practical trading candidate, even if it technically 'passes' the formal tests.
  5. Sanity-check the economic rationale. Does the relationship make fundamental sense? A gold-linked jewelry stock cointegrating with a gold ETF has a clear, durable economic story. Two randomly chosen, economically unrelated stocks that happen to show a statistically significant cointegration relationship in a five-year backtest are a classic data-snooping trap (see Chapter 1) β€” the relationship is far more likely to break down out-of-sample.

Golden Rule: Statistical tests tell you whether a relationship existed historically. They cannot tell you why β€” and without a plausible economic 'why', a cointegration result found by testing hundreds of random pairs is far more likely to be noise than a durable, tradable relationship.


8. Key Takeaways

  • Most individual price series β€” including most single stocks and broad indices like Nifty 50 β€” behave close to a random walk, not a mean-reverting series, which is why naive contrarian strategies on raw prices often underperform.
  • Stationarity is the formal property underlying mean reversion: a stationary series' variance grows more slowly over time than a random walk's.
  • The ADF test directly checks whether a price change depends on the current distance from the mean; a reliably negative, statistically significant coefficient signals mean reversion.
  • The Hurst exponent characterizes a series' overall tendency: below 0.5 signals mean reversion, exactly 0.5 signals a random walk, and above 0.5 signals trending/momentum behavior; the Variance Ratio test provides the formal significance check.
  • Half-life is often the most practically useful metric β€” it tells you how quickly deviations shrink, helps you judge whether a series reverts fast enough to trade profitably, and gives you a principled, non-arbitrary look-back window for your trading rules.
  • Cointegration lets you manufacture mean-reverting behavior from two or more individually non-stationary series β€” the statistical foundation of pairs and basket trading. The CADF test handles pairs; the Johansen test generalizes to three or more instruments and directly yields hedge ratios.
  • Always pair statistical significance with a plausible economic rationale β€” a cointegration relationship with no underlying business logic is a strong candidate for data-snooping bias.

Coming up in Chapter 5: Now that we can identify genuinely mean-reverting series and pairs, we'll turn statistics into strategy β€” building practical, risk-bounded mean-reversion trading rules using Bollinger bands, exploring the scaling-in technique, and introducing the Kalman filter as a way to dynamically update hedge ratios as market relationships evolve over time.

Chapter 4: The Statistics of Mean Reversion | Algorithmic Trading 101: Strategies, Backtesting & Risk Management - TradeKaizen