Learn R Programming

fEGarch (version 1.0.1)

VaR_calc: VaR and ES Computation for Standardized Distributions

Description

Compute the value at risk (VaR) and the expected shortfall (ES) numerically for the standardized distributions available in this package. These quantiles can then be used to obtain the conditional VaR and ES following GARCH-type models.

Usage

VaR_calc(
  level = 0.99,
  dist = c("norm", "std", "ged", "ald", "snorm", "sstd", "sged", "sald"),
  ...
)

ES_calc( level = 0.975, dist = c("norm", "std", "ged", "ald", "snorm", "sstd", "sged", "sald"), ... )

Value

Returns a numeric vector of the same length as the input argument level.

Arguments

level

a numeric vector with the confidence level(s) to calculate the VaR or ES for; the quantiles are the VaR or ES computed at one minus the input level; the result is thus with negative sign for common level input such as 0.975 or 0.99.

dist

a single character value (or the default vector) that specifies the distribution to consider (all distributions are considered to be standardized with mean zero and variance one).

...

further arguments to consider for the distributions; for "std" or "sstd", specify the degrees of freedom df, for "ged" or "sged", give the shape parameter shape, and for "ald" or "sald", use the additional argument P; moreover, for the skewed distributions "snorm", "sstd", "sged" and "sald", the skewness parameter skew must be provided as well.

Details

The VaR is found numerically using numerical root finding via uniroot (of the stats package), whereas the ES is obtained through numerical integration, where firstly the VaR at the corresponding confidence level is computed using VaR_calc, and where subsequently integrate (of the stats package) is used at the tail of the distribution.

In detail, let \(f(x)\) be the probability density function (pdf) of a standardized random variable with mean zero and variance one. Without the need to state a cumulative distribution function (cdf) mathematically, we can define it in R numerically by integrating over \(f\) from -Inf to some quantile x using integrate. To then find a quantile for a given cumulative probability, we can use uniroot to find the quantile, where the numerical cdf function minus the set cumulative probability equals zero. This way, a numerical VaR can be found.

On the other hand, a numerical ES for a (continuous) random variable with mean zero and variance one follows the alternative definition of the ES $$\text{ES}_{\alpha}=(1-\alpha)^{-1}\int_{-\infty}^{\text{VaR}_{\alpha}}x f(x) dx,$$ where \(\alpha\), usually 0.99 or 0.975, is the confidence level, \(\text{VaR}_{\alpha}\) is the VaR at the same \(\alpha\). Using the previous approach, \(\text{VaR}_{\alpha}\) can be easily identified. Then, in R, a function \(g(x)=x f(x)\) can also be defined easily. Ultimately, only integrate needs to be applied from -Inf to the corresponding VaR as the upper bound to the function \(g\). The resulting numerical integral is then divided by \((1-\alpha)\).

Examples

Run this code

# 99-percent VaR, normal distribution
VaR_calc(level = 0.99, dist = "norm")

# 99-percent VaR, t-distribution with df = 10
VaR_calc(level = 0.99, dist = "std", df = 10)

# 97.5-percent ES, normal distribution
ES_calc(level = 0.975, dist = "norm")

# 97.5-percent ES, t-distribution with df = 10
ES_calc(level = 0.975, dist = "std", df = 10)


Run the code above in your browser using DataLab