Skip to content

IntermediateOptions, Derivatives & FinancePython

Run this module

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

View source on GitHub


Expected Shortfall (CVaR)

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

Continue in Options, Derivatives & Finance

  • Advanced Options Pricing

    This module covers advanced mathematical techniques for pricing financial derivatives. The focus is on models beyond the standard assumptions. Rather than assuming constant volatility, we explore dynamic and local volatility models. These models are crucial for correctly valuing exotic options and managing the risks of complex derivatives portfolios.

  • 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

  • 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 utility does NOT use any external APIs. All data is managed locally for learning and experimentation.

Browse all modules Learning paths