TQBTHEQUANTBATEMAN
TQB/ learn/ volatility/ realized volatilityEN · DARK
Volatility · foundation

Realized volatility

Measuring path dispersion without confusing an estimator for an observable truth

BY THE END, YOU CAN

01Compute close-to-close and range-based realized-volatility estimators with explicit units.

02Derive annualization from return variance rather than memorizing a square-root rule.

03Diagnose window, sampling, jump and microstructure effects.

04Interpret a rolling estimate as a backward-looking state variable, not a forecast.

01
INTUITION

Separate the quote from the quantity inferred from it.

Realized volatility is an estimate extracted from a finite price path. The sampling clock, return definition, window and treatment of jumps are part of the number—not implementation details.

01

Prices are observed; volatility is estimated from returns.

02

Variance aggregates across independent increments; volatility inherits square-root time scaling only under stated assumptions.

03

Range estimators use intraday extremes efficiently but impose stronger path assumptions.

02
WHY MARKETS CARE

Start from executable inputs and conventions.

Risk limits, variance-swap marks, volatility targeting and model validation all need an ex-post measure of dispersion that can be reproduced from a fixed dataset.

INSTRUMENTS

cash equities and indices

futures

variance swaps

volatility-controlled portfolios

QUOTE CONVENTION

This lesson reports annualized decimal volatility from log returns and an ACT/365-like clock. A displayed 20% means 0.20 in calculations.

03
MATHEMATICS

Transform quotes without losing units or arbitrage constraints.

Formula · Short derivation

Close-to-close estimator

σ^cc=A 1n−1∑t=1n(rt−rˉ)2\widehat{\sigma}_{cc}=\sqrt{A\,\frac{1}{n-1}\sum_{t=1}^{n}(r_t-\bar r)^2}

Annualized sample standard deviation of equally spaced log returns.

Short derivation
Short derivation

From quadratic return variation to an annualized quote

The square-root rule follows from a variance model; it is not a universal unit conversion.

  1. 01

    Define the return clock

    Choose close-to-close log returns at a fixed sampling interval and preserve timezone, corporate-action and missing-observation rules.

    rt=ln⁡St−ln⁡St−1r_t=\ln S_t-\ln S_{t-1}
  2. 02

    Estimate one-period variance

    Center the sample when estimating unconditional variance. For a zero-mean high-frequency model, realized variance often uses the uncentered sum.

    sr2=1n−1∑(rt−rˉ)2s_r^2=\frac{1}{n-1}\sum(r_t-\bar r)^2
  3. 03

    Derive time aggregation

    If equal-period returns are uncorrelated with common variance, the variance of their sum is the sum of variances.

    Var⁡(∑i=1Ari)=AVar⁡(r)\operatorname{Var}(\sum_{i=1}^{A}r_i)=A\operatorname{Var}(r)
  4. 04

    Convert variance to volatility

    Taking the positive square root produces annualized volatility.

    σann=A sr\sigma_{ann}=\sqrt{A}\,s_r
  5. 05

    Choose an estimator for the data

    OHLC estimators can reduce sampling noise, while EWMA deliberately weights recent shocks more heavily. Compare estimators rather than silently switching definitions.

A realized-volatility number is auditable only when its return clock, estimator, window, annualization and data cleaning are attached.

Inputs
  • r_t = ln(S_t/S_{t-1}): log return
  • n: observations in the window
  • A: observations per year
  • λ: EWMA decay
Assumptions and limits
  • Backward-looking and regime dependent.
  • Sensitive to jumps, market closure and microstructure noise.
  • Square-root scaling can fail under autocorrelation or non-stationarity.
Formula · Short derivation

Parkinson range estimator

σ^P2=A4nln⁡2∑t=1n[ln⁡(Ht/Lt)]2\widehat{\sigma}_{P}^{2}=\frac{A}{4n\ln 2}\sum_{t=1}^{n}\left[\ln(H_t/L_t)\right]^2

Uses the intraday high-low range and is efficient under a continuous driftless diffusion, but misses overnight jumps.

Formula · Definition

EWMA variance

σ^t2=λσ^t−12+(1−λ)rt2\widehat{\sigma}_{t}^{2}=\lambda\widehat{\sigma}_{t-1}^{2}+(1-\lambda)r_t^2

A recursive state with geometrically decaying memory; the decay factor determines responsiveness.

05
MODEL / PRICING

Invert, fit, and reprice the market instruments.

METHOD

Compute several estimators over the same clean path, report their definitions, and examine sensitivity to sampling and window length.

CALIBRATION

There is no option calibration. Select λ or window length through a documented forecasting or risk objective and validate out of sample.

Implementation with current QuantLib

Current QuantLib separates market structures, processes, instruments, engines and calibration helpers. Use those abstractions only after the lesson’s conventions, domains and numerical checks are explicit.

API authority: upstream QuantLib reference pinned in the source registry.
06PYTHON IMPLEMENTATIONOpen the implementation and checks.
ARCHITECTURE
  • Validate domains and units at the boundary.
  • Keep the numerical kernel framework-free and deterministic.
  • Return diagnostics with values.
  • Test analytical limits and failure states.
PYTHON 3 · NUMPY / SCIPY

Auditable realized-volatility estimators

Compute close-to-close, Parkinson and EWMA estimates from a deterministic price path.

REUSABLE EXAMPLE
01from __future__ import annotations
02
03import numpy as np
04
05def realized_vol(close: np.ndarray, periods: int = 252) -> float:
06 if close.ndim != 1 or close.size < 3 or np.any(close <= 0):
07 raise ValueError("close must contain at least three positive prices")
08 returns = np.diff(np.log(close))
09 return float(np.std(returns, ddof=1) * np.sqrt(periods))
10
11def parkinson(high: np.ndarray, low: np.ndarray, periods: int = 252) -> float:
12 if high.shape != low.shape or np.any(high < low) or np.any(low <= 0):
13 raise ValueError("invalid high-low path")
14 variance = np.mean(np.log(high / low) ** 2) / (4.0 * np.log(2.0))
15 return float(np.sqrt(periods * variance))
16
17close = np.array([100.0, 101.2, 99.8, 102.1, 101.4, 103.0])
18high = close[1:] * 1.008
19low = close[1:] * 0.992
20sigma_cc = realized_vol(close)
21sigma_p = parkinson(high, low)
22assert np.isfinite([sigma_cc, sigma_p]).all()
23assert sigma_cc > 0.0 and sigma_p > 0.0
24print(f"CC {sigma_cc:.2%} | Parkinson {sigma_p:.2%}")
EXPECTED OUTPUTDeterministic annualized close-to-close and Parkinson estimates.
SANITY CHECKS

✓ Positive prices and ordered ranges are validated.

✓ Sample standard deviation uses ddof=1.

✓ Annualization is explicit.

07
INTERACTIVE LAB

Move the quote and inspect every linked representation.

PATH → ESTIMATOR → ANNUALIZED STATE

Estimator and regime lab

Change estimator, window and scenario; inspect the path, rolling estimate and annualization together.

SYNTHETIC · CONTROLLED SCENARIOS
Latest rolling11.00%
Peak11.00%
EWMA λ0.94
Annualized volatility by Trading days

Calm: Low dispersion with a stable state.

  • 20d rolling
  • EWMA
Trading days: 0. 20d rolling: 11.0%. EWMA: 11.0%.

Use Left/Right or Up/Down arrows to inspect values; Home and End jump to the bounds.

ACTIVE STATE

Calm — Low dispersion with a stable state. Move the intensity control and inspect every series with pointer or touch.

08
FRONT OFFICE

Where the model meets the book.

ON THE DESK
“The window is a position: it determines which regime you are carrying into the number.”
VISIBLE INPUTS

adjusted OHLC path

sampling clock

window

annualization basis

jump and missing-data policy

CALIBRATION

There is no option calibration. Select λ or window length through a documented forecasting or risk objective and validate out of sample.

RISK

estimator risk

regime lag

jump sensitivity

sampling bias

DAILY WORKFLOW
  1. freeze path
  2. clean events
  3. compute estimators
  4. compare windows
  5. flag breaks
Production failure modes
  • unadjusted splits
  • mixed timezones
  • overnight gaps omitted
  • percent/decimal mismatch
09MACRO CONNECTIONOpen the transmission channel.
MACRO CONNECTION

Realized volatility as a regime recorder

Macro shocks enter the observed path through jumps, clustered returns and changing correlations; the window controls how long that regime remains visible.

01Policy or growth shocktransmits

moves prices and correlations

02Return pathtransmits

records jumps and clustering

03Estimatortransmits

weights and annualizes the path

04Risk stateoutput

feeds limits and forecasts

10COMMON PITFALLSOpen the failure checklist.
01

Calling the estimate observable volatility.

02

Annualizing without stating the return interval.

03

Comparing OHLC and close-only estimators as if assumptions were identical.

04

Treating a rolling window as forward-looking.

11SOURCES / FURTHER READINGOpen sources and continue the track.
research

Volatility, Monte Carlo and stochastic-volatility lectures

Research map for the mathematical progression and numerical experiments; prose, examples and code are original.

Source
Computational Finance Course
Author
L. A. Grzelak
Ref
main
OPEN ORIGINAL SOURCE ↗
implementation reference

Current volatility structures, processes, calibration helpers and tests

Implementation reference for production abstractions and validation patterns.

Source
QuantLib upstream
Author
QuantLib contributors
Ref
v1.42.1
OPEN ORIGINAL SOURCE ↗