Skip to content

Risk

Value-at-risk and expected shortfall

VaR and expected shortfall as positive losses by the parametric normal, Cornish-Fisher, historical, Monte Carlo and RiskMetrics EWMA methods.

Model id
risk.value_at_risk, version 1
Domain
Risk
Evidence
standard
Cost class
heavy: Estimation or simulation; a hosted run may take up to 30 seconds.

Formula

VaR=−μh+zcσh\mathrm{VaR} = -\mu h + z_c \sigma\sqrt{h}ES=−μh+σh φ(zc)1−c\mathrm{ES} = -\mu h + \sigma\sqrt{h}\,\frac{\varphi(z_c)}{1 - c}g=z+(z2−1)S6+(z3−3z)K24−(2z3−5z)S236g = z + \tfrac{(z^2 - 1)S}{6} + \tfrac{(z^3 - 3z)K}{24} - \tfrac{(2z^3 - 5z)S^2}{36}z=Φ−1(1−c)z = \Phi^{-1}(1 - c)mES=−μ−σ1−c∫−∞gx φ(x)[1+S6He3(x)+K24He4(x)+S272He6(x)]dx\begin{aligned} \mathrm{mES} &= -\mu - \frac{\sigma}{1 - c}\int_{-\infty}^{g} x\,\varphi(x)\Big[1 + \tfrac{S}{6}He_3(x) \\ &\quad + \tfrac{K}{24}He_4(x) + \tfrac{S^2}{72}He_6(x)\Big]dx \end{aligned}VaR=−h q^1−c\mathrm{VaR} = -\sqrt{h}\,\hat{q}_{1 - c}ES=−h rt∣rt≤q^1−c‾\mathrm{ES} = -\sqrt{h}\,\overline{r_t \mid r_t \le \hat{q}_{1 - c}}σt2=λσt−12+(1−λ)rt2,σ12=r12\sigma_t^2 = \lambda\sigma_{t-1}^2 + (1 - \lambda) r_t^2, \quad \sigma_1^2 = r_1^2SE(VaR^)=c(1−c)/Nf(q^)\mathrm{SE}(\widehat{\mathrm{VaR}}) = \frac{\sqrt{c(1 - c)/N}}{f(\hat{q})}SE(ES^)=stail2+c(ES−VaR)2N(1−c)\mathrm{SE}(\widehat{\mathrm{ES}}) = \sqrt{\frac{s^2_{\mathrm{tail}} + c(\mathrm{ES} - \mathrm{VaR})^2}{N(1 - c)}}

Where

VaR\mathrm{VaR}
Value-at-risk: the loss the confidence level leaves a chance of exceeding value_at_risk
ES\mathrm{ES}
Expected shortfall: the average loss beyond value-at-risk expected_shortfall
μ\mu
Mean return per period mean
σ\sigma
Volatility per period volatility
hh
Horizon, in periods horizon
cc
Confidence level confidence
zcz_c
The standard normal quantile at the confidence level
φ\varphi
The standard normal density
gg
The Cornish-Fisher quantile, adjusted for skewness and kurtosis quantile
zz
The standard normal quantile at one less the confidence level
SS
Skewness of the returns skewness
KK
Excess kurtosis of the returns excess_kurtosis
mES\mathrm{mES}
Modified expected shortfall expected_shortfall
He3He_3
A probabilists' Hermite polynomial; He_4 and He_6 are the fourth and the sixth
q^1−c\hat{q}_{1 - c}
The returns' empirical quantile at one less the confidence level quantile
rtr_t
The return in period t returns
λ\lambda
The decay of the exponentially weighted variance decay
σt2\sigma_t^2
The exponentially weighted variance in period t
NN
Number of returns, or of simulations observations
f(q^)f(\hat{q})
The density of the returns at the quantile
stail2s^2_{\mathrm{tail}}
Variance of the losses beyond value-at-risk

Each symbol's field is named beside it; the inputs and outputs, with their units and bounds, are under Variables, and the citations give each formula's source.

Variables

Rates, returns and yields are decimals: 0.05 is five percent. Bounds in brackets include their end; in parentheses they exclude it.

Inputs

Normal VaR and ES (parametric): 6 inputs
Inputs of the calculation parametric
NameDescription
CalculationcalculationtextNormal VaR and ES
Meanmeanreturn · [-1, 1]Mean return per period
Volatilityvolatilityvolatility · (0, 2]Standard deviation of returns per period
Confidenceconfidenceprobability · [0.5, 0.9999]One-tailed confidence level, such as 0.99
Horizonhorizonperiods · [1, 1000]Horizon in periods of the returns, such as 10 days
Position valueposition_valuemoney · (0, 1e+10]Position value; the default of 1 makes the amounts the decimals
Modified VaR and ES from skewness and kurtosis (cornish_fisher): 8 inputs
Inputs of the calculation cornish_fisher
NameDescription
CalculationcalculationtextModified VaR and ES from skewness and kurtosis
Meanmeanreturn · [-1, 1]Mean return per period
Volatilityvolatilityvolatility · (0, 2]Standard deviation of returns per period
Skewnessskewnessratio · [-3, 3]Skewness of returns per period
Excess kurtosisexcess_kurtosisratio · [-2, 20]Excess kurtosis of returns per period
Confidenceconfidenceprobability · [0.5, 0.9999]One-tailed confidence level, such as 0.99
Horizonhorizonperiods · [1, 1000]Horizon in periods of the returns, such as 10 days
Position valueposition_valuemoney · (0, 1e+10]Position value; the default of 1 makes the amounts the decimals
Historical-simulation VaR and ES (historical): 6 inputs
Inputs of the calculation historical
NameDescription
CalculationcalculationtextHistorical-simulation VaR and ES
Returnsreturnsreturn (array) · length min 2, max 10080; each [-1, 100]Returns per period, in time order
InterpolationinterpolationtextHow the quantile falls between two returns (NumPy's methods; linear is Hyndman and Fan's definition 7)
Confidenceconfidenceprobability · [0.5, 0.9999]One-tailed confidence level, such as 0.99
Horizonhorizonperiods · [1, 1000]Horizon in periods of the returns, such as 10 days
Position valueposition_valuemoney · (0, 1e+10]Position value; the default of 1 makes the amounts the decimals
Monte Carlo VaR and ES with standard errors (monte_carlo): 10 inputs
Inputs of the calculation monte_carlo
NameDescription
CalculationcalculationtextMonte Carlo VaR and ES with standard errors
Meanmeanreturn · [-1, 1]Mean return per period
Volatilityvolatilityvolatility · (0, 2]Standard deviation of returns per period
DistributiondistributiontextDistribution of the standardized horizon return
Degrees of freedomdegrees_of_freedomratio · (2, 1000]Student-t degrees of freedom; ignored for the normal
Simulationssimulationscount · [10000, 1e+06]Number of simulated horizon returns
Seedseedcount · [0, 9.0072e+15]Random seed (ADR-0008 decision 7): the same seed, the same draws
Confidenceconfidenceprobability · [0.5, 0.9999]One-tailed confidence level, such as 0.99
Horizonhorizonperiods · [1, 1000]Horizon in periods of the returns, such as 10 days
Position valueposition_valuemoney · (0, 1e+10]Position value; the default of 1 makes the amounts the decimals
RiskMetrics EWMA volatility with normal VaR and ES (ewma): 6 inputs
Inputs of the calculation ewma
NameDescription
CalculationcalculationtextRiskMetrics EWMA volatility with normal VaR and ES
Returnsreturnsreturn (array) · length min 1, max 10080; each [-1, 100]Returns per period, oldest first
Decaydecayratio · [0.5, 0.999]Decay factor lambda (RiskMetrics uses 0.94 for daily data)
Confidenceconfidenceprobability · [0.5, 0.9999]One-tailed confidence level, such as 0.99
Horizonhorizonperiods · [1, 1000]Horizon in periods of the returns, such as 10 days
Position valueposition_valuemoney · (0, 1e+10]Position value; the default of 1 makes the amounts the decimals

Outputs

Normal VaR and ES (parametric): 6 outputs
Outputs of the calculation parametric
NameDescription
Value at riskvalue_at_riskreturn · [-100000, 100000]VaR as a decimal of the position (a loss > 0)
Expected shortfallexpected_shortfallreturn · [-100000, 100000]Expected shortfall as a decimal of the position (a loss > 0)
Value at risk amountvalue_at_risk_amountmoney · [-1e+15, 1e+15]VaR in money: the decimal times the position
Expected shortfall amountexpected_shortfall_amountmoney · [-1e+15, 1e+15]Expected shortfall in money: the decimal times the position
CalculationcalculationtextNormal VaR and ES
Quantilequantileratio · [0, 4]Standard normal quantile of the loss at confidence c
Modified VaR and ES from skewness and kurtosis (cornish_fisher): 6 outputs
Outputs of the calculation cornish_fisher
NameDescription
Value at riskvalue_at_riskreturn · [-100000, 100000]VaR as a decimal of the position (a loss > 0)
Expected shortfallexpected_shortfallreturn · [-100000, 100000]Expected shortfall as a decimal of the position (a loss > 0)
Value at risk amountvalue_at_risk_amountmoney · [-1e+15, 1e+15]VaR in money: the decimal times the position
Expected shortfall amountexpected_shortfall_amountmoney · [-1e+15, 1e+15]Expected shortfall in money: the decimal times the position
CalculationcalculationtextModified VaR and ES from skewness and kurtosis
Quantilequantileratio · [-1000, 1000]Cornish-Fisher quantile of the standardized loss at the confidence level (the normal quantile without skewness or excess kurtosis)
Historical-simulation VaR and ES (historical): 7 outputs
Outputs of the calculation historical
NameDescription
Value at riskvalue_at_riskreturn · [-100000, 100000]VaR as a decimal of the position (a loss > 0)
Expected shortfallexpected_shortfallreturn · [-100000, 100000]Expected shortfall as a decimal of the position (a loss > 0)
Value at risk amountvalue_at_risk_amountmoney · [-1e+15, 1e+15]VaR in money: the decimal times the position
Expected shortfall amountexpected_shortfall_amountmoney · [-1e+15, 1e+15]Expected shortfall in money: the decimal times the position
CalculationcalculationtextHistorical-simulation VaR and ES
Observationsobservationscount · [2, 10080]Returns used
Tail observationstail_observationscount · [1, 10080]Returns at or below the VaR quantile
Monte Carlo VaR and ES with standard errors (monte_carlo): 8 outputs
Outputs of the calculation monte_carlo
NameDescription
Value at riskvalue_at_riskreturn · [-100000, 100000]VaR as a decimal of the position (a loss > 0)
Expected shortfallexpected_shortfallreturn · [-100000, 100000]Expected shortfall as a decimal of the position (a loss > 0)
Value at risk amountvalue_at_risk_amountmoney · [-1e+15, 1e+15]VaR in money: the decimal times the position
Expected shortfall amountexpected_shortfall_amountmoney · [-1e+15, 1e+15]Expected shortfall in money: the decimal times the position
CalculationcalculationtextMonte Carlo VaR and ES with standard errors
Value at risk standard errorvalue_at_risk_standard_errorreturn · [0, 100000]Standard error of the simulated VaR
Expected shortfall standard errorexpected_shortfall_standard_errorreturn · [0, 100000]Standard error of the simulated ES
Simulationssimulationscount · [10000, 1e+06]Simulated returns
RiskMetrics EWMA volatility with normal VaR and ES (ewma): 6 outputs
Outputs of the calculation ewma
NameDescription
Value at riskvalue_at_riskreturn · [-100000, 100000]VaR as a decimal of the position (a loss > 0)
Expected shortfallexpected_shortfallreturn · [-100000, 100000]Expected shortfall as a decimal of the position (a loss > 0)
Value at risk amountvalue_at_risk_amountmoney · [-1e+15, 1e+15]VaR in money: the decimal times the position
Expected shortfall amountexpected_shortfall_amountmoney · [-1e+15, 1e+15]Expected shortfall in money: the decimal times the position
CalculationcalculationtextRiskMetrics EWMA volatility with normal VaR and ES
Volatility forecastvolatility_forecastvolatility · [0, 100]Volatility forecast for the next period

Calculator

Run the model on your own inputs, starting from its example. Rates are decimals: 0.05 is five percent. The run goes to the pyeconomics API on this site: your values travel only in the request, and nothing is stored.

Loading the calculator…

Worked example

Example ten_day_normal. Inputs:

{
  "calculation": "parametric",
  "confidence": 0.99,
  "horizon": 10,
  "mean": 0,
  "position_value": 1000000,
  "volatility": 0.012
}

Outputs:

{
  "calculation": "parametric",
  "expected_shortfall": 0.10113776866275152,
  "expected_shortfall_amount": 101137.76866275152,
  "quantile": 2.3263478740408408,
  "value_at_risk": 0.08827869494231466,
  "value_at_risk_amount": 88278.69494231466
}

Assumptions

  • Losses are positive decimals of the position's value; a negative VaR is a gain at that confidence.
  • Scaling to a horizon of h periods by the square root of h assumes i.i.d. returns; the historical method scales its one-period quantile and tail mean the same way.
  • The historical and Monte Carlo ES is the mean loss at or beyond the VaR quantile; the quantile interpolates as the input names (Monte Carlo: linearly).
  • The Monte Carlo horizon return is drawn directly, normal or Student-t scaled to the volatility; the Student-t horizon return is not a sum of t draws.
  • The EWMA forecast assumes a zero mean and starts its recursion from the first squared return, as RiskMetrics' Table 5.3 does.

Limitations

  • The Cornish-Fisher expansion is valid only for moderate skewness and kurtosis: outside its domain the quantile is not monotone in the confidence level, and the model warns.
  • When the Edgeworth tail mean lies above the Cornish-Fisher quantile, the modified ES is set to the VaR, with a warning.
  • An output outside its bounds raises DomainError; the input bounds are sized so that none is known to occur.
  • No method models volatility clustering except the EWMA forecast.

Evidence

Status: standard. Textbook consensus, such as bond duration or the CAPM formula.

Every model declares one status: standard (textbook consensus), practitioner (a widely used convention), contested (under active debate), rejected (failed out of sample) or historical (a superseded methodology).

Syllabus

The 2027 CFA® Program's topic areas this model relates to, as factual tags. Each links to CFA Institute's page for its level; pyeconomics holds none of the curriculum's text.

Citations

  1. Boudt, K., Peterson, B. and Croux, C. (2008). Estimation and decomposition of downside risk for portfolios with non-normal returns. The Journal of Risk, 11(2), 79-103. doi:10.21314/JOR.2008.188 (Section 2: modified VaR (after Zangari, 1996, RiskMetrics Monitor) and modified ES from the Edgeworth expansion)
  2. Cornish, E. A. and Fisher, R. A. (1938). Moments and cumulants in the specification of distributions. Revue de l'Institut International de Statistique, 5(4), 307-320. doi:10.2307/1400905 (The expansion of a quantile in terms of cumulants)
  3. Hyndman, R. J. and Fan, Y. (1996). Sample quantiles in statistical packages. The American Statistician, 50(4), 361-365. doi:10.1080/00031305.1996.10473566 (Section 2, definitions 1 to 9 (definition 7 is linear interpolation))
  4. J.P. Morgan and Reuters (1996). RiskMetrics Technical Document, 4th ed. Morgan Guaranty Trust Company. https://www.msci.com/documents/10199/5915b101-4206-4ba0-aee2-3449d5c7e95a (Section 5.2.1, Eq. [5.3] and Table 5.3 (the recursive EWMA variance, seeded with the first squared return; decay 0.94 for daily data); Eq. [5.21] (the square-root-of-time rule))
  5. Basel Committee on Banking Supervision (2019). Minimum capital requirements for market risk. Bank for International Settlements. https://www.bis.org/bcbs/publ/d457.htm (MAR33.3 (ES at 97.5%) and MAR32.5 (VaR at 99% for backtesting))
  6. Glasserman, P. (2003). Monte Carlo Methods in Financial Engineering. Springer. https://openlibrary.org/isbn/9780387004518 (Section 9.1 (the standard error of an estimated quantile)). ISBN 9780387004518
  7. Manistre, B. J. and Hancock, G. H. (2005). Variance of the CTE estimator. North American Actuarial Journal, 9(2), 129-156. doi:10.1080/10920277.2005.10596207 (The asymptotic variance of the empirical CTE)

Changelog

  • Version 1: First version.

Use it elsewhere

Documentation
The model's reference page
REST API
GET or POST /v1/models/risk.value_at_risk/run
MCP tool
risk_value_at_risk, or run_model with the model's id; both give the same result. Connect an assistant
Command line
pyeconomics models run risk.value_at_risk --help

The worked example, from Python and from the command line:

Python
import pyeconomics

inputs = {
    "calculation": "parametric",
    "confidence": 0.99,
    "horizon": 10,
    "mean": 0,
    "position_value": 1000000,
    "volatility": 0.012,
}
result = pyeconomics.run("risk.value_at_risk", inputs)
print(result.to_json())
Command line
pyeconomics models run risk.value_at_risk --inputs - <<'JSON'
{
  "calculation": "parametric",
  "confidence": 0.99,
  "horizon": 10,
  "mean": 0,
  "position_value": 1000000,
  "volatility": 0.012
}
JSON