MulaiMulai sekarang secara gratis

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.

Latihan ini adalah bagian dari kursus

Quantitative Risk Management in Python

Lihat Kursus

Petunjuk latihan

  • 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.

Latihan interaktif praktis

Cobalah latihan ini dengan menyelesaikan kode contoh berikut.

# 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)
Edit dan Jalankan Kode