# Stationarity & Efficiency Tests

Also known as: ADF/KPSS, variance-ratio, random-walk benchmark.
A Statistics reference entry (Relationships) in the LuxAlgo Library: explained, not implemented as a chart indicator.

## What are Stationarity & Efficiency Tests?

Stationarity and efficiency tests ask two related questions of a series: do its statistical properties (mean, variance) stay stable through time, and does the series follow a random walk, with returns that carry no usable memory? Unit-root tests answer the first. The augmented Dickey-Fuller (ADF) test takes non-stationarity (a unit root) as its null hypothesis, so rejection is evidence of stationarity, mean-reverting behavior in trading terms; the KPSS test flips the logic and takes stationarity as its null. Efficiency tests answer the second: the variance-ratio test compares the variance of k-period returns to k times the one-period variance, which are equal under a random walk. Ratios persistently below one point toward mean reversion, above one toward trending behavior.

The machinery comes from econometrics: Dickey and Fuller published the unit-root test in 1979 (the augmented version handles serial correlation), Kwiatkowski, Phillips, Schmidt, and Shin proposed the KPSS test in 1992 as the complementary null, and Lo and MacKinlay's 1988 variance-ratio study formalized the random-walk benchmark, finding that weekly US stock returns of that era did not follow one. Trading platforms later compressed these procedures into rolling indicator-pane studies.

Traders use these tests as regime instruments. Mean-reversion logic (fading a [z-score](https://www.luxalgo.com/library/concept/z-score/), trading a pairs spread) presumes the traded series is roughly stationary, which raw price levels usually are not; spreads built through cointegration are candidates precisely because a stationary combination is the goal. Rolling versions of ADF, KPSS, or variance ratios are plotted as trend-versus-reversion gauges alongside measures such as the Hurst exponent, [fractal dimension](https://www.luxalgo.com/library/concept/fractal-dimension/), and [autocorrelation](https://www.luxalgo.com/library/concept/autocorrelation/).

The caveats are substantial: the tests have limited power in short windows, verdicts flip with lag and window choices, structural breaks masquerade as unit roots, and repeated rolling inference invites false positives. Above all, stationarity measured in the past is a description, not a contract; regimes end, and a test confirms the change only after enough post-change data accumulates. Treated as a probabilistic tilt rather than a switch, though, the tests give quantitative structure to a question every strategy silently answers: is this market trending, reverting, or indistinguishable from noise?

## How to read a rolling stationarity test on a chart

Platform implementations plot a windowed statistic below price; reading one takes a few checks.

1. Confirm what is being tested: raw prices are almost never stationary, so useful inputs are spreads, residuals after detrending, oscillator values, or returns.
2. Locate the statistic against its critical values: a rolling ADF statistic more negative than its critical line argues for stationarity in that window, while a rolling KPSS statistic above its critical line argues against it.
3. Check persistence: a verdict that holds across consecutive windows and survives a modest lookback change deserves weight; a one-bar excursion across a critical line does not.
4. Cross-check with an independent measure, such as a variance ratio or an [entropy measure](https://www.luxalgo.com/library/concept/entropy-measures/), before switching playbooks on the strength of a single test.

## How it's calculated

Statistical checks of whether a price series is stationary or carries a unit root, and whether its returns deviate from a random walk.

```
ADF regression: y_t - y_(t-1) = alpha + gamma × y_(t-1) + Σ_(i=1..p) c_i × (y_(t-i) - y_(t-i-1)) + e_t
ADF statistic = t-ratio of the estimated gamma; the unit-root null gamma = 0 is rejected when the statistic is more negative than the critical value
KPSS statistic = Σ_(t=1..T) S_t^2 / (T^2 × lrv)
VR(q) = Var(y_t - y_(t-q)) / (q × Var(y_t - y_(t-1)))
Random-walk benchmark: VR(q) = 1; VR(q) < 1 leans mean reversion, VR(q) > 1 leans trend persistence

  y_t: log price at bar t (y_(t-1), y_(t-i), y_(t-i-1), y_(t-q) are earlier values)
  alpha: intercept of the ADF regression
  gamma: coefficient on the lagged level; gamma = 0 means a unit root (nonstationary)
  c_i: coefficient on the i-th lagged difference
  p: number of augmenting lags (commonly chosen by AIC or BIC)
  e_t: ADF regression error at bar t
  S_t: partial sum through bar t of the residuals from regressing y on an intercept (include a trend to test trend stationarity)
  T: number of observations
  lrv: long-run variance of the level-regression residuals (Newey-West estimate)
  VR(q): variance ratio at return horizon q
  q: return horizon in bars (commonly 2 to 16)
  Var(): sample variance
  t: bar index
  i: lag or summation index
```

ADF and KPSS have opposite nulls, so they are read together: ADF rejecting while KPSS does not is the cleanest stationarity verdict.

Both tests use nonstandard critical values (Dickey-Fuller and KPSS tables), and the values change when a trend term is included.

The variance ratio follows Lo and MacKinlay, usually estimated on overlapping log returns with heteroskedasticity-robust z-statistics.

## How traders use it

- Gating mean reversion: run a rolling ADF (or KPSS) on a spread or detrended series and allow reversion entries only while the test favors stationarity, standing aside when the spread starts behaving like a random walk.
- Regime classification: a rolling variance ratio above one supports momentum tactics, below one supports fading extremes; many workflows require agreement with an independent regime measure before switching playbooks.
- Input validation: checking that series fed to statistical or machine-learning models (returns, spreads, oscillator inputs) are approximately stationary, since many estimators, from [linear regression](https://www.luxalgo.com/library/concept/linear-regression/) forecasts to [exponential smoothing](https://www.luxalgo.com/library/concept/exponential-smoothing-forecasts/), quietly assume it.
- Benchmarking against randomness: variance ratios locate a market relative to the random-walk baseline that [Monte Carlo price paths](https://www.luxalgo.com/library/concept/monte-carlo-price-paths/) and [probability cones](https://www.luxalgo.com/library/concept/probability-cones/) simulate forward; a market that tests as efficient argues against pattern edges.
- Pair selection: screening candidates by running ADF on the fitted spread, keeping combinations that stay stationary out of the formation window, and re-testing periodically since relationships decay.

## Stationarity & efficiency tests vs. related measures

- **Autocorrelation** (https://www.luxalgo.com/library/concept/autocorrelation/): Autocorrelation measures memory at specific lags; unit-root and variance-ratio tests aggregate that memory into a single verdict about the series' overall character. The tests are the hypothesis-testing layer on top of what the correlogram shows.
- **Fractal Dimension** (https://www.luxalgo.com/library/concept/fractal-dimension/): Fractal dimension (and the related Hurst exponent) grades trendiness on a continuous scale without a significance framework; ADF and KPSS give verdicts against critical values. Regime dashboards often plot one of each.
- **Entropy Measures** (https://www.luxalgo.com/library/concept/entropy-measures/): Entropy asks how unpredictable the sequence of moves is without assuming a linear model; variance-ratio and unit-root tests are linear-model statistics. A series can look linearly efficient yet carry low-entropy structure, so disagreements between the two are informative.

## FAQ

### What is the difference between the ADF and KPSS tests?

Their null hypotheses are opposite. ADF assumes a unit root (non-stationary), and rejection argues for stationarity; KPSS assumes stationarity, and rejection argues for a unit root. Used together they form a cross-check: ADF rejecting while KPSS does not is the strongest stationary verdict, the reverse is the strongest non-stationary verdict, and mixed outcomes (both rejecting, or neither) point to short samples, structural breaks, or a series near the boundary between the two.

### What does a variance ratio below one mean?

Multi-period return variance is growing more slowly than a random walk predicts, which is the statistical footprint of mean reversion: part of each move tends to be given back. A ratio above one indicates positive autocorrelation, consistent with trending. Both readings are estimates with sampling error, so small windows produce noisy ratios, and most implementations test whether the deviation from one is statistically significant.

### Why can't I run an ADF test on raw prices?

You can, but the answer is nearly always the same: price levels behave like integrated, random-walk-style series, so the test fails to reject and carries no information. Informative uses test something with a plausible claim to stability: a hedged spread, the residual after removing a fitted trend (from a [polynomial regression](https://www.luxalgo.com/library/concept/polynomial-regression/), for example), or a bounded oscillator series.

### How much data do stationarity tests need?

More than most chart windows provide. Unit-root tests have low power in small samples, frequently failing to reject even when the process is genuinely stationary but slowly reverting. Rolling windows of several hundred bars are common, verdicts from shorter windows deserve heavy discounting, and the calendar span matters as much as the bar count.

### What does it mean if a market tests as efficient?

Only that the specific statistic finds no exploitable linear structure at the tested horizons. It does not rule out nonlinear structure, conditional patterns tied to session or volatility state, or edges in other data entirely, and verdicts are horizon-specific: daily and intraday sampling of the same market can disagree.

## Related concepts

- Correlation: https://www.luxalgo.com/library/concept/correlation/
- Beta: https://www.luxalgo.com/library/concept/beta/
- Alpha: https://www.luxalgo.com/library/concept/alpha/
- Autocorrelation: https://www.luxalgo.com/library/concept/autocorrelation/
- Lead-lag Detection: https://www.luxalgo.com/library/concept/lead-lag-detection/
- Cointegration: https://www.luxalgo.com/library/concept/cointegration/
- Pairs Trading Stack: https://www.luxalgo.com/library/concept/pairs-trading-stack/

---

Source: https://www.luxalgo.com/library/concept/stationarity-and-efficiency-tests/ (LuxAlgo Library, the encyclopedia of trading & technical analysis). Free to use with attribution: https://www.luxalgo.com/library/license/