VaR and risk exposure

Previously you computed the VaR and CVaR when losses were Normally distributed. Here you'll find the VaR using another common loss distribution, the Student's t-distribution (or T) contained in scipy.stats.

You'll compute an array of 99% VaR measures from the T distribution (with 30 - 1 = 29 degrees of freedom), using 30-day rolling windows from investment bank portfolio losses.

First you'll find the mean and standard deviation of each window, creating a list of rolling_parameters. You'll use these to compute the 99% VaR array of measures.

Then you'll use this array to plot the risk exposure for a portfolio initially worth $100,000. Recall that risk exposure is the probability of loss (this is 1%) multiplied by the loss amount (this is the loss given by the 99% VaR).

Diese Übung ist Teil des Kurses

Quantitative Risk Management in Python

Kurs anzeigen

Anleitung zur Übung

  • Import the Student's t-distribution from scipy.stats.
  • Compute the 30-day window mean mu and standard deviation sigma vectors from losses, and place into rolling_parameters.
  • Compute a Numpy array of 99% VaR measures VaR_99 using t.ppf(), from a list of T distributions using the elements of rolling_parameters.
  • Compute and visualize the risk exposure associated with the VaR_99 array.

Interaktive Übung zum Anfassen

Probieren Sie diese Übung aus, indem Sie diesen Beispielcode ausführen.

# Import the Student's t-distribution
from scipy.____ import t

# Create rolling window parameter list
mu = losses.rolling(30).____
sigma = losses.rolling(30).____
rolling_parameters = [(29, mu[i], s) for i,s in enumerate(sigma)]

# Compute the 99% VaR array using the rolling window parameters
VaR_99 = np.array( [ t.ppf(____, *params) 
                    for params in ____ ] )

# Plot the minimum risk exposure over the 2005-2010 time period
plt.plot(losses.index, 0.01 * ____ * 100000)
plt.show()