VaR from a fitted distribution

Minimizing CVaR requires calculating the VaR at a confidence level, say 95%. Previously you derived the VaR as a quantile from a Normal (or Gaussian) distribution, but minimizing the CVaR more generally requires computing the quantile from a distribution that best fits the data.

In this exercise a fitted loss distribution is provided, which fits losses from an equal-weighted investment bank portfolio from 2005-2010. You'll first plot this distribution using its .evaluate() method (fitted distributions will be covered in more detail in Chapter 4).

Next you'll use the .resample() method of the fitted object to draw a random sample of 100,000 observations from the fitted distribution.

Finally, using np.quantile() on the random sample will then compute the 95% VaR.

Diese Übung ist Teil des Kurses

Quantitative Risk Management in Python

Kurs anzeigen

Anleitung zur Übung

  • Plot the fitted loss distribution. Notice how the fitted distribution is different from a Normal distribution.
  • Create a 100,000 point sample of random draws from the fitted distribution using fitted's .resample() method.
  • Use np.quantile() to find the 95% VaR from the random sample, and display the result.

Interaktive Übung zum Anfassen

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

# Visualize the fitted distribution with a plot
x = np.linspace(-0.25,0.25,1000)
plt.____(x,fitted.evaluate(x))
plt.show()

# Create a random sample of 100,000 observations from the fitted distribution
sample = fitted.____(____)

# Compute and display the 95% VaR from the random sample
VaR_95 = np.____(sample, ____)
print(VaR_95)