Quant Memo
Core

The Kolmogorov-Smirnov Test

A test that compares two entire distributions at once — a sample against a reference, or two samples against each other — by finding the single largest vertical gap between their cumulative distribution curves.

Prerequisites: The Empirical Distribution Function, Hypothesis Testing

You've fit a normal distribution to a year of daily returns and want to know: does the data actually look normal, or is that assumption going to bite you in the tails? Or you've backtested two versions of a strategy and want to know if their trade-return distributions genuinely differ, not just their means. Both questions are really the same question in disguise: are two distributions — one empirical, one theoretical or empirical — the same, or meaningfully different? The Kolmogorov-Smirnov (KS) test compares two entire cumulative distribution curves at once, rather than reducing each to a single summary number like a mean or variance first.

An analogy: overlaying two staircases

Picture the empirical distribution function (see The Empirical Distribution Function) of your data as a staircase, and the theoretical distribution you're testing against as a smooth curve — or, for a two-sample test, a second staircase from a different dataset. Lay one directly on top of the other and find the single point where they're vertically furthest apart. If that biggest gap is small, the two curves hug each other closely everywhere, meaning the distributions are similar across their entire range, not just on average. If the gap is large, somewhere along the range one distribution has noticeably more (or less) mass below a point than the other — and the test turns "how large is too large" into a precise probability statement.

The idea, one symbol at a time

The KS statistic for comparing an empirical CDF F^n(x)\hat{F}_n(x) to a reference CDF F0(x)F_0(x) is

Dn=supxF^n(x)F0(x),D_n = \sup_x \left| \hat{F}_n(x) - F_0(x) \right|,

the largest absolute vertical distance between the two curves over all xx. In plain English: check every possible threshold xx, measure how far off your empirical distribution is from the reference distribution at that threshold, and DnD_n is the single worst-case gap. For two samples, the two-sample version replaces F0F_0 with a second empirical CDF F^m\hat{F}_m. Under the null hypothesis that the sample really is drawn from F0F_0 (or that both samples share a common distribution), DnD_n has a known distribution — and critically, one that does not depend on the shape of F0F_0 itself (a property called distribution-free), which lets a single table of critical values work for testing against any reference distribution, normal, exponential, or otherwise.

Worked example 1: a five-point normality check by hand

Suppose 5 sorted, standardized daily returns (mean 0, sd 1): 1.8,0.4,0.1,0.6,1.3-1.8, -0.4, 0.1, 0.6, 1.3. The ECDF steps up at 0.2,0.4,0.6,0.8,1.00.2, 0.4, 0.6, 0.8, 1.0. Comparing to the standard normal CDF Φ(x)\Phi(x) at each point, checking both just-before and at each jump (since the largest gap can occur on either side): at x=1.8x=-1.8, Φ(1.8)0.036\Phi(-1.8)\approx0.036, and F^5\hat{F}_5 jumps from 0 to 0.2 there, giving gaps 0.0360.036 and 0.1640.164. Checking the remaining points similarly and taking the largest gap overall gives, say, D50.20D_5 \approx 0.20 (illustrative). With only 5 points, the 5% critical value is around 0.56, so D5=0.20D_5=0.20 is far from significant — you'd need a much bigger gap, or far more data, to reject normality.

Worked example 2: two-sample comparison of strategy returns

Now compare 100 trade returns from Strategy A against 100 from Strategy B. Suppose their empirical CDFs are close everywhere except around the median, where Strategy A's CDF sits noticeably higher (meaning A has more small/negative outcomes concentrated there) — giving a two-sample D100,100=0.18D_{100,100} = 0.18. The approximate critical value at the 5% level for two samples of size 100 each is roughly 1.361100+11000.1921.36\sqrt{\frac{1}{100}+\frac{1}{100}} \approx 0.192. With D=0.18D=0.18 just under that threshold, the test narrowly fails to reject the null of equal distributions at 5% — a close call that would flip with a slightly larger sample or a slightly bigger gap, illustrating how KS test conclusions can be sensitive right around a real difference of this size.

D = max gap sample CDF reference CDF
The KS statistic D is the single largest vertical distance between the two cumulative curves, found by scanning across every possible x — not an average gap, the worst one.
critical value (5%) observed D
Because D's null distribution is distribution-free, a single critical value works regardless of the shape of the reference distribution being tested against.

What this means in practice

The KS test is a standard goodness-of-fit check whenever you've assumed a distribution shape — testing whether return residuals really look normal before relying on formulas that assume normality, or comparing two backtests' full return distributions rather than just their Sharpe ratios. Its distribution-free property makes it convenient, but it is a blunt instrument for tail behavior specifically, since the CDFs of most distributions are close together in the tails almost by construction (both curves are near 0 or near 1 there).

The Kolmogorov-Smirnov statistic is the largest vertical gap, at any point, between two cumulative distribution curves — one empirical vs. a reference, or two empirical curves against each other. Because its null distribution doesn't depend on the shape being tested against, a single table of critical values applies to any comparison.

The KS test is most sensitive to differences near the center of the distribution (where the CDFs are steepest and small horizontal shifts translate into the largest vertical gaps) and least sensitive in the tails — exactly the region a quant usually cares most about for risk purposes. A KS test can easily fail to detect a real difference in tail heaviness between two return distributions even while correctly detecting a difference in their medians; a QQ plot (see QQ Plots) is a better tool specifically for inspecting tail fit.

Related concepts

Practice in interviews

Further reading

  • Massey, 'The Kolmogorov-Smirnov Test for Goodness of Fit', JASA
  • Conover, Practical Nonparametric Statistics, ch. 6
ShareTwitterLinkedIn