Extreme values and backtesting
Extreme values are those which exceed a threshold and are used to determine if risk measures such as VaR are accurately reflecting the risk of loss.
You'll explore extreme values by computing the 95% VaR of the equally-weighted investment bank portfolio for 2009-2010 (recall that this is equivalent to historical simulation from 2010 onwards), and then backtesting on data from 2007-2008.
2009-2010 portfolio losses are available in estimate_data
, from which you'll compute the 95% VaR estimate. Then find extreme values exceeding the VaR estimate, from the 2007-2008 portfolio losses in the available backtest_data
.
Compare the relative frequency of extreme values to the 95% VaR, and finally visualize the extreme values with a stem plot.
Cet exercice fait partie du cours
Quantitative Risk Management in Python
Instructions
- Compute the 95% VaR on
estimate_data
usingnp.quantile()
. - Find the
extreme_values
frombacktest_data
usingVaR_95
as the loss threshold. - Compare the relative frequency of
extreme_values
to theVaR_95
estimate. Are they the same? - Display a stem plot of
extreme_values
, showing how large deviations clustered during the crisis.
Exercice interactif pratique
Essayez cet exercice en complétant cet exemple de code.
# Compute the 95% VaR on 2009-2010 losses
VaR_95 = ____.____(estimate_data, 0.95)
# Find backtest_data exceeding the 95% VaR
extreme_values = backtest_data[____ > VaR_95]
# Compare the fraction of extreme values for 2007-2008 to the Var_95 estimate
print("VaR_95: ", VaR_95, "; Backtest: ", len(____) / len(backtest_data) )
# Plot the extreme values and look for clustering
plt.stem(extreme_values.index, ____)
plt.ylabel("Extreme values > VaR_95"); plt.xlabel("Date")
plt.show()