Value at risk (VaR)

Using only knowledge from Chapters 2, 4, and 5 of SDAFE

Andrew Pua

2024-06-14

Motivation

  1. The worst that could happen is we lose everything due to changes in prices. This means that the net return is \(R_t = -1\).
  2. But this is not very useful as a way to measure market risk.
  3. We need a meaningful and quantifiable measure of risk which incorporates the uncertainty of returns.

Value at risk (VaR)

  1. Think of loss as monetary loss in positive terms.

    • Usually, we write \(-350\) pesos to represent loss.
    • But in Chapter 19, it is represented as a loss of 350 pesos.
  2. Fix a horizon \(T\) and a confidence coefficient \(1-\alpha\).

    • The phrase “confidence coefficient” is technically and conceptually different from confidence level.

Value at risk (VaR)

  1. Let \(\mathcal{L}\) be the loss over the holding period \(T\). Then the \(\mathsf{VaR}(\alpha)\) is the \(\alpha\)th upper quantile of \(\mathcal{L}\).

  2. For simplicity, we focus on continuous loss distributions. By definition, we have \[\mathbb{P}\left(\mathcal{L} > \mathsf{VaR}(\alpha)\right)=\alpha.\]

  3. There is a \(100\alpha\)% chance of a loss exceeding \(\mathsf{VaR}(\alpha)\) over the holding period \(T\).

Value at risk (VaR)

  1. You can frame VaR as:

    • Rule out the \(100\alpha\)% worst things that might happen over some holding period.
    • How low could my investment go if I exclude the worst \(100\alpha\)% of outcomes?

Example 19.1

  • Yearly returns of a stock are normally distributed with mean 0.04 and standard deviation 0.18.
  • If you have $100,000 worth of stock, what is the VaR for a holding period of 1 year?
  • Apply Chapters 2 and 4 only: Require knowledge of normal distributions and quantiles.
  • Pay attention book has an egregious typo!

Example 19.1

  • Very unrealistic!

    • Requires you know the distribution of returns
    • Requires you know the population mean and population standard deviation of the yearly returns
  • Admittedly, easy to calculate.

  • Have to believe that stationarity also holds over the holding period.

Directions

  1. VaR works by excluding the worst \(100\alpha\)% of outcomes.
  2. But those excluded losses may materialize and your risk measure fails to account for that!
  3. Use an alternative measure called expected shortfall.

Directions

  1. Even if you are willing to accept VaR deficiencies, Example 19.1 is only a baseline.

  2. You must estimate the distribution of returns and/or some its features.

    • Use some nonparametric approaches from Chapter 4.
    • Use parametric approaches from Chapter 5.
  3. You must accept that there is uncertainty in your measurements too.

    • Leads to Chapter 6 on the bootstrap.

Expected shortfall

  • Define expected shortfall \(\mathsf{ES}(\alpha)\) as \[\mathsf{ES}(\alpha)=\frac{\int_0^{\alpha} \mathsf{VaR}(u)\, du }{\alpha}\] or \[\mathsf{ES}(\alpha)=\mathbb{E}\left(\mathcal{L} | \mathcal{L} > \mathsf{VaR}(\alpha)\right)\]

  • Best prediction of the losses given that losses exceed a threshold

Estimating VaR and ES

  1. Nonparametrically: no model assumed
  2. Parametrically: by assuming a model for returns
  3. In both cases, you use historical data and assume stationarity.
  4. As of this moment, you have to also assume independence, which may not be plausible.

Nonparametric estimation of VaR

  1. Let \(S>0\) be your fixed position denominated in a particular currency.
  2. Let \(R\) be returns which are treated as random variables having common cdf \(F\).
  3. The loss is \(\mathcal{L}=-SR\).
  4. Observe that \[\begin{eqnarray*}\alpha &=&\mathbb{P}\left(R < F^{-1}(\alpha)\right) \\ &=&\mathbb{P}\left(-SR > -SF^{-1}(\alpha)\right) = \mathbb{P}\left(\mathcal{L} > -SF^{-1}(\alpha)\right) \end{eqnarray*}\]

Nonparametric estimation of VaR

  1. Therefore, \[\mathsf{VaR}(\alpha)=-S\times F^{-1}(\alpha).\]

  2. But \(F\) is unknown. So we estimate it using the empirical cdf. Therefore, \[\widehat{\mathsf{VaR}}^{\mathsf{np}}(\alpha)=-S\times \widehat{F}^{-1}(\alpha).\]

    • The sample -quantile of the observed distribution of returns is \(\widehat{F}^{-1}(\alpha)\).

Nonparametric estimation of ES

  1. Since expected shortfall is \[\mathsf{ES}(\alpha)=\mathbb{E}\left(\mathcal{L} | \mathcal{L} > \mathsf{VaR}(\alpha)\right),\] we can directly estimate this by taking averages.

  2. Two unknowns here:

    • Population mean \(\mathbb{E}(\cdot)\) is involved.
    • \(\mathsf{VaR}(\alpha)\) has to be estimated.

Nonparametric estimation of ES

  1. Estimate \(\mathsf{VaR}(\alpha)\) using \(\widehat{\mathsf{VaR}}^{\mathsf{np}}(\alpha)\).
  2. Use a sample average to estimate the population average! Method of moments showing up here.
  3. Note that you should be plugging in consistent estimators for the unknown quantities.

Nonparametric estimation of ES

\[\begin{eqnarray*}\widehat{\mathsf{ES}}^{\mathsf{np}}(\alpha) &=&\frac{\displaystyle\frac{1}{n}\sum_{i=1}^n \mathcal{L}_i I(\mathcal{L}_i > \widehat{\mathsf{VaR}}^{\mathsf{np}}(\alpha))}{\displaystyle\frac{1}{n}\sum_{i=1}^n I(\mathcal{L}_i > \widehat{\mathsf{VaR}}^{\mathsf{np}}(\alpha))} \\ &=& \frac{\displaystyle\frac{1}{n}\sum_{i=1}^n -S\times R_i \times I(-S\times R_i > -S\times \widehat{F}^{-1}(\alpha))}{\displaystyle\frac{1}{n}\sum_{i=1}^n I(-S\times R_i > -S\times \widehat{F}^{-1}(\alpha))}\end{eqnarray*}\]

Nonparametric estimation of ES

\[\begin{eqnarray*}\widehat{\mathsf{ES}}^{\mathsf{np}}(\alpha) &=&\frac{\displaystyle\frac{1}{n}\sum_{i=1}^n \mathcal{L}_i I(\mathcal{L}_i > \widehat{\mathsf{VaR}}^{\mathsf{np}}(\alpha))}{\displaystyle\frac{1}{n}\sum_{i=1}^n I(\mathcal{L}_i > \widehat{\mathsf{VaR}}^{\mathsf{np}}(\alpha))} \\ &=& -S\times \frac{\displaystyle\frac{1}{n}\sum_{i=1}^n R_i \times I( R_i < \widehat{F}^{-1}(\alpha))}{\displaystyle\frac{1}{n}\sum_{i=1}^n I( R_i < \widehat{F}^{-1}(\alpha))}\end{eqnarray*}\]

Parametric estimation of VaR

  1. Suppose you assume a parametric model for the returns and that \(\boldsymbol\theta\) is a vector of parameters.
  2. Instead of looking at \(F^{-1}(\alpha)\), we look at \(F^{-1}(\alpha | \boldsymbol\theta)\).
  3. Estimate \(F^{-1}(\alpha | \boldsymbol\theta)\) using \(F^{-1}(\alpha | \widehat{\boldsymbol\theta})\).
  4. So, we have \[\widehat{\mathsf{VaR}}^{\mathsf{par}}(\alpha)=-S\times F^{-1}(\alpha | \widehat{\boldsymbol\theta}).\]

Parametric estimation of ES

  1. The approach is very similar to the nonparametric approach.
  2. The difference is that there is a general form of the ES and there are specific forms of the ES depending on the assumed distribution for returns.
  3. Note that \[\begin{eqnarray*}\mathsf{ES}(\alpha)&=&\mathbb{E}\left(\mathcal{L} | \mathcal{L} > \mathsf{VaR}(\alpha)\right)\\ &=&\mathbb{E}\left(-S\times R | -S\times R > -S\times F^{-1}(\alpha) \right) \\ &=& -S\times \mathbb{E}\left( R | R < F^{-1}(\alpha) \right)\end{eqnarray*}\]

Parametric estimation of ES

  1. As a result, we have \[\begin{eqnarray*}\mathsf{ES}(\alpha) &=& -S\times \frac{\displaystyle\int_{-\infty}^{F^{-1}(\alpha)} xf(x)\, dx}{\mathbb{P}\left(R<F^{-1}(\alpha)\right)} \\ &=& -\frac{S}{\alpha}\times \int_{-\infty}^{F^{-1}(\alpha)} xf(x)\, dx \end{eqnarray*}\]

Parametric estimation of ES

  1. In the parametric approach, the cdf \(F\) and the density \(f\) are all completely specified. Therefore, \[\begin{eqnarray*}\mathsf{ES}(\alpha) &=& -\frac{S}{\alpha}\times \int_{-\infty}^{F^{-1}(\alpha |\boldsymbol\theta)} xf(x |\boldsymbol\theta)\, dx \end{eqnarray*}\]

Parametric estimation of ES

  1. Plug-in estimates for unknown quantities obtained under the assumed model: \[\begin{eqnarray*}\widehat{\mathsf{ES}}^{\mathsf{par}}(\alpha) &=& -\frac{S}{\alpha}\times \int_{-\infty}^{F^{-1}(\alpha |\widehat{\boldsymbol\theta})} xf(x|\widehat{\boldsymbol\theta})\, dx \end{eqnarray*}\]

Parametric estimation of ES

  1. It may be possible to obtain a closed-form expression for the ES.

    • For the case of normally distributed returns \(N(\mu,\sigma^2)\): \[\mathsf{ES}^{\mathsf{norm}}(\alpha)= S\times \left\{-\mu+\sigma \left(\frac{\phi(\Phi^{-1}(\alpha))}{\alpha}\right)\right\}.\]
    • For the case of \(t_{\nu}\left(\mu,\lambda^2\right)\) distributed returns: \[\mathsf{ES}^{\mathsf{t}}(\alpha)= S\times \left\{-\mu+\lambda \left(\frac{f_{\nu}(F_{\nu}^{-1}(\alpha))}{\alpha}\left[\frac{\nu+\left(F_{\nu}^{-1}(\alpha)\right)^2}{\nu-1}\right]\right)\right\}.\]

Code in book versus code in slides

  1. The book has some extra lines of code which are unnecessary, e.g. lines 4, 5 in page 556.
  2. The book uses MASS::fitdistr() to fit parametric distributions.
  3. The slides streamline the code and you could streamline it further to remove the lines which display the results.
  4. The slides start from the raw data, include optimization of a log-likelihood, and show everything until the communication of the final results.

PSEi illustration with daily returns

  1. Suppose you hold a 20,000 peso position in a PSEi index fund (if it exists).
  2. Find a 1-day or 24-h \(\mathsf{VaR}(0.05)\).
  3. Find the expected shortfall based on the earlier VaR.
  4. Provide nonparametric and parametric estimates of these quantities.

PSEi illustration with daily returns

  1. Compute daily returns.
library(readxl)
PSEi <- read_excel("PSEi.xls", skip = 2)
PSEi_clean <- PSEi[which(!is.na(PSEi$Close)),]
dates <- as.Date(PSEi_clean$Date)
prices <- PSEi_clean$Close
library(quantmod)
ts <- xts(prices, dates)
ret.daily <- dailyReturn(ts, type="log")

PSEi illustration with daily returns

  1. Find the 0.05-quantile of the return distribution.
q <- quantile(ret.daily$daily.returns, 0.05)
q
         5% 
-0.02386479 
  1. Nonparametric estimate of the \(\mathsf{VaR}\)
VaR_np <- -20000*q
VaR_np
      5% 
477.2957 

So, VaR is about 477 pesos.

PSEi illustration with daily returns

  1. How many times do we see returns falling below the 0.05-quantile?
den <- sum(ret.daily$daily.returns < q)
den
[1] 229
  1. What is the sum of the returns for those times?
num <- sum(ret.daily$daily.returns * (ret.daily$daily.returns < q))
num
[1] -8.182677

PSEi illustration with daily returns

  1. Nonparametric estimate of the expected shortfall
ES_np <- -20000*num/den
ES_np
[1] 714.6443

So, the expected shortfall is 715 pesos.

PSEi illustration with daily returns

  1. We found in Chapter 5 that a \(t_{\nu}^{\mathsf{std}}(\mu,\sigma^2)\) is a parametric model which fits daily returns for the PSEi quite well.
library(fGarch)
loglik <- function(theta)
{
  -sum(dstd(ret.daily$daily.returns, mean = theta[1], sd = theta[2], nu = theta[3], log = TRUE))
}
start <- c(mean(ret.daily$daily.returns), sd(ret.daily$daily.returns), 4)
mle <- optim(start, loglik, hessian = TRUE)
mle$par
[1] 0.0001664988 0.0161166579 3.4635993397

PSEi illustration with daily returns

  1. Find the 0.05-quantile of the return distribution, assuming it is \(t_{\nu}^{\mathsf{std}}(\mu,\sigma^2)\).
library(fGarch)
q.para <- qstd(0.05, mean = mle$par[1], sd = mle$par[2], nu = mle$par[3])
q.para
[1] -0.02319996
  1. Parametric estimate of the \(\mathsf{VaR}\)
VaR_p <- -20000*q.para # typo in recording
VaR_p
[1] 463.9993

So, VaR is about 464 pesos.

PSEi illustration with daily returns

  1. Calculating the expected shortfall is more difficult.

    • Applying Equation (19.8) of the book requires going reparametrizing to the \(t_{\nu}(\mu, \lambda^2)\) distribution.
    • These two versions of a \(t\)-distribution are related by \[\sigma^2= \lambda^2 \frac{\nu}{\nu-2}.\]
sd.est.t <-  mle$par[2]*sqrt((mle$par[3]-2)/mle$par[3])
sd.est.t
[1] 0.01047665

PSEi illustration with daily returns

  1. Here are some intermediate quantities:
temp1 <- qt(0.05, df = mle$par[3])
temp2 <- dt(temp1, df =  mle$par[3]) 
c(temp1, temp2)
[1] -2.23033807  0.05092119
  1. Now, we can calculate the expected shortfall for the parametric case.
ES_p <- 20000*(-mle$par[1]+sd.est.t*temp2/0.05*(mle$par[3]+temp1^2)/(mle$par[3]-1))
ES_p
[1] 727.5577

So, the expected shortfall is 728 pesos.

Practice

  1. The code in the book uses a subset of the daily returns. Try using different subsets to see how sensitive your VaR is to the length of historical data you are using.

  2. R Lab Problem 1

    • Connection to ES calculations for the \(t\)-distribution
    • Connection to Equation (4.3) in Result 4.1
  3. R Lab Problem 2: Straightforward calculations

  4. Exercises 1 and 3a-3c