27  Value at Risk test

Setup
library(dplyr)
library(latex2exp)
library(backports)
library(ggplot2)
library(knitr)

Let’s consider a ARMA(2,2)-GARCH(1,1) model defined as: xt=μ+ϕ1xt1+ϕ2xt2+θ1et1+θ2et2+etet=σtutσt2=ω+α1et12+β1σt12 The Value at Risk (VaR) with confidence level α depends on the distribution of xt that is implicitly defined from the distribution of ut. Therefore, the VaR at time t, conditional to the information up to time t1, is implicitly defined as: P(XtVaRtt1α)=α.

27.1 Normal distribution

Let’s consider independent and normally distributed residuals ut. Then, also the conditional distribution of xt given the information up to time t1 will be normal with conditional mean and variance given by: {E{XtIt1}=μ+ϕ1xt1+ϕ2xt2+θ1et1+θ2et2V{XtIt1}=ω+α1et12+β1σt12=σt2 Hence, given the quantile qα of a standard normal with level α, the VaR is computed as: VaRtt1α=E{XtIt1}+qαV{XtIt1}.

27.2 Gaussian Mixture distribution

Let’s consider independent and Gaussian mixture distributed residuals ut with 2 components. Then, also the conditional distribution of xt given the information up to time t1 will be a Gaussian mixture with conditional mean and variance given by: {E{XtIt1,B=1}=μ+ϕ1xt1+ϕ2xt2+θ1et1+θ2et2+μ1σtE{XtIt1,B=0}=μ+ϕ1xt1+ϕ2xt2+θ1et1+θ2et2+μ0σtV{XtIt1,B=1}=(σtσ1)2V{XtIt1,B=0}=(σtσ0)2 Hence, given the quantile qα of a Gaussian mixture with 2 components with level α, that in general needs to be computed numerically, the VaR is defined as: VaRtt1α=qα.

27.3 Test on the number of violations

Let’s define a violation of the VaRt|t1α as vt=1[xtVaRtt1α]Bernoulli(α),

and let’s define the number of violations of the conditional VaR as follows, i.e. Nt=i=1tvi.

27.3.1 Asymptotic variance

Applying the central limit theorem (CLT) it is possible to prove that the statistic test converges in distribution to a standard normal, i.e. T1α=1ti=1t(viαα(1α))dnN(0,1). Hence, given the null hypothesis H0:P{XtVaRt|t1α|It1)=α, that is equivalent to E{et}=α we define the critical values at a confidence level α as α=P{|T1α|>tα/2}tα/2=P1{P{|T1α|>tα/2}}

where P and P1 are respectively the distribution and the quantile of a standard normal. Therefore, the null hypothesis is rejected at a confidence level α if: {[T1α<tα/2][T1α>tα/2]H0 rejected[tα/2<T1α<tα/2]H0 not rejected

27.3.2 Empirical variance

Instead of using the theoretical variance of et, namely α(1α), let’s substitute it with the empirical one, i.e. α(1α)Ntt(1Ntt). Hence, the new statistic test NV2 converges to NV1 in probability, therefore also in distribution, i.e.  T2α=1ti=1t(viαNtt(1Ntt))pnT1αdnN(0,1).

For small samples, the following relation between the two statistics should be used: T2α=α(1α)Ntt(1Ntt)T1α.

27.4 Example: H0 is not rejected

Instead of simulating exactly utN(0,1), let’s simulate residuals that are close to the normal distribution, i.e. utt(25).

AR(2)-GARCH(1,2) simulation and VaR
# ===================== Setups ======================
set.seed(1)   # random seed 
ci <- 0.05    # confidence level 
t_bar <- 5000 # number of simulations 
# parameters
parAR <- c(mu=0.5, phi1 = 0.34, phi1 = 0.14)
parGARCH <- c(omega=0.4, alpha1=0.25, 
              beta1=0.25, beta2=0.15) 
# long-term std deviation of residuals 
sigma_eps <- sqrt(parGARCH[1]/(1-sum(parGARCH[-1])))
# ================== Simulation =====================
# Initial points
Xt <- rep(parAR[1]/(1-sum(parAR[-1])), 3)
sigma <- rep(sigma_eps, 3)
# Simulated residuals 
eps <- rt(t_bar, 25)
eps[1:3] = eps[1:3]*sigma_eps
# Value at Risk
q_alpha = qnorm(ci)
VaR = c(0)
for(t in 3:t_bar){
  # AR component 
  Xt[t] <- parAR[1] + parAR[2]*Xt[t-1] + parAR[3]*Xt[t-2]
  # ARCH component 
  sigma[t] <- parGARCH[1] + parGARCH[2]*eps[t-1]^2 
  # GARCH component 
  sigma[t] <- sigma[t] + parGARCH[3]*sigma[t-1]^2 + parGARCH[4]*sigma[t-2]^2
  sigma[t] <- sqrt(sigma[t])
  # Simulated residuals 
  eps[t] <- sigma[t]*eps[t]
  # Simulated value at risk
  VaR[t] <- Xt[t] + sigma[t]*q_alpha
  # Simulated time series 
  Xt[t] <- Xt[t] + eps[t]
}
# ===================== Plot ======================
# GARCH(1,1) simulation
ggplot()+
  geom_line(aes(1:t_bar, Xt), size = 0.2)+
  geom_line(aes(1:t_bar, VaR), size = 0.2, color = "red")+
  theme_bw()+
  labs(x = NULL, y = TeX("$X_t$"),
       subtitle = TeX(paste0("$\\mu:\\;", parAR[1], 
                             "\\;\\; \\phi_{1}:\\;", parAR[2],
                             "\\;\\; \\phi_{2}:\\;", parAR[3],
                             "\\;\\; \\omega:\\;", parGARCH[1], 
                             "\\;\\; \\alpha_{1}:\\;", parGARCH[2],
                             "\\;\\; \\beta_{1}:\\;", parGARCH[3],
                             "\\;\\; \\beta_{2}:\\;", parGARCH[4],
                             "$")))
Figure 27.1: AR(2)-GARCH(1,2) simulation with theoric (red) VaR at α=0.05.
VaR test Student-t25
# ======================================
# Violation of the VaR
vt <- ifelse(Xt < VaR, 1, 0)
vt[1:3] <- 0
# Theoric variance
v_theoric <- ci*(1-ci)
# Empiric variance
v_empiric <- (sum(vt)/t_bar)*(1 - sum(vt)/t_bar)
# Standardized number of violations
Nt <- sum((vt - ci)/sqrt(v_theoric))
# Statistic test (NV_1)
T1 <- (1/sqrt(t_bar))*Nt
# Statistic test (NV_2)
T2 <- (sqrt(v_theoric)/sqrt(v_empiric))*T1
# Rejection level 
t_alpha <- qnorm(ci/2)
# =============== Kable =============== 
kab <- dplyr::tibble(
  n = t_bar,
  alpha = paste0(format(ci*100, digits = 3), "%"),
  alpha_hat = paste0(format(sum(vt)/t_bar*100, digits = 3), "%"),
  t_alpha_dw = t_alpha,
  T1 = T1,
  T2 = T2,
  t_alpha_up = -t_alpha,
  H01 = ifelse(T1 > t_alpha_up | T1 < t_alpha_dw, "Rejected", "Non-Rejected"),
  H02 = ifelse(T2 > t_alpha_up | T2 < t_alpha_dw, "Rejected", "Non-Rejected")
)  %>%
  dplyr::mutate_if(is.numeric, format, digits = 4, scientific = FALSE)
colnames(kab) <- c("$$n$$", "$$\\alpha$$", "$$\\frac{N_n}{n}$$", "$$t_{\\alpha/2}$$", 
                   "$$\\text{T}_1^{\\alpha}$$", "$$\\text{T}_2^{\\alpha}$$", "$$t_{\\alpha/2}$$", "$$H_0(\\text{T}_1)$$", "$$H_0(\\text{T}_2)$$")

knitr::kable(kab)
Table 27.1: Test for a Student-t with 25 degrees of freedom at α=0.05 on the number of violations of the theoric VaR at α=0.05.
n α Nnn tα/2 T1α T2α tα/2 H0(T1) H0(T2)
5000 5% 5.6% -1.96 1.947 1.845 1.96 Non-Rejected Non-Rejected

27.5 Example: H0 is rejected

Instead of simulating exactly utN(0,1), let’s simulate residuals that are not close to the normal distribution, i.e. utt(5).

AR(2)-GARCH(1,2) simulation and VaR
# ==================== Setups =====================
set.seed(1)   # random seed 
ci <- 0.05    # confidence level 
t_bar <- 1000 # number of simulations 
# parameters
parAR <- c(mu=0.5, phi1 = 0.34, phi1 = 0.14)
parGARCH <- c(omega=0.4, alpha1=0.25,
              beta1=0.25, beta2=0.15) 
# quasi long-term std deviation of residuals 
sigma_eps <- sqrt(parGARCH[1]/(1-sum(parGARCH[-1])))
# ================== Simulation ===================
set.seed(1)
# Initial points
Xt <- rep(parAR[1]/(1-sum(parAR[-1])), 3)
mu <- rep(parAR[1]/(1-sum(parAR[-1])), 3)
sigma <- rep(sigma_eps, 3)
# Simulated residuals 
eps <- rt(t_bar, 5) 
eps[1:3] <- eps[1:3]*sigma_eps
# Value at Risk
q_alpha = qnorm(ci)
VaR = c(0)
for(t in 3:t_bar){
  # AR component 
  mu[t] <- parAR[1] + parAR[2]*Xt[t-1] + parAR[3]*Xt[t-2]
  # ARCH component 
  sigma[t] <- parGARCH[1] + parGARCH[2]*eps[t-1]^2 
  # GARCH component 
  sigma[t] <- sigma[t] + parGARCH[3]*sigma[t-1]^2 + parGARCH[4]*sigma[t-2]^2
  sigma[t] <- sqrt(sigma[t])
  # Simulated residuals 
  eps[t] <- sigma[t]*eps[t]
  # Simulated value at risk
  VaR[t] <- mu[t] + sigma[t]*q_alpha
  # Simulated time series 
  Xt[t] <- mu[t] + eps[t]
}
# Empirical quantile 
q_alpha_emp <- quantile(eps/sigma, probs = ci)
VaR_emp <- mu + sigma*q_alpha_emp

# ===================== Plot ======================
# GARCH(1,1) simulation
ggplot()+
  geom_line(aes(1:t_bar, Xt), size = 0.2)+
  geom_line(aes(1:t_bar, VaR), size = 0.2, color = "red")+
  geom_line(aes(1:t_bar, VaR_emp), size = 0.2, color = "blue")+
  theme_bw()+
  labs(x = NULL, y = TeX("$X_t$"),
       subtitle = TeX(paste0("$\\mu:\\;", parAR[1], 
                             "\\;\\; \\phi_{1}:\\;", parAR[2],
                             "\\;\\; \\phi_{2}:\\;", parAR[3],
                             "\\;\\; \\omega:\\;", parGARCH[1], 
                             "\\;\\; \\alpha_{1}:\\;", parGARCH[2],
                             "\\;\\; \\beta_{1}:\\;", parGARCH[3],
                             "\\;\\; \\beta_{2}:\\;", parGARCH[4],
                             "$")))
Figure 27.2: AR(2)-GARCH(1,2) simulation with theoric (red) and empirical (blue) VaR at α=0.05.

Computing the test on the normal quantile gives a rejection of the null hypothesis H0, i.e. the deviation from the VaR is not stochastic and it is not an adequate measure of risk.

VaR test Student-t5
# ======================================
# Violation of the VaR
vt <- ifelse(Xt < VaR, 1, 0)
vt[1:3] <- 0
# Theoric variance
v_theoric <- ci*(1-ci)
# Empiric variance
v_empiric <- (sum(vt)/t_bar)*(1 - sum(vt)/t_bar)
# Standardized number of violations
Nt <- sum((vt - ci)/sqrt(v_theoric))
# Statistic test (NV_1)
T1 <- (1/sqrt(t_bar))*Nt
# Statistic test (NV_2)
T2 <- (sqrt(v_theoric)/sqrt(v_empiric))*T1
# Rejection level 
t_alpha <- qnorm(ci/2)
# =============== Kable =============== 
kab <- dplyr::tibble(
  n = t_bar,
  alpha = paste0(format(ci*100, digits = 3), "%"),
  alpha_hat = paste0(format(sum(vt)/t_bar*100, digits = 3), "%"),
  t_alpha_dw = t_alpha,
  T1 = T1,
  T2 = T2,
  t_alpha_up = -t_alpha,
  H01 = ifelse(T1 > t_alpha_up | T1 < t_alpha_dw, "Rejected", "Non-Rejected"),
  H02 = ifelse(T2 > t_alpha_up | T2 < t_alpha_dw, "Rejected", "Non-Rejected")
)  %>%
  dplyr::mutate_if(is.numeric, format, digits = 4, scientific = FALSE)
colnames(kab) <- c("$$n$$", "$$\\alpha$$", "$$\\frac{N_n}{n}$$", "$$-t_{\\alpha/2}$$", 
                   "$$\\text{T}_1^{\\alpha}$$", "$$\\text{T}_2^{\\alpha}$$", "$$t_{\\alpha/2}$$", 
                   "$$H_0(\\text{T}_1)$$", "$$H_0(\\text{T}_2)$$")
knitr::kable(kab)
Table 27.2: Test for a Student-t with 5 degrees of freedom at α=0.05 on the number of violations of the theoric VaR at α=0.05.
n α Nnn tα/2 T1α T2α tα/2 H0(T1) H0(T2)
1000 5% 8.5% -1.96 5.078 3.969 1.96 Rejected Rejected

Setting α=0.05 we obtain an empiric q^α equal to -2.07 different from the theoric one of -1.6449.