VaR for the Normal distribution
To get accustomed to the Value at Risk (VaR) measure, it helps to apply it to a known distribution. The Normal (or Gaussian) distribution is especially appealing as it 1) has an analytically simple form, and 2) represents a wide variety of empirical phenomena. For this exercise you'll assume that the loss of a portfolio is normally distributed, i.e., the higher the value drawn from the distribution, the higher the loss.
You'll learn how to apply both scipy.stats.norm
's ppf()
(percent point function) and numpy
's quantile()
function to find the VaR at the 95% and 99% confidence levels, respectively, for a standard Normal distribution. You'll also visualize the VaR as a threshold on a Normal distribution plot.
Diese Übung ist Teil des Kurses
Quantitative Risk Management in Python
Anleitung zur Übung
- Use
norm
's.ppf()
percent point function to find the VaR measure at the 95% confidence level. - Now find the 99% VaR measure using Numpy's
quantile()
function applied to 100,000 random Normaldraws
. - Compare the 95% and 99% VaR measures using a
print
statement. - Plot the Normal distribution, and add a line indicating the 95% VaR.
Interaktive Übung zum Anfassen
Probieren Sie diese Übung aus, indem Sie diesen Beispielcode ausführen.
# Create the VaR measure at the 95% confidence level using norm.ppf()
VaR_95 = norm.ppf(____)
# Create the VaR measure at the 99% confidence level using numpy.quantile()
draws = norm.rvs(size = 100000)
VaR_99 = np.quantile(____, 0.99)
# Compare the 95% and 99% VaR
print("95% VaR: ", ____, "; 99% VaR: ", ____)
# Plot the normal distribution histogram and 95% VaR measure
plt.hist(draws, bins = 100)
plt.axvline(x = ____, c='r', label = "VaR at 95% Confidence Level")
plt.legend(); plt.show()