Get startedGet started for free

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.

This exercise is part of the course

Quantitative Risk Management in Python

View Course

Exercise instructions

  • 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 Normal draws.
  • Compare the 95% and 99% VaR measures using a print statement.
  • Plot the Normal distribution, and add a line indicating the 95% VaR.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# 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()
Edit and Run Code