Explanation 1
The live starter code is self-contained and uses only runner-compatible functions.
Loading
Lesson 20 of 22
Advanced Topic – Optional. Define loss consistently, estimate tail risk, backtest prior-only forecasts, and qualify extreme-value extrapolation.
Advanced Topic – Optional
This chapter extends the core pathway. Complete Chapters 1–14 first, then use this material when your question and data justify the added model complexity.
Motivation
A risk number is actionable only when loss definition, horizon, confidence level, unit, model, and validation status stay attached.
Why this matters
Define loss consistently, estimate tail risk, backtest prior-only forecasts, and qualify extreme-value extrapolation.
Packages and data
Base R; PerformanceAnalytics, rugarch, and evir are optional.
Explanation 1
The live starter code is self-contained and uses only runner-compatible functions.
Explanation 2
Book-only outputs are labelled when the separate source dataset or advanced package was not supplied.
Explanation 3
R code, paths, function names, and formulas remain left-to-right in every locale.
Terminology
An upper loss quantile at stated probability and horizon.
Says little about severity beyond threshold
Average loss in the selected tail.
For continuous tails ES is at least VaR
Compares outcomes with forecasts made using prior information only.
Coverage and clustering matter
Notation and formulas
VaR_p = quantile_p(loss); ES_p = mean(loss | loss >= VaR_p)
Losses are positive in this convention, so upper quantiles measure risk.
Worked example
Scenario
What are historical 95% VaR and expected shortfall for a simulated heavy-tailed loss sample?
R check
set.seed(2020)
loss <- -100*(rt(2400,df=6)*.012/sqrt(6/4))
var95 <- unname(quantile(loss,.95))
es95 <- mean(loss[loss>=var95])
var99 <- unname(quantile(loss,.99))
es99 <- mean(loss[loss>=var99])
print(data.frame(level=c(.95,.99),VaR=c(var95,var99),ES=c(es95,es99)))
stopifnot(es95>=var95,es99>=var99,var99>=var95)Expected shortfall is larger because it averages losses beyond the VaR threshold. Limitation: Simulation choice, tail distribution, liquidity, horizon, and threshold uncertainty remain; this is not investment or regulatory advice.
Visual
Expected shortfall exceeds VaR, and higher confidence moves farther into the tail.
R connection
Run the self-contained starter code in the protected STATLAB R runner. The code prints an auditable result and avoids network or unrestricted file access.
Live R Lab
Run a self-contained example, verify its output, and explain one limitation for market risk: var, expected shortfall, and evt.
Ready to run
Common mistake
Do not switch loss signs halfway through a workflow.
STATLAB Tip
Unit-test monotonicity: 99% VaR ≥ 95% VaR and ES ≥ VaR for a continuous upper tail.
Guided practice
Scenario
Build a prior-250-observation rolling 99% VaR and inspect both exception rate and clustering.
Compare your result with the definition, units, and model assumptions—not only with a target number.
Exercises
Complete these without looking at the selected solutions. More than one defensible program may exist.
Explanation 1
Compute historical 99% VaR and ES.
Explanation 2
Derive normal-theory ES.
Explanation 3
Inspect mean excess across thresholds.
Selected solutions
These are compact solution routes. Confirm dimensions, units, and any changed modelling choices.
Explanation 1
quantile(loss,.99); mean(loss[loss>=quantile(loss,.99)])
Explanation 2
mean(loss)+sd(loss)*dnorm(qnorm(p))/(1-p)
Explanation 3
Look for a plausible stability region and disclose sparse-tail uncertainty.
Chapter summary
Define loss consistently, estimate tail risk, backtest prior-only forecasts, and qualify extreme-value extrapolation.
Explanation 1
VaR is a quantile; ES measures tail severity.
Explanation 2
Methods embed different assumptions.
Explanation 3
Backtests must be prior-only.
Explanation 4
EVT extrapolation needs sensitivity analysis.
Terminology
historical VaR
Use in Market Risk: VaR, Expected Shortfall, and EVT.
exception rate
Use in Market Risk: VaR, Expected Shortfall, and EVT.
portfolio VaR
Use in Market Risk: VaR, Expected Shortfall, and EVT.
tail fit
Use in Market Risk: VaR, Expected Shortfall, and EVT.
References and provenance
Artzner et al. (1999); Safavi (2026), Chapter 20. Student notes: Mohammad Safavi, Ph.D., STATLAB Academy, Version 1.0.
Resource
The authoritative 125-page English PDF accompanies this native lesson.
DownloadReflection
Name the assumption, evidence you would seek, and how the recommendation might change.
Exit check
Reach 70% to complete the chapter. Explanations appear after submission.
Checkpoint
Question 1 of 2. Answered 0/2. Passing score: 70%.