edgekit

Order statistics & extremes

Sort a sample and every position in the sorted list becomes a random variable with its own distribution: the minimum, the maximum, the median, the second-highest bid in an auction, the best-looking strategy out of fifty. Order statistics are the calculus of ranked randomness — and because trading constantly selects extremes (best backtest, worst drawdown, record high), their distributions are the honest answer to “how good should the best one look by luck alone?” This chapter derives the k-th order statistic’s distribution, the Beta law for uniforms, the probability integral transform, the growth of Gaussian maxima, records, and the German tank problem.

Intuition — the maximum is a biased estimator of quality

Ask fifty coin-flippers to flip twenty times each and the best of them will get around fifteen heads — not because anyone is skilled, but because you selected the maximum. The maximum of draws is pushed into the tail by construction, and its distribution tells you exactly how far. Everything in this chapter is a version of that one calculation, and the punchline for quants is uncomfortable: the expected best of zero-edge strategies grows like — slowly, but never zero. Selection is a source of apparent performance.

The distribution of the k-th order statistic#

Let be i.i.d. with CDF and density , and let be the sorted values. The key observation is a counting one: the event happens exactly when at least of the draws land at or below . The number that do is Binomial(), so

The two ends are the cases to know cold — they need no summation:

Proof sketch — the density of the k-th order statistic

Differentiating the sum works but is messy. The direct argument: for to land in the sliver , one draw must fall in the sliver (probability ), exactly must fall below (probability ), and the remaining above (probability ). The number of ways to assign draws to the three roles is the multinomial coefficient . Multiply:

(Two draws in the sliver has probability of order — negligible. This “one here, count the rest” pattern is the same combinatorial move as stars and bars, and it is worth being able to reproduce it from scratch in one line.)

Worked example (by hand). Three independent draws. Probability the maximum is below 0.9: . Probability the minimum exceeds 0.5: . Density of the maximum: , so . The maximum of three uniforms sits, on average, three-quarters of the way up — each extra draw pushes the record closer to 1, but with diminishing returns.

Uniform order statistics — the Beta law and spacings#

For uniforms, on and the general density specialises to something famous. Substituting into the boxed density:

This is the Beta distribution’s origin story (see the distribution zoo): Beta() is the law of the -th smallest of uniforms. From the Beta mean :

The slick symmetry argument for k/(n+1)

No integration needed: uniform points cut into spacings. By symmetry (exchangeability of the gaps — rotate the circle obtained by gluing 0 to 1), all spacings have the same distribution, and they sum to 1, so each has expectation . Then is the sum of the first spacings: . The sorted uniforms sit, on average, at perfectly even quantile positions — this is why p-p plots and plotting positions work. Each single spacing is , i.e. — for large , approximately exponential with rate , the bridge to Poisson-process interarrivals.

Beta densities of the order statistics of uniform samples, showing the minimum, median, and maximum densities peaking at evenly spaced positions
Densities of the order statistics of n uniforms: X_(k) ~ Beta(k, n+1-k). The minimum and maximum hug the edges, the median peaks in the centre, and the means line up at the even quantile positions k/(n+1). Sorting turns one flat distribution into a fan of sharply located ones.

The range follows immediately: . Ten uniform draws span, on average, of the interval.

The probability integral transform#

One theorem explains why uniforms are the universal currency of simulation and of p-values.

Proof — F(X) is uniform, and F⁻¹(U) has law F

Let have a continuous, strictly increasing CDF , and set . For any ,

which is exactly the CDF. Conversely, if then , so has CDF . (For general , use the generalised inverse ; the second statement survives untouched.)

Two consequences. Simulation: to sample any distribution, sample a uniform and push it through — the inverse-transform method of Monte Carlo. Inference: a p-value is for a test statistic with null CDF , so under the null the p-value is exactly Uniform(0,1) — the fact that makes p-value thresholds meaningful and multiple-testing corrections computable (multiple testing & paradoxes).

How big is the maximum? Gaussian extremes#

For uniforms the maximum crawls toward the endpoint. For unbounded distributions the question is how fast the maximum grows, and for Gaussians there is a clean, classic answer.

Heuristic derivation — E[max] of n standard normals ≈ √(2 ln n)

The maximum of draws sits near the level that a single draw exceeds about once in tries — i.e. solve . Using the Gaussian tail approximation , take logs of :

The correction terms are negative and decay slowly, so overstates the mean at practical (see the table) — but the growth rate is right, and the qualitative fact is the one to internalise: the max of Gaussians grows only logarithmically. Doubling your number of tries barely moves the record; and fluctuations of the max stay — the max concentrates. The full limit theory (Gumbel, Fréchet, Weibull) is in extreme value theory.

n√(2 ln n)E[max] (exact/simulated)
102.151.54
1003.032.51
1,0003.723.24
1,000,0005.264.86
Expected maximum of n standard normal draws plotted against n on a log scale, growing like the square root of two log n, with the asymptote drawn above the exact curve
The expected maximum of n standard normals grows like sqrt(2 ln n) — painfully slowly, with the asymptote (upper curve) approached from below. Selection inflates the best observation, but only logarithmically: the 1000th strategy you try moves the luck ceiling far less than the 10th did.
Quant lens — the best backtest of N is a max, not a mean

Test independent zero-edge strategies and each produces a roughly Gaussian Sharpe t-stat. The best one is the max of Gaussians: expected value standard errors — about 2.1 for , 3.0 for . So “our best strategy has t = 3” is the expected outcome of trying a hundred random ones. This is the mathematical core of data snooping, the deflated Sharpe ratio, and the reason overfitting detectionasks “how many did you try?” before it asks anything else. Same math, different market: the winning bid in an auction and the highest-water-mark fund in a database are maxima too — both flattered by exactly this amount.

Records — 1/n by pure symmetry#

Observation sets a record if it exceeds all before it: .

Proof — P(record at n) = 1/n, and E[# records] = H_n

Among the exchangeable draws (i.i.d., continuous so no ties), each is equally likely to be the largest, so — no calculation, pure symmetry. With indicator variables and linearity of expectation (the workhorse of random variables & moments):

A century of annual data yields expected records — record heat, record volume, record drawdown are frequent under pure randomness, and (a lovely deeper fact) the record indicators are mutually independent. When a desk celebrates a “record month,” the base-rate question is , not zero.

The German tank problem#

Order statistics power one of the great applied-statistics war stories. Serial numbers with unknown; you capture tanks — a sample without replacement — and observe maximum serial . The maximum alone is the sufficient statistic, but itself is biased low (the max of a sample never exceeds, and rarely equals, the max of the population). The expected gap above should equal the average spacing: the observed serials cut into nearly-equal gaps, so roughly — solving gives the unbiased (indeed UMVU) estimator

Worked example. Five captured tanks, highest serial 60: . Read the second form: take the observed max and add the average observed gap () — the sample’s own spacing estimates how far beyond the sample the population extends. In WWII this estimator put German tank production near 270/month while intelligence guessed 1,400; records later showed 276. The same logic prices “how many competitors are in this trade” from the sparse ones you can see.

order_stats_check.py
import numpy as np

rng = np.random.default_rng(11)
reps = 100_000

# 1) k-th order statistic of uniforms is Beta(k, n+1-k): check k=2, n=5
u = np.sort(rng.random(size=(reps, 5)), axis=1)
x2 = u[:, 1]                                   # X_(2) of n=5 -> Beta(2, 4)
print(f"X_(2) of 5 uniforms: mean={x2.mean():.4f} (theory 2/6={2/6:.4f}), "
      f"var={x2.var():.5f} (theory {2*4/(6**2*7):.5f})")

# 2) E[max of n normals] vs the sqrt(2 ln n) asymptote
for n in (10, 100, 1000):
    mx = rng.standard_normal(size=(20_000, n)).max(axis=1)
    print(f"n={n:5d}  E[max]={mx.mean():.3f}   sqrt(2 ln n)={np.sqrt(2*np.log(n)):.3f}")

# 3) Records: expected count in n draws = H_n = 1 + 1/2 + ... + 1/n
n = 100
x = rng.standard_normal(size=(reps, n))
records = (x >= np.maximum.accumulate(x, axis=1)).sum(axis=1)
print(f"records in {n} draws: {records.mean():.3f}  (H_100 = {sum(1/i for i in range(1, n+1)):.3f})")

Practice problems#

Problem 1 — expected max of two (and three) uniforms

independent. Find ; then for three uniforms.

Solution. Systematic: , density , so ; for three, . Slick: by the spacings symmetry, , giving and instantly — and the general answer for the max of . Worth adding unprompted: , and by the symmetry — a one-line sanity check worth making a habit.

Problem 2 — expected number of records

You observe 100 i.i.d. yearly returns. How many record years (each beating all previous) do you expect? Why does the answer not depend on the return distribution?

Solution. Record at year has probability — among exchangeable continuous draws, each is equally likely to be largest, so the distribution cancels out entirely. By linearity of expectation over the indicators (dependence irrelevant): . About five record years per century — logarithmic growth, so records keep arriving forever, just ever more rarely. Follow-up they like: the probability year 100 itself is a record is exactly , distribution-free — the cleanest nonparametric test statistic there is.

Problem 3 — broken stick, triangle

Break a unit stick at two points chosen uniformly at random. What is the probability the three pieces form a triangle?

Solution. Let the cut points be (the order statistics of two uniforms); pieces are . A triangle exists iff every piece is shorter than (each side must be beaten by the other two summing past it). In the unit square the failure regions — some piece — carve out three corner triangles of total area , leaving

Fast symmetry version: the three “a piece exceeds ½” events are disjoint and each has probability (both cuts must land in the same half-stick region), so the failure probability is . Classic enough that the escalation — “break the longer piece again instead” — should be expected; the machinery is identical, only the conditioning changes.

Problem 4 — the second-highest bid

bidders draw private values i.i.d. . In a second-price auction (winner pays the second-highest value), what revenue does the seller expect?

Solution. Truthful bidding is dominant in a second-price auction, so revenue is the second order statistic from the top: , hence

Two bidders: ; five: ; the gap to the highest value — the winner’s information rent — is exactly one average spacing, , shrinking as competition thickens. The market intuition transfers directly to order books: the spread you pay crossing to the best quote behaves like a top spacing, and it tightens as the number of competing quotes grows.

Problem 5 — the median of three uniforms

Three i.i.d. draws. Find the distribution, mean, and variance of the median.

Solution. with is : density — an inverted parabola peaking at . Mean by symmetry (or ); variance from the Beta formula . Compare a single draw: variance . The median of three is a better estimator of the centre than one draw (variance down 40%) yet uses no arithmetic on the values — the germ of robust statistics, and of why median-based statistics resist outliers that wreck means.

Next: from sorted randomness to sequential randomness — fair games, stopping rules, and the theorem that says no exit strategy can beat a game with no edge: Martingales & optional stopping.