Gaussian and Brownian Volatility Estimation
Medium · Machine Learning · Data Scientist · Technical Screen
Prompt
Address the following two parameter-estimation problems:
- Zero-mean Gaussian draws: Suppose
X_1, ..., X_100are mutually independent random variables drawn fromN(0, sigma^2), where the true mean is fixed at0whilesigma > 0is unknown. Construct a point estimator forsigma, determine whether its expectation equalssigma, and—if it is biased—derive how to adjust it so that it becomes unbiased. - Discretely sampled Brownian path: Suppose
X_t = sigma W_trepresents a driftless scaled Brownian motion starting fromX_0 = 0(withW_tdenoting standard Brownian motion) recorded at the integer timestampst = 1, 2, ..., 100. From these100observations, letH = max(X_1, ..., X_100),L = min(X_1, ..., X_100),C = X_100, andR = H - L. Examine calibrated volatility estimators formed from each of these three summary expressions:(i) |C|(ii) R - |C| / 2-
(iii) R^2 + C^2Detail how you put these three candidates on a fair comparison footing, evaluate them under Mean Squared Error (MSE), state which candidate you select and why, and explicitly declare whether your evaluation targets
sigmaorsigma^2.
Scope & Expectations
- Propose a principled estimator for
sigmaexploiting the known zero mean, test unbiasedness rigorously, and derive both the exact finite-sample debiasing multiplier and its effect on MSE. - Identify the natural parameter scale (
sigmavssigma^2) of each Brownian summary expression, calibrate expectations accurately for100discrete snapshots rather than continuous-time formulas, and align all candidates onto one common target before comparing MSE. - Use scale invariance and simulation (or analytical moments where available) to rank
(i),(ii), and(iii)by relative MSE, explain the correlation intuition behind the winner, and note how summary-bar estimators compare against using all100increments directly.
Step-by-step walkthrough
Part 1a: propose the natural estimator and check bias
Because
X_1, ..., X_100are drawn independently fromN(0, sigma^2)with a known mean of0, we do not estimate a sample meanX_barand do not divide byn - 1(Bessel'sn - 1correction only compensates for estimating an unknown mean). Every observation directly satisfiesE[X_i^2] = Var(X_i) + (E[X_i])^2 = sigma^2 + 0 = sigma^2.Averaging the squared observations gives the Maximum Likelihood Estimator (MLE) of variance, and taking its square root gives the natural MLE of
sigma:sigma2_hat = (1 / n) * sum_{i=1}^n X_i^2 -> E[sigma2_hat] = sigma^2 (unbiased for sigma^2) sigma_hat = sqrt( (1 / n) * sum_{i=1}^n X_i^2 ) -> MLE of sigma Worked check (n = 100): if sum_{i=1}^{100} X_i^2 = 400, then sigma2_hat = 4.0 and sigma_hat = 2.0.Is
sigma_hatunbiased forsigma? No — it slightly underestimatessigma! Because the functiong(y) = sqrt(y)curves downward (it is strictly concave), random upward swings insigma2_hatget compressed more than downward swings get stretched. For instance, if a random variance estimate is equally likely to be1or9(average5, truesigma = sqrt(5) = 2.236), thensqrt(1) = 1andsqrt(9) = 3average to2.000 < 2.236. Formally, Jensen's inequality states that for any non-constant positive random variableY,E[sqrt(Y)] < sqrt(E[Y]), soE[sigma_hat] < sqrt(E[sigma2_hat]) = sigma.We can compute the exact bias factor in closed form. Standardize
Z_i = X_i / sigma ~ N(0, 1). ThenS = sum_{i=1}^n Z_i^2follows a chi-square distribution withndegrees of freedom (chi^2_n), whose square root has exact expectationE[sqrt(S)] = sqrt(2) * Gamma((n + 1) / 2) / Gamma(n / 2). Writingsigma_hat = sigma * sqrt(S / n)gives:E[sigma_hat] = c_n * sigma, where c_n = sqrt(2 / n) * Gamma((n + 1) / 2) / Gamma(n / 2) For n = 100: c_100 = 0.997503 (matches the large-n expansion 1 - 1 / (4n) = 1 - 1 / 400 = 0.9975) Bias: E[sigma_hat] - sigma = -0.002497 * sigma (about -0.25%)Part 1b: debias the estimator and check its MSE trade-off
Because
c_ndepends only on the sample sizen = 100and not onsigma, dividingsigma_hatbyc_ncancels the multiplicative bias completely:sigma_unbiased = sigma_hat / c_n = 1.002503 * sigma_hat -> E[sigma_unbiased] = sigma (exact) Worked check: if sigma_hat = 2.0000, then sigma_unbiased = 2.0000 / 0.997503 = 2.0050.Compute
c_nusingmath.lgamma(log-Gamma) so largennever overflows floating-point arithmetic:from math import exp, lgamma, sqrt def bias_factor_c(n: int) -> float: """Return E[sigma_hat] / sigma for n i.i.d. N(0, sigma^2) samples.""" return sqrt(2.0 / n) * exp(lgamma((n + 1) / 2.0) - lgamma(n / 2.0)) c_100 = bias_factor_c(100) # 0.99750316 debiased_example = 2.0 / c_100 # 2.005006Does debiasing actually reduce Mean Squared Error (
MSE = Var + Bias^2)? UsingE[sigma_hat^2] = sigma^2andE[sigma_hat] = c_n * sigma, we haveVar(sigma_hat) = (1 - c_n^2) * sigma^2. Comparing the natural multiples ofsigma_hatatn = 100:Estimator Bias MSE / sigma^2(formula)MSE / sigma^2(n = 100)sigma_hat(MLE)-0.0025 * sigma2 * (1 - c_n)0.004994sigma_hat / c_n(unbiased)01 / c_n^2 - 10.005012c_n * sigma_hat(MSE-optimal multiple)-0.0050 * sigma1 - c_n^20.004987Cramér–Rao bound (unbiased floor) 01 / (2n)0.005000Mention this practical nuance in an interview: at
n = 100, the bias (0.0025 * sigma) is 28 times smaller than the standard error (sqrt(0.005) * sigma = 0.0707 * sigma), and multiplying by1 / c_100 = 1.0025slightly increases MSE (0.004994 -> 0.005012) because scaling up inflates variance by more than the tiny squared bias it eliminates. (As a side note,sqrt(pi / 2) * mean(|X_i|)is also exactly unbiased forsigma, withMSE = (pi / 2 - 1) * sigma^2 / n = 0.00571 * sigma^2—88%as efficient on pure Gaussian data, and more robust to fat-tailed outliers.)Part 2a: identify the target (`sigma` vs `sigma^2`) and calibrate
In Part 2,
W_tis a standard Brownian motion (W_0 = 0, and each integer stepW_t - W_{t-1}is an independentN(0, 1)draw), soX_t = sigma * W_tobserved att = 1, 2, ..., 100is a cumulative sum of100independentN(0, sigma^2)increments:Level X_t ^ H = max(X_1..X_100) ---*--- | / \ | | * / \ | R = H - L (path range) 0 +---------/-\-----------------/--------\----* | C = X_100 (final value) | / \ * / \ / | | \ / \ / * v | --*-- --*-- L = min(X_1..X_100) +-------------------------------------------------> time t (1 .. 100)Because
X_t = sigma * W_t, multiplyingsigmaby2multipliesH,L,C, andRby2, and multipliesR^2andC^2by4. That homogeneity immediately tells us which parameter each raw statistic targets:(i) |C|and(ii) R - |C|/2have units ofsigma(degree 1), so they naturally estimatesigma.(iii) R^2 + C^2has units ofsigma^2(degree 2), so it naturally estimatessigma^2.
Calibrating a statistic
Tmeans dividing it by its expected value atsigma = 1so the resulting estimator is unbiased:(i) C = X_100 ~ N(0, 100 * sigma^2) -> E[|C|] = sqrt(200 / pi) * sigma = 7.979 * sigma (exact) (ii) R - |C| / 2 -> E[R - |C|/2] = 10.76 * sigma (discrete simulation) (iii) R^2 + C^2 -> E[R^2] + E[C^2] = (240.2 + 100.0) * sigma^2 = 340.2 * sigma^2Watch out for discrete vs. continuous monitoring: Because
HandLare taken only over the100integer snapshotst = 1..100, they miss higher peaks and lower troughs between integer times! Continuous-time Brownian formulas (E[R_cont] = sqrt(800 / pi) * sigma = 15.96 * sigmaand Parkinson'sE[R_cont^2] = 4 * ln(2) * 100 * sigma^2 = 277.3 * sigma^2) exceed the 100-step discrete averages (14.75and240.2) by8%and15%, so dividing by continuous-time constants would systematically underestimate volatility!On a sample path with
H = 12, L = -4, C = 6(soR = 16), the calibrated estimates are(i) 6 / 7.979 = 0.75forsigma,(ii) (16 - 3) / 10.76 = 1.21forsigma, and(iii) (256 + 36) / 340.2 = 0.86forsigma^2(whose square root is0.93).Part 2b: put all three estimators on a common scale to compare MSE
You cannot compare the MSE of a
sigmaestimator (unitssigma^2) directly with the MSE of asigma^2estimator (unitssigma^4) — for example, atsigma = 0.01vssigma = 100,sigma^4andsigma^2differ by four orders of magnitude! First pick one common estimation target and map all three statistics onto it:- Estimating
sigma: calibrate(i) |C|,(ii) R - |C|/2, and(iii') sqrt(R^2 + C^2)by dividing each by itssigma = 1mean (7.979,10.76, and17.17). - Estimating
sigma^2: calibrate(i') C^2,(ii') (R - |C|/2)^2, and(iii) R^2 + C^2by dividing each by itssigma = 1mean (100.0,125.0, and340.2).
Next, use scale invariance: any degree-1 statistic satisfies
T = sigma * Z, whereZis the exact same statistic evaluated on asigma = 1standard Brownian motionW_1, ..., W_100. For the unbiased calibrated estimatorT_cal = T / E_{sigma=1}[Z] = sigma * (Z / E[Z]):MSE(T_cal) = E[(T_cal - sigma)^2] = sigma^2 * Var(Z) / (E[Z])^2Because
sigma^2multiplies all three candidates identically, the dimensionless relative MSEv = Var(Z) / (E[Z])^2depends zero onsigma! A single Monte Carlo run atsigma = 1settles the MSE ranking universally across everysigma > 0. (Even if you define "calibrated" as multiplyingTby the MSE-minimizing constantE[Z] / E[Z^2]instead of the unbiased constant1 / E[Z], relative MSE becomesv / (1 + v), which is strictly increasing invand gives the exact same winner.)import numpy as np def compare_brownian_estimators(n_steps: int = 100, n_paths: int = 200_000, seed: int = 0): rng = np.random.default_rng(seed) paths = np.cumsum(rng.standard_normal((n_paths, n_steps)), axis=1) high = paths.max(axis=1) low = paths.min(axis=1) close = paths[:, -1] path_range = high - low sigma_stats = { "(i) |C|": np.abs(close), "(ii) R - |C|/2": path_range - 0.5 * np.abs(close), "(iii) sqrt(R^2 + C^2)": np.sqrt(path_range ** 2 + close ** 2), } results = {} for name, z in sigma_stats.items(): mean_z = float(z.mean()) rel_mse = float(z.var() / (mean_z ** 2)) results[name] = (mean_z, rel_mse) return results- Estimating
Part 2c: MSE comparison table and why `(ii)` wins
Simulating
2,000,000paths atsigma = 1(row(i)also has closed-form exact values) gives the relative MSE (MSE / sigma^2when targetingsigma, andMSE / sigma^4when targetingsigma^2):Candidate Calibration & Relative MSE for sigmaCalibration & Relative MSE for sigma^2(i)endpointabs(C)abs(C) / 7.98->pi/2 - 1 = 0.571(exact)C^2 / 100->2.000(exact)(ii)drift-trimmed rangeR - abs(C)/2(R - abs(C)/2) / 10.76->0.079(R - abs(C)/2)^2 / 125.0->0.321(iii)quadratic sumR^2 + C^2sqrt(R^2 + C^2) / 17.17->0.154(R^2 + C^2) / 340.2->0.748Decision: Whether we state our target as
sigmaorsigma^2, the ranking is(ii) < (iii) < (i). Prefer(ii)to estimatesigmavia(R - |C|/2) / 10.76— its MSE is roughly half that of(iii)(0.079vs0.154, or0.321vs0.748onsigma^2) and more than 7 times smaller than(i)(0.079vs0.571)!Why does
(ii)win while(iii)loses even toRalone?(i) |C|wastes the path:C = X_100is a single Gaussian draw, discardingt = 1..99completely (effective sample size1).- Range
Rcaptures path excursions: UsingRalone already drops relative MSE to0.103forsigma(0.473forsigma^2viaR^2). - Subtracting
|C|/2in(ii)cancels shared endpoint noise: Whenever a path happens to finish with a huge net move|C|, its rangeRis forced to be large too (Corr(R, |C|) = 0.79). Subtracting0.5 * |C|strips out that noisy directional stretch (0.103 -> 0.079), landing right next to the numerically optimal linear combinationR - 0.43 * |C|(0.077). - Adding
+ C^2in(iii)has the wrong sign:(iii)is a classic trap!C^2is extremely noisy (relative MSE2.000) and strongly positively correlated withR^2(Corr = 0.84). Adding+1 * C^2amplifies endpoint noise and raises relative MSE forsigma^2from0.473(R^2alone) up to0.748! Just as in the classic Garman–Klass range-and-close variance estimator, the variance-minimizing weight onC^2alongsideR^2is negative (~ -0.69), not+1.
Step back: using the full observed path beats all three
Before wrapping up, highlight one big-picture insight: our setup records
X_tat every integer timestampt = 1, 2, ..., 100, not solely through the three summary numbers(H, L, C)!By definition of Brownian motion, the
100step incrementsdX_t = X_t - X_{t-1}(withX_0 = 0) are 100 independentN(0, sigma^2)draws — turning Part 2 straight back into Part 1! Computing realized variance from all100increments:sigma2_RV = (1 / 100) * sum_{t=1}^{100} (X_t - X_{t-1})^2 -> relative MSE for sigma^2 = 2 / 100 = 0.020 sigma_RV = sqrt(sigma2_RV) / c_100 -> relative MSE for sigma = 0.005sigma2_RVis a sufficient statistic for the observed trajectory and hits the Cramér–Rao lower bound: its MSE is 16 times smaller than(ii)(0.020vs0.321forsigma^2, and0.005vs0.079forsigma). Thus the complete engineering answer is:- Among the three
(H, L, C)bar estimators (needed when you only store daily High/Low/Close bars rather than full intraday ticks), estimatesigmawith calibrated(ii) (R - |C|/2) / 10.76. - When all
100observationsX_1, ..., X_100are available, difference consecutive observations and use Part 1's realized-volatility estimator!
- Among the three
Intuition & how it works
Think of estimating volatility sigma as measuring the typical step size of a jittery compass. In Part 1, you observe 100 independent steps starting from 0, so averaging their squares (1 / n) * sum X_i^2 is an unbiased estimator (a formula whose long-run average across repeated samples equals the true parameter) for sigma^2. Taking its square root gives the natural Maximum Likelihood Estimator (MLE) (the parameter value that makes the observed sample most probable) for sigma, which slightly underestimates sigma because sqrt(y) bends downward and compresses random upward spikes more than downward dips. In Part 2, you watch a 100-step cumulative random walk through three summary lenses — just the final position |C|, the high-minus-low span trimmed by half the net move R - |C|/2, or the quadratic sum R^2 + C^2 — and pick the lens with the smallest Mean Squared Error (MSE) (Var + Bias^2, the average squared distance from the true target).
Two naive shortcuts regularly trip candidates up. First, dividing by n - 1 when the true mean 0 is already known introduces upward variance bias, while assuming E[sqrt(Y)] == sqrt(E[Y]) violates Jensen's inequality (for any non-constant random variable Y and concave curve like sqrt, E[sqrt(Y)] < sqrt(E[Y])). Second, in Part 2, comparing a sigma estimator's MSE directly against a sigma^2 estimator's MSE mixes incompatible units (sigma^2 vs sigma^4), and assuming "R^2 + C^2 combines two numbers so it must beat R alone" misses that C^2 is ultra-noisy and strongly positively correlated with R^2 — adding + C^2 amplifies noise, whereas subtracting |C|/2 in (ii) cancels it!
Walk through tiny concrete numbers on both parts:
- Part 1 (
n = 100,sum X_i^2 = 400):sigma2_hat = 400 / 100 = 4.0,sigma_hat = sqrt(4.0) = 2.0, and dividing by the exact bias factorc_100 = 0.9975yields unbiasedsigma_unbiased = 2.0 / 0.9975 = 2.005. - Part 2 (
H = 12, L = -4, C = 6, soR = 16): Mapping all three ontosigmaby dividing each statistic by itssigma = 1expected value gives(i) 6 / 7.98 = 0.75,(ii) (16 - 3) / 10.76 = 1.21, and(iii) sqrt((256 + 36) / 340.2) = 0.93; across simulated paths,(ii)wins decisively with relative MSE0.079vs0.154for(iii)and0.571for(i).
Key points
- Part 1 variance &
sigmaestimation: With known mean0,sigma2_hat = (1 / n) * sum X_i^2is unbiased forsigma^2. Becausesum X_i^2 / sigma^2follows a chi-square distribution (the distribution of the sum ofnsquared independent standard normal variables),sigma_hat = sqrt(sigma2_hat)satisfiesE[sigma_hat] = c_n * sigmawithc_n = sqrt(2 / n) * Gamma((n + 1) / 2) / Gamma(n / 2) = 0.997503atn = 100, sosigma_hat / c_100is exactly unbiased. - Negligible bias vs. MSE at
n = 100: The-0.25%bias (-0.0025 * sigma) is28xsmaller than the0.071 * sigmastandard error, andsigma_hat,sigma_hat / c_100, andc_100 * sigma_hatall achieve MSE within0.5%of the Cramér–Rao lower bound (sigma^2 / (2n) = 0.005 * sigma^2, the theoretical minimum variance achievable by any unbiased estimator). - Part 2 target homogeneity: Under Brownian motion (
X_t = sigma * W_t, a continuous-time random walk with independent Gaussian increments), linear statistics(i) |C|and(ii) R - |C|/2naturally estimatesigma, while quadratic(iii) R^2 + C^2naturally estimatessigma^2. Always state your chosen target (sigmaorsigma^2) and transform all three onto that single scale before comparing MSE. - Scale invariance & discrete calibration: By scale invariance (every path scales linearly with
sigma, soMSEequalssigma^2orsigma^4times asigma-free constant), one Monte Carlo simulation oft = 1..100atsigma = 1supplies both the exact discrete-monitoring calibration constants and the universal MSE ranking. - Winner among
(i),(ii),(iii): On both thesigmascale (0.079 < 0.154 < 0.571) and thesigma^2scale (0.321 < 0.748 < 2.000),(ii) R - |C|/2wins, because subtracting half the net close move cancels noisy directional drift shared betweenRand|C|, whereas+ C^2in(iii)enters with the wrong sign and inflates variance aboveR^2alone (0.473 -> 0.748). - Full-path benchmark: Because all
100pointsX_1, ..., X_100are observed, realized variance(1 / 100) * sum (X_t - X_{t-1})^2is a sufficient statistic (a summary that retains 100% of the sample's information aboutsigma) with16xlower MSE than(ii)(0.020vs0.321forsigma^2).
Common mistakes
- Using
1 / (n - 1)despite a fixed zero mean: Subtracting0consumes zero degrees of freedom; dividing by99instead of100makessigma2_hatbiased upward by+1.01%. - Claiming
sqrt(sigma2_hat)is unbiased becausesigma2_hatis unbiased: Unbiasedness is preserved only by linear transformations, never by nonlinear functions likesqrt. - Comparing MSE across mismatched units (
sigmavssigma^2): Comparing0.079 * sigma^2directly against0.748 * sigma^4is dimensionally invalid unless you either takesqrt(...)of(iii)or square(i)and(ii)before calibrating. - Plugging continuous-time range constants into
100discrete points: Continuous Brownian formulas (E[R] = sqrt(800 / pi) * sigma = 15.96 * sigma,E[R^2] = 4 * ln(2) * 100 * sigma^2 = 277.3 * sigma^2) overstate100-step discrete range moments (14.75and240.2), biasing volatility estimates downward by8%–13%. - Assuming
R^2 + C^2beatsRbecause "more terms add information": Adding a noisier, positively correlated quantity (Corr(R^2, C^2) = 0.84) with a positive weight increases variance; the variance-reducing weight onC^2is negative (~ -0.69, as in Garman–Klass). - Assuming
H >= 0andL <= 0: The problem definesH = max(X_1, ..., X_100)excludingX_0 = 0; with probability~5.6%all100steps stay strictly negative (H < 0), thoughR = H - Lremains positive (H_0 = max(0, H)shifts calibration slightly from10.76to10.84without changing the ranking).
Follow-up questions
- How do you build an exact 95% confidence interval for sigma in the first setup? Use the pivotal quantity
S = sum_{i=1}^{100} X_i^2 / sigma^2 ~ chi^2_100(a function of data and unknown parameter whose distribution does not depend onsigma). Withn = 100, the2.5%and97.5%quantiles ofchi^2_100are74.22and129.56, soP(74.22 <= sum X_i^2 / sigma^2 <= 129.56) = 0.95. Inverting and taking square roots gives[sqrt(sum X_i^2 / 129.56), sqrt(sum X_i^2 / 74.22)]— forsum X_i^2 = 400, that is[1.757, 2.321], asymmetric around2.0becausechi^2_100is right-skewed. - How do these volatility estimators behave when the Brownian path includes an unknown linear drift? Under
X_t = mu * t + sigma * W_t, both|C|andRgrow with|mu|:C ~ N(100 * mu, 100 * sigma^2)meansE[C^2 / 100] = sigma^2 + 100 * mu^2, severely biasing close-only and naive range estimators upward whenever a strong trend is present. Notice that(ii) R - |C|/2partially dampens moderate drift because subtracting|C|/2removes half of a straight-line trend, whereas for full path data you simply demean the increments ((1 / 99) * sum (dX_t - mean(dX))^2), or on OHLC bars switch to the Rogers–Satchell estimator, which usesH * (H - C) + L * (L - C)to stay completely unbiased for any constant driftmu. - Why does high-frequency market microstructure noise break naive realized variance, and how do you fix it? At high sampling frequencies (seconds or ticks), observed log-prices equal
Y_t = X_t + eps_t, where market microstructure noiseeps_t(bid-ask bounce and tick rounding of varianceeta^2) contaminates every point. Each incrementY_t - Y_{t-1} = dX_t + eps_t - eps_{t-1}adds2 * eta^2to the expected squared change, causing realized variance to blow up as sampling gets finer instead of converging! Standard fixes are sampling at coarser intervals (such as 5-minute bars), averaging subsampled grids (two-scale / multi-scale realized variance), or using pre-averaged increments so theeps_tnoise cancels out.
Follow-up questions
- How do you build an exact 95% confidence interval for sigma in the first setup?
- How do these volatility estimators behave when the Brownian path includes an unknown linear drift?
- Why does high-frequency market microstructure noise break naive realized variance, and how do you fix it?
Similar questions
- Low-Latency Tree Ensemble Inference
- Select Score Cutoff for Target Precision
- Payment Fraud Detection Under Class Imbalance and Drift
- Diagnosing and Fixing Overfitting in Supervised Learning
- Correlation Bounds, Equicorrelated Variables, and Box-Muller Sampling
- Feed Click-Through Rate Feature Engineering and Modeling