## Example 2.16 in McNeil, Frey, Embrechts (2015)
V <- 10000 # value of the portfolio today
sig <- 0.2/sqrt(250) # daily volatility (annualized volatility of 20%)
nu <- 4 # degrees of freedom for the t distribution
alpha <- seq(0.001, 0.999, length.out=256) # confidence levels
VaRnorm <- VaR_t(alpha, sigma=V*sig, df=Inf)
VaRt4 <- VaR_t(alpha, sigma=V*sig*sqrt((nu-2)/nu), df=nu)
ESnorm <- ES_t(alpha, sigma=V*sig, df=Inf)
ESt4 <- ES_t(alpha, sigma=V*sig*sqrt((nu-2)/nu), df=nu)
ran <- range(VaRnorm, VaRt4, ESnorm, ESt4)
plot(alpha, VaRnorm, type="l", ylim=ran, xlab=expression(alpha), ylab="")
lines(alpha, VaRt4, col="royalblue3")
lines(alpha, ESnorm, col="darkorange2")
lines(alpha, ESt4, col="maroon3")
legend("bottomright", bty="n", lty=rep(1,4), col=c("black",
"royalblue3", "darkorange3", "maroon3"),
legend=c(expression(VaR[alpha]~~"for normal model"),
expression(VaR[alpha]~~"for "*t[4]*" model"),
expression(ES[alpha]~~"for normal model"),
expression(ES[alpha]~~"for "*t[4]*" model")))
Run the code above in your browser using DataLab