LoslegenKostenlos loslegen

Computing VaR and ES for normal distribution

The standard function qnorm() calculates quantiles of a normal distribution from the probability p, the mean, and standard deviation, and thus can be used to calculate value-at-risk (VaR). The function ESnorm() from the QRM package calculates the expected shortfall (ES) for a normal distribution from the probability p, location parameter mu, and scale parameter sd:

qnorm(p, mean = 0, sd = 1)
ESnorm(p, mu = 0, sd = 1)

Common numeric values for p include 0.95 and 0.99 for confidence levels of 95% and 99%, respectively.

In this exercise, you will compute and display VaR and ES for a normal distribution \(N(\mu, \sigma^2)\) with mean \(\mu\) and standard deviation \(\sigma\). In the process, you will use the new functions for sequence generation and adding straight lines to a plot. You can read about their arguments by typing in ?seq and ?abline to your console.

The variables mu and sigma contain the estimated mean and standard deviation of the Dow Jones index returns for 2008-2009 contained in djx. All three objects are available in your workspace.

Diese Übung ist Teil des Kurses

Quantitative Risk Management in R

Kurs anzeigen

Anleitung zur Übung

  • Fill in seq() to make a sequence of 100 x-values going from \(-4\sigma\) to \(4\sigma\) and assign to xvals.
  • Fill in dnorm() to compute the density of a \(N(\mu, \sigma^2)\) distribution at xvals and assign to ndens.
  • Plot ndens against xvals using type = "l".
  • Use qnorm() and ESnorm() to compute the 99% VaR and 99% ES of the distribution and assign to VaR99 and ES99, respectively.
  • Fill in abline() to create vertical lines for VaR99 and ES99 in red and green, respectively.

Interaktive Übung

Versuche dich an dieser Übung, indem du diesen Beispielcode vervollständigst.

# Make a sequence of 100 x-values going from -4*sigma to 4*sigma
___ <- seq(from = -4*sigma, to = 4*sigma, length.out = ___)

# Compute the density of a N(mu, sigma^2) distribution at xvals
___ <- dnorm(___, mean = ___, sd = ___)

# Plot ndens against xvals


# Compute the 99% VaR and 99% ES of a N(mu, sigma^2) distribution
___ <- qnorm(___, mean = ___, sd = ___)
___ <- ESnorm(___, mu = ___, sd = ___)

# Draw vertical lines at VaR99 and ES99 in red and green
abline(v = ___, col = "red")
abline(v = ___, col = "green")
Code bearbeiten und ausführen