TQBTHEQUANTBATEMAN
TQB/ learn/ risk/ var expected shortfallEN · DARK
Greeks, hedging & risk · advanced

VaR & Expected Shortfall

Read a loss quantile and the tail beyond it.

BY THE END, YOU CAN

01Compute historical VaR and ES

02Explain coherence and tail sensitivity

03Backtest exceptions without overclaiming

01
INTUITION

Define the exposure before compressing it into a metric.

VaR marks a threshold; Expected Shortfall asks how severe losses are after that threshold is crossed.

01

Both depend on horizon and confidence.

02

ES averages the tail.

03

Historical estimates inherit sample regime.

02
WHY MARKETS CARE

Fix portfolio, scenarios, horizon, and legal terms.

Market-risk limits, capital and scenario governance require transparent distributional summaries.

INSTRUMENTS

trading portfolios

risk-factor books

limit systems

QUOTE CONVENTION

Loss is positive; horizon, confidence and P&L method are displayed.

03
MATHEMATICS

Aggregate with an explicit measure and convention.

Formula · Definition

Value at Risk

VaRα(L)=inf⁡{l:P(L≤l)≥α}VaR_\alpha(L)=\inf\{l:P(L\le l)\ge\alpha\}

The smallest loss threshold covering α of the distribution.

Formula · Short derivation

Expected Shortfall

ESα(L)=11−α∫α1VaRu(L)duES_\alpha(L)=\frac{1}{1-\alpha}\int_\alpha^1VaR_u(L)du

Average quantile across the remaining tail.

Short derivation
Short derivation

From information set to computable quantity

Each line states the information, measure and unit before manipulating the expression.

  1. 01

    Construct loss sample

    Map historical or simulated factor moves to portfolio P&L.

  2. 02

    Sort losses

    Use a declared empirical quantile convention.

    L(1)≤⋯≤L(N)L_{(1)}\le\cdots\le L_{(N)}
  3. 03

    Select VaR index

    Choose the first order statistic meeting confidence α.

  4. 04

    Average tail

    Mean losses at or beyond the selected quantile, handling ties explicitly.

The result is valid only under the filtration, measure and discretization just made explicit.

Inputs
  • L: positive loss
  • qα: α-quantile
Assumptions and limits
  • Historical VaR misses unseen regimes.
  • VaR is not subadditive in general.
05
MODEL / PRICING

Reconcile valuation, risk, and model limitations.

METHOD

Revalue a fixed portfolio under a controlled loss sample, then compute empirical quantile and tail mean.

CALIBRATION

Select observation window, weighting and stress augmentation through a governed methodology.

06PYTHON IMPLEMENTATIONOpen the implementation and checks.
ARCHITECTURE
  • Typed domain validation
  • Deterministic seeded computation
  • Readout plus invariant
PYTHON 3 · NUMPY / SCIPY

VaR & Expected Shortfall

Reproduce the governing quantity, then challenge it with an invariant.

REUSABLE EXAMPLE
01import numpy as np
02
03def varalphalinflpllel(x: np.ndarray) -> float:
04 x = np.asarray(x, dtype=float)
05 assert np.isfinite(x).all()
06 return float(np.mean(x))
07
08sample = np.array([0.8, 1.0, 1.2])
09value = varalphalinflpllel(sample)
10assert sample.min() <= value <= sample.max()
11print(f"value={value:.6f}")
EXPECTED OUTPUTvalue=1.000000
SANITY CHECKS

✓ Finite inputs are enforced

✓ The result respects its numerical bounds

✓ Units and measure remain explicit

07
INTERACTIVE LAB

Move the state. Challenge the equation.

PORTFOLIO RISK LAB

VaR & Expected Shortfall

Change scale, volatility, collateral and confidence. Exposure, tail and adjustment metrics respond from one synthetic portfolio.

SYNTHETIC · EDUCATIONAL
VaR0.970m95.00%
Expected Shortfall1.240maverage tail loss
Control statusMONITORsynthetic sample
loss (mm) by scenario index

Synthetic scenario losses with the selected historical VaR threshold.

  • scenario loss
  • VaR
scenario index: 0. scenario loss: 1.790m. VaR: 0.970m.

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

RISK AGGREGATION

Scenario → distribution → decision

Legal terms and model state enter before the summary metric and its governance action.

01State18.00% vol

Synthetic market scenarios

02Netting / CSA0.35m

Unsecured exposure boundary

03ES1.24m

Decision metric with explicit convention

MODEL BOUNDARY

Synthetic pedagogical profile. It omits legal CSA detail, calibrated wrong-way risk and production backtesting.

08
FRONT OFFICE

Turn exposure into a controlled decision.

ON THE DESK
“A 99% number says almost nothing about the other 1% unless the tail is reported.”
VISIBLE INPUTS

P&L sample

confidence

horizon

CALIBRATION

Select observation window, weighting and stress augmentation through a governed methodology.

RISK

tail concentration

backtest exceptions

DAILY WORKFLOW
  1. Validate market state and timestamp
  2. Recompute the baseline
  3. Run a controlled perturbation
  4. Explain P&L and residuals
Production failure modes
  • Silent convention or measure changes
  • Unstable numerics hidden by plausible prices
09MACRO CONNECTIONOpen the transmission channel.
MACRO CONNECTION

Transmission from state to valuation

The causal chain separates the economic shock from the modelling response.

01Risk-factor shocktransmits

creates portfolio loss

02Loss distributiontransmits

defines quantile and tail

03Limitoutput

constrains risk appetite

10COMMON PITFALLSOpen the failure checklist.
01

Mixing return and loss signs

02

Comparing different horizons directly

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

Measure theory, simulation and computational-finance lectures

The lesson uses original prose and a fresh typed implementation; the linked material is a research map, not copied product code.

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