Aan de slagGa gratis aan de slag

Comparing CVaR and VaR

The conditional value at risk (CVaR), or expected shortfall (ES), asks what the average loss will be, conditional upon losses exceeding some threshold at a certain confidence level. It uses VaR as a point of departure, but contains more information because it takes into consideration the tail of the loss distribution.

You'll first compute the 95% VaR for a Normal distribution of portfolio losses, with the same mean and standard deviation as the 2005-2010 investment bank portfolio_losses. You'll then use the VaR to compute the 95% CVaR, and plot both against the Normal distribution.

The portfolio_losses are available in your workspace, as well as the norm Normal distribution from scipy.stats.

Deze oefening maakt deel uit van de cursus

Quantitative Risk Management in Python

Cursus bekijken

Oefeninstructies

  • Compute the mean and standard deviation of portfolio_losses and assign them to pm and ps, respectively.
  • Find the 95% VaR using norm's .ppf() method--this takes arguments loc for the mean and scale for the standard deviation.
  • Use the 95% VaR and norm's .expect() method to find the tail_loss, and use it to compute the CVaR at the same level of confidence.
  • Add vertical lines showing the VaR (in red) and the CVaR (in green) to a histogram plot of the Normal distribution.

Praktische interactieve oefening

Probeer deze oefening eens door deze voorbeeldcode in te vullen.

# Compute the mean and standard deviation of the portfolio returns
pm = portfolio_losses.____
ps = portfolio_losses.____

# Compute the 95% VaR using the .ppf()
VaR_95 = norm.ppf(0.95, loc = ____, scale = ____)
# Compute the expected tail loss and the CVaR in the worst 5% of cases
tail_loss = norm.____(lambda x: x, loc = ____, scale = ____, lb = VaR_95)
CVaR_95 = (1 / (1 - 0.95)) * ____

# Plot the normal distribution histogram and add lines for the VaR and CVaR
plt.hist(norm.rvs(size = 100000, loc = pm, scale = ____), bins = 100)
plt.axvline(x = VaR_95, c='r', label = "VaR, 95% confidence level")
plt.axvline(x = ____, c='g', label = "CVaR, worst 5% of outcomes")
plt.legend(); plt.show()
Code bewerken en uitvoeren