risk_measures {qrmtools} | R Documentation |
Computing risk measures.
## Value-at-risk VaR_np(x, level, names = FALSE, type = 1, ...) VaR_t(level, loc = 0, scale = 1, df = Inf) VaR_GPD(level, shape, scale) VaR_Par(level, shape, scale = 1) VaR_GPDtail(level, threshold, p.exceed, shape, scale) ## Expected shortfall ES_np(x, level, method = c(">", ">="), verbose = FALSE, ...) ES_t(level, loc = 0, scale = 1, df = Inf) ES_GPD(level, shape, scale) ES_Par(level, shape, scale = 1) ES_GPDtail(level, threshold, p.exceed, shape, scale) ## Multivariate geometric value-at-risk and expectiles gVaR(x, level, start = colMeans(x), method = if(length(level) == 1) "Brent" else "Nelder-Mead", ...) gEX(x, level, start = colMeans(x), method = if(length(level) == 1) "Brent" else "Nelder-Mead", ...)
x |
|
level |
|
names |
see |
type |
see |
loc |
location parameter mu. |
shape |
|
scale |
|
df |
degrees of freedom, a positive number; choose |
threshold |
threhold u (used to estimate the exceedance
probability based on the data |
p.exceed |
exceedance probability; typically |
start |
|
method |
|
verbose |
|
... |
The distribution function of the Pareto distribution is given by
F(x) = 1-(kappa/(kappa+x))^{theta}, x >= 0,
where theta > 0, kappa > 0.
VaR_np()
, ES_np()
estimate value-at-risk and expected
shortfall non-parametrically. For the latter, the mean over all losses
(strictly) beyond value-at-risk is computed. If method = ">="
,
there is always at least one such loss, whereas if method =
">"
, there might be no such loss, in which case NaN
is returned.
VaR_t()
, ES_t()
compute value-at-risk and expected
shortfall for the t (or normal) distribution.
VaR_GPD()
, ES_GPD()
compute value-at-risk and expected
shortfall for the generalized Pareto distribution (GPD).
VaR_Par()
, ES_Par()
compute value-at-risk and expected
shortfall for the Pareto distribution.
gVaR()
, gEX()
compute the multivariate geometric
value-at-risk and expectiles suggested by Chaudhuri (1996) and
Herrmann et al. (2018), respectively.
Marius Hofert
McNeil, A. J., Frey, R. and Embrechts, P. (2015). Quantitative Risk Management: Concepts, Techniques, Tools. Princeton University Press.
Chaudhuri, P. (1996). On a geometric notion of quantiles for multivariate data. Journal of the American Statistical Assosiation 91(434), 862–872.
Herrmann, K., Hofert, M. and Mailhot, M. (2018). Multivariate geometric expectiles. Scandinavian Actuarial Journal, 2018(7), 629–659.
### 1 Univariate measures ###################################################### ## Generate some losses and (non-parametrically) estimate VaR_alpha and ES_alpha set.seed(271) L <- rlnorm(1000, meanlog = -1, sdlog = 2) # L ~ LN(mu, sig^2) ## Note: - meanlog = mean(log(L)) = mu, sdlog = sd(log(L)) = sig ## - E(L) = exp(mu + (sig^2)/2), var(L) = (exp(sig^2)-1)*exp(2*mu + sig^2) ## To obtain a sample with E(L) = a and var(L) = b, use: ## mu = log(a)-log(1+b/a^2)/2 and sig = sqrt(log(1+b/a^2)) VaR_np(L, level = 0.99) ES_np(L, level = 0.99) ## 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, scale = V*sig, df = Inf) VaRt4 <- VaR_t(alpha, scale = V*sig*sqrt((nu-2)/nu), df = nu) ESnorm <- ES_t(alpha, scale = V*sig, df = Inf) ESt4 <- ES_t(alpha, scale = 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"))) ### 2 Multivariate measures #################################################### ## Setup library(copula) n <- 1e4 # MC sample size nu <- 3 # degrees of freedom th <- iTau(tCopula(df = nu), tau = 0.5) # correlation parameter cop <- tCopula(param = th, df = nu) # t copula set.seed(271) # for reproducibility U <- rCopula(n, cop = cop) # copula sample theta <- c(2.5, 4) # marginal Pareto parameters stopifnot(theta > 2) # need finite 2nd moments X <- sapply(1:2, function(j) qPar(U[,j], shape = theta[j])) # generate X N <- 17 # number of angles (rather small here because of run time) phi <- seq(0, 2*pi, length.out = N) # angles r <- 0.98 # radius alpha <- r * cbind(alpha1 = cos(phi), alpha2 = sin(phi)) # vector of confidence levels ## Compute geometric value-at-risk system.time(res <- gVaR(X, level = alpha)) gvar <- t(sapply(seq_len(nrow(alpha)), function(i) { x <- res[[i]] if(x[["convergence"]] != 0) # 0 = 'converged' warning("No convergence for alpha = (", alpha[i,1], ", ", alpha[i,2], ") (row ", i, ")") x[["par"]] })) # (N, 2)-matrix ## Compute geometric expectiles system.time(res <- gEX(X, level = alpha)) gex <- t(sapply(seq_len(nrow(alpha)), function(i) { x <- res[[i]] if(x[["convergence"]] != 0) # 0 = 'converged' warning("No convergence for alpha = (", alpha[i,1], ", ", alpha[i,2], ") (row ", i, ")") x[["par"]] })) # (N, 2)-matrix ## Plot geometric VaR and geometric expectiles plot(gvar, type = "b", xlab = "Component 1 of geometric VaRs and expectiles", ylab = "Component 2 of geometric VaRs and expectiles", main = "Multivariate geometric VaRs and expectiles") lines(gex, type = "b", col = "royalblue3") legend("bottomleft", lty = 1, bty = "n", col = c("black", "royalblue3"), legend = c("geom. VaR", "geom. expectile")) lab <- substitute("MC sample size n ="~n.*","~t[nu.]~"copula with Par("*th1* ") and Par("*th2*") margins", list(n. = n, nu. = nu, th1 = theta[1], th2 = theta[2])) mtext(lab, side = 4, line = 1, adj = 0)