##' @title Bootstrap the nonparametric VaR or ES estimator for all alpha
##'
##' @param x vector of losses
##' @param B number of bootstrap replications
##' @param level confidence level
##' @param method risk measure used
##'
##' @return (length(alpha), B)-matrix where the bth column contains the estimated
##' risk measure at each alpha based on the bth bootstrap sample of the
##' losses
##' @author Marius Hofert
##' @note vectorized in x and level
##' @export
bootstrap_VaR_ES <- function(x, B, level, method = c("VaR", "ES"))
{
stopifnot(is.vector(x), (n <- length(x)) >= 1, B >= 1)
method <- match.arg(method)
rm <- if(method == "VaR") {
qrmtools::VaR_np
} else {
function(x, level) qrmtools::ES_np(x, level = level, verbose = TRUE)
}
## Construct the bootstrap samples (by drawing with replacement)
## from the underlying empirical distribution function
x.boot <- matrix(sample(x, size = n * B, replace = TRUE), ncol = B) # (n, B)-matrix
## For each bootstrap sample, estimate the risk measure
apply(x.boot, 2, rm, level = level) # (length(level), B)-matrix
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.