# NOT RUN {
## Example for inverse-gamma mixture (resulting in a t distribution) for
## which the expected shortfall admits a closed formula
set.seed(42) # reproducibility
level <- seq(from = 0.9, to = 0.95, by = 0.01)
df <- 4
## If 'qmix' is provided as string, ESnvmix() uses the closed formula
ES1 <- ESnvmix(level, qmix = "inverse.gamma", df = df)
## If 'qmix' is provided as function, the expected shortfall is estimated
ES2 <- ESnvmix(level, qmix = function(u, df) 1/qgamma(1-u, shape = df/2, rate = df/2),
df = df)
stopifnot(all.equal(ES1, ES2, tol = 1e-2, check.attributes = FALSE))
# }
Run the code above in your browser using DataLab