Gaussian and Brownian Volatility Estimation

Medium · Machine Learning · Data Scientist · Technical Screen

Prompt

Address the following two parameter-estimation problems:

  1. Zero-mean Gaussian draws: Suppose X_1, ..., X_100 are mutually independent random variables drawn from N(0, sigma^2), where the true mean is fixed at 0 while sigma > 0 is unknown. Construct a point estimator for sigma, determine whether its expectation equals sigma, and—if it is biased—derive how to adjust it so that it becomes unbiased.
  2. Discretely sampled Brownian path: Suppose X_t = sigma W_t represents a driftless scaled Brownian motion starting from X_0 = 0 (with W_t denoting standard Brownian motion) recorded at the integer timestamps t = 1, 2, ..., 100. From these 100 observations, let H = max(X_1, ..., X_100), L = min(X_1, ..., X_100), C = X_100, and R = H - L. Examine calibrated volatility estimators formed from each of these three summary expressions:
    • (i) |C|
    • (ii) R - |C| / 2
    • (iii) R^2 + C^2

      Detail 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 sigma or sigma^2.

Scope & Expectations

  • Propose a principled estimator for sigma exploiting 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 (sigma vs sigma^2) of each Brownian summary expression, calibrate expectations accurately for 100 discrete 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 all 100 increments directly.

Step-by-step walkthrough

  1. Part 1a: propose the natural estimator and check bias

    Because X_1, ..., X_100 are drawn independently from N(0, sigma^2) with a known mean of 0, we do not estimate a sample mean X_bar and do not divide by n - 1 (Bessel's n - 1 correction only compensates for estimating an unknown mean). Every observation directly satisfies E[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_hat unbiased for sigma? No — it slightly underestimates sigma! Because the function g(y) = sqrt(y) curves downward (it is strictly concave), random upward swings in sigma2_hat get compressed more than downward swings get stretched. For instance, if a random variance estimate is equally likely to be 1 or 9 (average 5, true sigma = sqrt(5) = 2.236), then sqrt(1) = 1 and sqrt(9) = 3 average to 2.000 < 2.236. Formally, Jensen's inequality states that for any non-constant positive random variable Y, E[sqrt(Y)] < sqrt(E[Y]), so E[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). Then S = sum_{i=1}^n Z_i^2 follows a chi-square distribution with n degrees of freedom (chi^2_n), whose square root has exact expectation E[sqrt(S)] = sqrt(2) * Gamma((n + 1) / 2) / Gamma(n / 2). Writing sigma_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%)
    
  2. Part 1b: debias the estimator and check its MSE trade-off

    Because c_n depends only on the sample size n = 100 and not on sigma, dividing sigma_hat by c_n cancels 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_n using math.lgamma (log-Gamma) so large n never 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.005006
    

    Does debiasing actually reduce Mean Squared Error (MSE = Var + Bias^2)? Using E[sigma_hat^2] = sigma^2 and E[sigma_hat] = c_n * sigma, we have Var(sigma_hat) = (1 - c_n^2) * sigma^2. Comparing the natural multiples of sigma_hat at n = 100:

    Estimator Bias MSE / sigma^2 (formula) MSE / sigma^2 (n = 100)
    sigma_hat (MLE) -0.0025 * sigma 2 * (1 - c_n) 0.004994
    sigma_hat / c_n (unbiased) 0 1 / c_n^2 - 1 0.005012
    c_n * sigma_hat (MSE-optimal multiple) -0.0050 * sigma 1 - c_n^2 0.004987
    Cramér–Rao bound (unbiased floor) 0 1 / (2n) 0.005000

    Mention 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 by 1 / c_100 = 1.0025 slightly 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 for sigma, with MSE = (pi / 2 - 1) * sigma^2 / n = 0.00571 * sigma^2 — 88% as efficient on pure Gaussian data, and more robust to fat-tailed outliers.)

  3. Part 2a: identify the target (`sigma` vs `sigma^2`) and calibrate

    In Part 2, W_t is a standard Brownian motion (W_0 = 0, and each integer step W_t - W_{t-1} is an independent N(0, 1) draw), so X_t = sigma * W_t observed at t = 1, 2, ..., 100 is a cumulative sum of 100 independent N(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, multiplying sigma by 2 multiplies H, L, C, and R by 2, and multiplies R^2 and C^2 by 4. That homogeneity immediately tells us which parameter each raw statistic targets:

    • (i) |C| and (ii) R - |C|/2 have units of sigma (degree 1), so they naturally estimate sigma.
    • (iii) R^2 + C^2 has units of sigma^2 (degree 2), so it naturally estimates sigma^2.

    Calibrating a statistic T means dividing it by its expected value at sigma = 1 so 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^2
    

    Watch out for discrete vs. continuous monitoring: Because H and L are taken only over the 100 integer snapshots t = 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 * sigma and Parkinson's E[R_cont^2] = 4 * ln(2) * 100 * sigma^2 = 277.3 * sigma^2) exceed the 100-step discrete averages (14.75 and 240.2) by 8% and 15%, so dividing by continuous-time constants would systematically underestimate volatility!

    On a sample path with H = 12, L = -4, C = 6 (so R = 16), the calibrated estimates are (i) 6 / 7.979 = 0.75 for sigma, (ii) (16 - 3) / 10.76 = 1.21 for sigma, and (iii) (256 + 36) / 340.2 = 0.86 for sigma^2 (whose square root is 0.93).

  4. Part 2b: put all three estimators on a common scale to compare MSE

    You cannot compare the MSE of a sigma estimator (units sigma^2) directly with the MSE of a sigma^2 estimator (units sigma^4) — for example, at sigma = 0.01 vs sigma = 100, sigma^4 and sigma^2 differ 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 its sigma = 1 mean (7.979, 10.76, and 17.17).
    • Estimating sigma^2: calibrate (i') C^2, (ii') (R - |C|/2)^2, and (iii) R^2 + C^2 by dividing each by its sigma = 1 mean (100.0, 125.0, and 340.2).

    Next, use scale invariance: any degree-1 statistic satisfies T = sigma * Z, where Z is the exact same statistic evaluated on a sigma = 1 standard Brownian motion W_1, ..., W_100. For the unbiased calibrated estimator T_cal = T / E_{sigma=1}[Z] = sigma * (Z / E[Z]):

    MSE(T_cal) = E[(T_cal - sigma)^2] = sigma^2 * Var(Z) / (E[Z])^2
    

    Because sigma^2 multiplies all three candidates identically, the dimensionless relative MSE v = Var(Z) / (E[Z])^2 depends zero on sigma! A single Monte Carlo run at sigma = 1 settles the MSE ranking universally across every sigma > 0. (Even if you define "calibrated" as multiplying T by the MSE-minimizing constant E[Z] / E[Z^2] instead of the unbiased constant 1 / E[Z], relative MSE becomes v / (1 + v), which is strictly increasing in v and 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
    
  5. Part 2c: MSE comparison table and why `(ii)` wins

    Simulating 2,000,000 paths at sigma = 1 (row (i) also has closed-form exact values) gives the relative MSE (MSE / sigma^2 when targeting sigma, and MSE / sigma^4 when targeting sigma^2):

    Candidate Calibration & Relative MSE for sigma Calibration & Relative MSE for sigma^2
    (i) endpoint abs(C) abs(C) / 7.98 -> pi/2 - 1 = 0.571 (exact) C^2 / 100 -> 2.000 (exact)
    (ii) drift-trimmed range R - abs(C)/2 (R - abs(C)/2) / 10.76 -> 0.079 (R - abs(C)/2)^2 / 125.0 -> 0.321
    (iii) quadratic sum R^2 + C^2 sqrt(R^2 + C^2) / 17.17 -> 0.154 (R^2 + C^2) / 340.2 -> 0.748

    Decision: Whether we state our target as sigma or sigma^2, the ranking is (ii) < (iii) < (i). Prefer (ii) to estimate sigma via (R - |C|/2) / 10.76 — its MSE is roughly half that of (iii) (0.079 vs 0.154, or 0.321 vs 0.748 on sigma^2) and more than 7 times smaller than (i) (0.079 vs 0.571)!

    Why does (ii) win while (iii) loses even to R alone?

    1. (i) |C| wastes the path: C = X_100 is a single Gaussian draw, discarding t = 1..99 completely (effective sample size 1).
    2. Range R captures path excursions: Using R alone already drops relative MSE to 0.103 for sigma (0.473 for sigma^2 via R^2).
    3. Subtracting |C|/2 in (ii) cancels shared endpoint noise: Whenever a path happens to finish with a huge net move |C|, its range R is forced to be large too (Corr(R, |C|) = 0.79). Subtracting 0.5 * |C| strips out that noisy directional stretch (0.103 -> 0.079), landing right next to the numerically optimal linear combination R - 0.43 * |C| (0.077).
    4. Adding + C^2 in (iii) has the wrong sign: (iii) is a classic trap! C^2 is extremely noisy (relative MSE 2.000) and strongly positively correlated with R^2 (Corr = 0.84). Adding +1 * C^2 amplifies endpoint noise and raises relative MSE for sigma^2 from 0.473 (R^2 alone) up to 0.748! Just as in the classic Garman–Klass range-and-close variance estimator, the variance-minimizing weight on C^2 alongside R^2 is negative (~ -0.69), not +1.
  6. Step back: using the full observed path beats all three

    Before wrapping up, highlight one big-picture insight: our setup records X_t at every integer timestamp t = 1, 2, ..., 100, not solely through the three summary numbers (H, L, C)!

    By definition of Brownian motion, the 100 step increments dX_t = X_t - X_{t-1} (with X_0 = 0) are 100 independent N(0, sigma^2) draws — turning Part 2 straight back into Part 1! Computing realized variance from all 100 increments:

    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.005
    

    sigma2_RV is a sufficient statistic for the observed trajectory and hits the Cramér–Rao lower bound: its MSE is 16 times smaller than (ii) (0.020 vs 0.321 for sigma^2, and 0.005 vs 0.079 for sigma). 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), estimate sigma with calibrated (ii) (R - |C|/2) / 10.76.
    • When all 100 observations X_1, ..., X_100 are available, difference consecutive observations and use Part 1's realized-volatility estimator!

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 factor c_100 = 0.9975 yields unbiased sigma_unbiased = 2.0 / 0.9975 = 2.005.
  • Part 2 (H = 12, L = -4, C = 6, so R = 16): Mapping all three onto sigma by dividing each statistic by its sigma = 1 expected 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 MSE 0.079 vs 0.154 for (iii) and 0.571 for (i).

Key points

  • Part 1 variance & sigma estimation: With known mean 0, sigma2_hat = (1 / n) * sum X_i^2 is unbiased for sigma^2. Because sum X_i^2 / sigma^2 follows a chi-square distribution (the distribution of the sum of n squared independent standard normal variables), sigma_hat = sqrt(sigma2_hat) satisfies E[sigma_hat] = c_n * sigma with c_n = sqrt(2 / n) * Gamma((n + 1) / 2) / Gamma(n / 2) = 0.997503 at n = 100, so sigma_hat / c_100 is exactly unbiased.
  • Negligible bias vs. MSE at n = 100: The -0.25% bias (-0.0025 * sigma) is 28x smaller than the 0.071 * sigma standard error, and sigma_hat, sigma_hat / c_100, and c_100 * sigma_hat all achieve MSE within 0.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|/2 naturally estimate sigma, while quadratic (iii) R^2 + C^2 naturally estimates sigma^2. Always state your chosen target (sigma or sigma^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, so MSE equals sigma^2 or sigma^4 times a sigma-free constant), one Monte Carlo simulation of t = 1..100 at sigma = 1 supplies both the exact discrete-monitoring calibration constants and the universal MSE ranking.
  • Winner among (i), (ii), (iii): On both the sigma scale (0.079 < 0.154 < 0.571) and the sigma^2 scale (0.321 < 0.748 < 2.000), (ii) R - |C|/2 wins, because subtracting half the net close move cancels noisy directional drift shared between R and |C|, whereas + C^2 in (iii) enters with the wrong sign and inflates variance above R^2 alone (0.473 -> 0.748).
  • Full-path benchmark: Because all 100 points X_1, ..., X_100 are observed, realized variance (1 / 100) * sum (X_t - X_{t-1})^2 is a sufficient statistic (a summary that retains 100% of the sample's information about sigma) with 16x lower MSE than (ii) (0.020 vs 0.321 for sigma^2).

Common mistakes

  • Using 1 / (n - 1) despite a fixed zero mean: Subtracting 0 consumes zero degrees of freedom; dividing by 99 instead of 100 makes sigma2_hat biased upward by +1.01%.
  • Claiming sqrt(sigma2_hat) is unbiased because sigma2_hat is unbiased: Unbiasedness is preserved only by linear transformations, never by nonlinear functions like sqrt.
  • Comparing MSE across mismatched units (sigma vs sigma^2): Comparing 0.079 * sigma^2 directly against 0.748 * sigma^4 is dimensionally invalid unless you either take sqrt(...) of (iii) or square (i) and (ii) before calibrating.
  • Plugging continuous-time range constants into 100 discrete 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) overstate 100-step discrete range moments (14.75 and 240.2), biasing volatility estimates downward by 8%–13%.
  • Assuming R^2 + C^2 beats R because "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 on C^2 is negative (~ -0.69, as in Garman–Klass).
  • Assuming H >= 0 and L <= 0: The problem defines H = max(X_1, ..., X_100) excluding X_0 = 0; with probability ~5.6% all 100 steps stay strictly negative (H < 0), though R = H - L remains positive (H_0 = max(0, H) shifts calibration slightly from 10.76 to 10.84 without 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 on sigma). With n = 100, the 2.5% and 97.5% quantiles of chi^2_100 are 74.22 and 129.56, so P(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)] — for sum X_i^2 = 400, that is [1.757, 2.321], asymmetric around 2.0 because chi^2_100 is 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| and R grow with |mu|: C ~ N(100 * mu, 100 * sigma^2) means E[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|/2 partially dampens moderate drift because subtracting |C|/2 removes 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 uses H * (H - C) + L * (L - C) to stay completely unbiased for any constant drift mu.
  • 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 noise eps_t (bid-ask bounce and tick rounding of variance eta^2) contaminates every point. Each increment Y_t - Y_{t-1} = dX_t + eps_t - eps_{t-1} adds 2 * eta^2 to 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 the eps_t noise cancels out.

Follow-up questions

Similar questions

More Tudor interview questions

All 1 Tudor questions →