NewTurn any lesson into a live trading bot with one prompt, using AgenKitagenkit.xyz

Part 2 · StatisticsLesson 710 minQuant Bible §3.2

Confidence intervals

What “95% confident” really promises, watched across a hundred repeated experiments.

An estimate without an error bar is half an answer. A confidence interval says what range the true parameter plausibly lies in, and it is also how traders are asked to quote: “give me a 90% interval for the number of windows in this building.”

Definition

A confidence interval of level 1−α1-\alpha for a parameter θ\theta is a random interval I\mathcal I, computed from the data, with

Pθ(I∋θ)  ≥  1−αfor every possible θ.P_\theta\big(\mathcal I \ni \theta\big) \;\ge\; 1 - \alpha \qquad \text{for every possible } \theta .

Careful with the wording. The interval is random; the parameter is fixed. “95% confidence” is a property of the procedure: if you repeated the experiment many times, about 95% of the intervals you built would contain θ\theta. A single interval either does or doesn’t.

Building one from the CLT

The estimator is usually an average, so its centre comes from the LLN and its width from the CLT. With qα/2q_{\alpha/2} the (1−α/2)(1-\alpha/2) quantile of N(0,1)\mathcal N(0,1) (1.645 for 90%, 1.96 for 95%, 2.576 for 99%):

I=[θ^−qα/2 σn,    θ^+qα/2 σn].\mathcal I = \Big[\hat\theta - \frac{q_{\alpha/2}\,\sigma}{\sqrt n},\;\; \hat\theta + \frac{q_{\alpha/2}\,\sigma}{\sqrt n}\Big].

There is a catch: σ\sigma usually depends on the unknown parameter. For a Bernoulli, σ=p(1−p)\sigma = \sqrt{p(1-p)}. Two standard fixes:

  • Conservative bound. p(1−p)≤14p(1-p) \le \tfrac14 always, so p^±qα/22n\hat p \pm \dfrac{q_{\alpha/2}}{2\sqrt n} is valid whatever pp is. It is a little too wide.
  • Plug-in (Slutsky’s theorem). Replace pp by p^\hat p inside the variance: p^±qα/2p^(1−p^)/n\hat p \pm q_{\alpha/2}\sqrt{\hat p(1-\hat p)/n}. Slutsky says the CLT still holds asymptotically after this swap.
Figure 7.1Coverage machine
The truth is p = 0.55. Each horizontal line is an interval built from a fresh sample of n flips; red ones miss. Draw batches and the cumulative coverage settles near the level you chose. Small n with the plug-in method undercovers a little; the conservative method overcovers.

Intervals on a trading floor

In interviews, an interval is your honesty about uncertainty. Ask for a 95% interval on a normal quantity with mean 100 and sd 10 and the answer is about 80 to 120 (±2σ). Ask for one on “the number of windows in this building” and there is no formula: your interval should be wider when you know less, and still realistic. “Between 0 and a billion” contains the truth and is useless, exactly like a market that is 0 @ 1 billion (lesson 17).

In code

import numpy as np
from scipy import stats
rng = np.random.default_rng(5)

p, n, level = 0.55, 50, 0.95
q = stats.norm.ppf(1 - (1 - level) / 2)          # 1.96

hits = 0
for _ in range(10_000):
    ph = rng.binomial(n, p) / n
    half = q * np.sqrt(ph * (1 - ph) / n)        # plug-in (Slutsky)
    hits += (ph - half <= p <= ph + half)
print(hits / 10_000)                              # ≈ 0.94: slightly under 95% at n = 50

Check yourself

A 95% confidence interval for a strategy’s mean daily return is [0.01%, 0.09%]. Which statement is correct?

Progress is saved in this browser only.