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
Where
- Value-at-risk: the loss the confidence level leaves a chance of exceeding
value_at_risk - Expected shortfall: the average loss beyond value-at-risk
expected_shortfall - Mean return per period
mean - Volatility per period
volatility - Horizon, in periods
horizon - Confidence level
confidence - The standard normal quantile at the confidence level
- The standard normal density
- The Cornish-Fisher quantile, adjusted for skewness and kurtosis
quantile - The standard normal quantile at one less the confidence level
- Skewness of the returns
skewness - Excess kurtosis of the returns
excess_kurtosis - Modified expected shortfall
expected_shortfall - A probabilists' Hermite polynomial; He_4 and He_6 are the fourth and the sixth
- The returns' empirical quantile at one less the confidence level
quantile - The return in period t
returns - The decay of the exponentially weighted variance
decay - The exponentially weighted variance in period t
- Number of returns, or of simulations
observations - The density of the returns at the quantile
- 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
| Name | Unit | Bounds | Description |
|---|---|---|---|
Calculationcalculationtext | text | Normal VaR and ES | |
Meanmeanreturn · [-1, 1] | return | [-1, 1] | Mean return per period |
Volatilityvolatilityvolatility · (0, 2] | volatility | (0, 2] | Standard deviation of returns per period |
Confidenceconfidenceprobability · [0.5, 0.9999] | probability | [0.5, 0.9999] | One-tailed confidence level, such as 0.99 |
Horizonhorizonperiods · [1, 1000] | periods | [1, 1000] | Horizon in periods of the returns, such as 10 days |
Position valueposition_valuemoney · (0, 1e+10] | money | (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
| Name | Unit | Bounds | Description |
|---|---|---|---|
Calculationcalculationtext | text | Modified VaR and ES from skewness and kurtosis | |
Meanmeanreturn · [-1, 1] | return | [-1, 1] | Mean return per period |
Volatilityvolatilityvolatility · (0, 2] | volatility | (0, 2] | Standard deviation of returns per period |
Skewnessskewnessratio · [-3, 3] | ratio | [-3, 3] | Skewness of returns per period |
Excess kurtosisexcess_kurtosisratio · [-2, 20] | ratio | [-2, 20] | Excess kurtosis of returns per period |
Confidenceconfidenceprobability · [0.5, 0.9999] | probability | [0.5, 0.9999] | One-tailed confidence level, such as 0.99 |
Horizonhorizonperiods · [1, 1000] | periods | [1, 1000] | Horizon in periods of the returns, such as 10 days |
Position valueposition_valuemoney · (0, 1e+10] | money | (0, 1e+10] | Position value; the default of 1 makes the amounts the decimals |
Historical-simulation VaR and ES (historical): 6 inputs
| Name | Unit | Bounds | Description |
|---|---|---|---|
Calculationcalculationtext | text | Historical-simulation VaR and ES | |
Returnsreturnsreturn (array) · length min 2, max 10080; each [-1, 100] | return (array) | length min 2, max 10080; each [-1, 100] | Returns per period, in time order |
Interpolationinterpolationtext | text | How the quantile falls between two returns (NumPy's methods; linear is Hyndman and Fan's definition 7) | |
Confidenceconfidenceprobability · [0.5, 0.9999] | probability | [0.5, 0.9999] | One-tailed confidence level, such as 0.99 |
Horizonhorizonperiods · [1, 1000] | periods | [1, 1000] | Horizon in periods of the returns, such as 10 days |
Position valueposition_valuemoney · (0, 1e+10] | money | (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
| Name | Unit | Bounds | Description |
|---|---|---|---|
Calculationcalculationtext | text | Monte Carlo VaR and ES with standard errors | |
Meanmeanreturn · [-1, 1] | return | [-1, 1] | Mean return per period |
Volatilityvolatilityvolatility · (0, 2] | volatility | (0, 2] | Standard deviation of returns per period |
Distributiondistributiontext | text | Distribution of the standardized horizon return | |
Degrees of freedomdegrees_of_freedomratio · (2, 1000] | ratio | (2, 1000] | Student-t degrees of freedom; ignored for the normal |
Simulationssimulationscount · [10000, 1e+06] | count | [10000, 1e+06] | Number of simulated horizon returns |
Seedseedcount · [0, 9.0072e+15] | count | [0, 9.0072e+15] | Random seed (ADR-0008 decision 7): the same seed, the same draws |
Confidenceconfidenceprobability · [0.5, 0.9999] | probability | [0.5, 0.9999] | One-tailed confidence level, such as 0.99 |
Horizonhorizonperiods · [1, 1000] | periods | [1, 1000] | Horizon in periods of the returns, such as 10 days |
Position valueposition_valuemoney · (0, 1e+10] | money | (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
| Name | Unit | Bounds | Description |
|---|---|---|---|
Calculationcalculationtext | text | RiskMetrics EWMA volatility with normal VaR and ES | |
Returnsreturnsreturn (array) · length min 1, max 10080; each [-1, 100] | return (array) | length min 1, max 10080; each [-1, 100] | Returns per period, oldest first |
Decaydecayratio · [0.5, 0.999] | ratio | [0.5, 0.999] | Decay factor lambda (RiskMetrics uses 0.94 for daily data) |
Confidenceconfidenceprobability · [0.5, 0.9999] | probability | [0.5, 0.9999] | One-tailed confidence level, such as 0.99 |
Horizonhorizonperiods · [1, 1000] | periods | [1, 1000] | Horizon in periods of the returns, such as 10 days |
Position valueposition_valuemoney · (0, 1e+10] | money | (0, 1e+10] | Position value; the default of 1 makes the amounts the decimals |
Outputs
Normal VaR and ES (parametric): 6 outputs
| Name | Unit | Bounds | Description |
|---|---|---|---|
Value at riskvalue_at_riskreturn · [-100000, 100000] | return | [-100000, 100000] | VaR as a decimal of the position (a loss > 0) |
Expected shortfallexpected_shortfallreturn · [-100000, 100000] | return | [-100000, 100000] | Expected shortfall as a decimal of the position (a loss > 0) |
Value at risk amountvalue_at_risk_amountmoney · [-1e+15, 1e+15] | money | [-1e+15, 1e+15] | VaR in money: the decimal times the position |
Expected shortfall amountexpected_shortfall_amountmoney · [-1e+15, 1e+15] | money | [-1e+15, 1e+15] | Expected shortfall in money: the decimal times the position |
Calculationcalculationtext | text | Normal VaR and ES | |
Quantilequantileratio · [0, 4] | ratio | [0, 4] | Standard normal quantile of the loss at confidence c |
Modified VaR and ES from skewness and kurtosis (cornish_fisher): 6 outputs
| Name | Unit | Bounds | Description |
|---|---|---|---|
Value at riskvalue_at_riskreturn · [-100000, 100000] | return | [-100000, 100000] | VaR as a decimal of the position (a loss > 0) |
Expected shortfallexpected_shortfallreturn · [-100000, 100000] | return | [-100000, 100000] | Expected shortfall as a decimal of the position (a loss > 0) |
Value at risk amountvalue_at_risk_amountmoney · [-1e+15, 1e+15] | money | [-1e+15, 1e+15] | VaR in money: the decimal times the position |
Expected shortfall amountexpected_shortfall_amountmoney · [-1e+15, 1e+15] | money | [-1e+15, 1e+15] | Expected shortfall in money: the decimal times the position |
Calculationcalculationtext | text | Modified VaR and ES from skewness and kurtosis | |
Quantilequantileratio · [-1000, 1000] | ratio | [-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
| Name | Unit | Bounds | Description |
|---|---|---|---|
Value at riskvalue_at_riskreturn · [-100000, 100000] | return | [-100000, 100000] | VaR as a decimal of the position (a loss > 0) |
Expected shortfallexpected_shortfallreturn · [-100000, 100000] | return | [-100000, 100000] | Expected shortfall as a decimal of the position (a loss > 0) |
Value at risk amountvalue_at_risk_amountmoney · [-1e+15, 1e+15] | money | [-1e+15, 1e+15] | VaR in money: the decimal times the position |
Expected shortfall amountexpected_shortfall_amountmoney · [-1e+15, 1e+15] | money | [-1e+15, 1e+15] | Expected shortfall in money: the decimal times the position |
Calculationcalculationtext | text | Historical-simulation VaR and ES | |
Observationsobservationscount · [2, 10080] | count | [2, 10080] | Returns used |
Tail observationstail_observationscount · [1, 10080] | count | [1, 10080] | Returns at or below the VaR quantile |
Monte Carlo VaR and ES with standard errors (monte_carlo): 8 outputs
| Name | Unit | Bounds | Description |
|---|---|---|---|
Value at riskvalue_at_riskreturn · [-100000, 100000] | return | [-100000, 100000] | VaR as a decimal of the position (a loss > 0) |
Expected shortfallexpected_shortfallreturn · [-100000, 100000] | return | [-100000, 100000] | Expected shortfall as a decimal of the position (a loss > 0) |
Value at risk amountvalue_at_risk_amountmoney · [-1e+15, 1e+15] | money | [-1e+15, 1e+15] | VaR in money: the decimal times the position |
Expected shortfall amountexpected_shortfall_amountmoney · [-1e+15, 1e+15] | money | [-1e+15, 1e+15] | Expected shortfall in money: the decimal times the position |
Calculationcalculationtext | text | Monte Carlo VaR and ES with standard errors | |
Value at risk standard errorvalue_at_risk_standard_errorreturn · [0, 100000] | return | [0, 100000] | Standard error of the simulated VaR |
Expected shortfall standard errorexpected_shortfall_standard_errorreturn · [0, 100000] | return | [0, 100000] | Standard error of the simulated ES |
Simulationssimulationscount · [10000, 1e+06] | count | [10000, 1e+06] | Simulated returns |
RiskMetrics EWMA volatility with normal VaR and ES (ewma): 6 outputs
| Name | Unit | Bounds | Description |
|---|---|---|---|
Value at riskvalue_at_riskreturn · [-100000, 100000] | return | [-100000, 100000] | VaR as a decimal of the position (a loss > 0) |
Expected shortfallexpected_shortfallreturn · [-100000, 100000] | return | [-100000, 100000] | Expected shortfall as a decimal of the position (a loss > 0) |
Value at risk amountvalue_at_risk_amountmoney · [-1e+15, 1e+15] | money | [-1e+15, 1e+15] | VaR in money: the decimal times the position |
Expected shortfall amountexpected_shortfall_amountmoney · [-1e+15, 1e+15] | money | [-1e+15, 1e+15] | Expected shortfall in money: the decimal times the position |
Calculationcalculationtext | text | RiskMetrics EWMA volatility with normal VaR and ES | |
Volatility forecastvolatility_forecastvolatility · [0, 100] | volatility | [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
- 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)
- 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)
- 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))
- 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))
- 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))
- 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
- 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, orrun_modelwith 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:
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())
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