توضیح 1
The live starter code is self-contained and uses only runner-compatible functions.
Loading
درس 20 از 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.
توضیح 1
The live starter code is self-contained and uses only runner-compatible functions.
توضیح 2
Book-only outputs are labelled when the separate source dataset or advanced package was not supplied.
توضیح 3
R code, paths, function names, and formulas remain left-to-right in every locale.
اصطلاحات
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
نمادگذاری و فرمولها
VaR_p = quantile_p(loss); ES_p = mean(loss | loss >= VaR_p)
Losses are positive in this convention, so upper quantiles measure risk.
مثال حلشده
سناریو
What are historical 95% VaR and expected shortfall for a simulated heavy-tailed loss sample?
بررسی با R
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
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.
تمرین هدایتشده
سناریو
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.
توضیح 1
Compute historical 99% VaR and ES.
توضیح 2
Derive normal-theory ES.
توضیح 3
Inspect mean excess across thresholds.
Selected solutions
These are compact solution routes. Confirm dimensions, units, and any changed modelling choices.
توضیح 1
quantile(loss,.99); mean(loss[loss>=quantile(loss,.99)])
توضیح 2
mean(loss)+sd(loss)*dnorm(qnorm(p))/(1-p)
توضیح 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.
توضیح 1
VaR is a quantile; ES measures tail severity.
توضیح 2
Methods embed different assumptions.
توضیح 3
Backtests must be prior-only.
توضیح 4
EVT extrapolation needs sensitivity analysis.
اصطلاحات
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.
منبع
The authoritative 125-page English PDF accompanies this native lesson.
دریافتبازاندیشی
Name the assumption, evidence you would seek, and how the recommendation might change.
ارزیابی پایانی