Skip to content

Expected Shortfall (CVaR)

Intermediate / Options, Derivatives & Finance / Python / source

Expected Shortfall (ES), also called Conditional Value at Risk (CVaR), measures the expected loss given that losses exceed the VaR threshold. It is a coherent risk measure — unlike VaR, it captures tail severity, not just frequency.

Functions

Function Description
historical_es(returns, confidence_level) Non-parametric ES from actual distribution
parametric_es(returns, confidence_level) Normal-assumption ES
cornish_fisher_es(returns, confidence_level) Skewness/kurtosis-adjusted ES
es_summary(returns, confidence_level) All three estimates in one dict

Key Concepts

  • VaR vs ES: VaR says "you won't lose more than X with 95% probability." ES says "given you exceed VaR, your average loss is Y."
  • Coherence: ES satisfies subadditivity — diversification always reduces risk. VaR does not.
  • Cornish-Fisher: Adjusts the normal quantile using higher moments. Better for fat-tailed (leptokurtic) returns.

Example

from expected_shortfall import es_summary
import numpy as np

returns = np.random.normal(0.001, 0.02, 252)
summary = es_summary(returns, confidence_level=0.95)
print(summary)
# {'historical_es': 0.0412, 'parametric_es': 0.0398, 'cornish_fisher_es': 0.0405, ...}

When to Use

  • Portfolio risk reporting (ES is required under Basel III / FRTB)
  • Comparing risk across strategies with different tail behaviors
  • Stress testing alongside VaR

Running it

cd "Finance - Expected Shortfall"
python "expected_shortfall.py"

More in Options, Derivatives & Finance

  • Advanced Options Pricing: This module covers advanced mathematical techniques for pricing financial derivatives.
  • Black-Scholes Option Pricing: This module lets you price basic stock options (calls and puts) using the Black-Scholes formula, a foundation of modern financial analysis.
  • Bond Price and Yield: This utility lets you calculate the fair price of a bond or estimate its yield to maturity (YTM), two of the most basic (and important!) ideas in investing.
  • CAPM: CAPM is the idea that won a Nobel Prize and still anchors how the industry thinks about return and risk.
  • Discounted Cash Flow (DCF): This tool calculates the present value of a series of future cash flows—the basic principle behind valuing businesses, real estate, projects, and stocks!
  • Dividend Tracker: This tool lets you track upcoming dividends for a list of stocks, calculate expected income, and view a dividend calendar.

Every module on one page or suggested reading orders.