# ES: Compute expected shortfall (ES) of distributions In cvar: Compute Expected Shortfall and Value at Risk for Continuous Distributions

## Description

`ES` computes the expected shortfall for distributions specified by the arguments. `dist` is typically a function (or the name of one). What `dist` computes is determined by `dist.type`, whose default setting is `"qf"` (the quantile function). Other possible settings of `dist.type` include `"cdf"` and `"pdf"`. Additional arguments for `dist` can be given with the `"..."` arguments.

Except for the exceptions discussed below, a function computing VaR for the specified distribution is constructed and the expected shortfall is computed by numerically integrating it. The numerical integration can be fine-tuned with argument `control`, which should be a named list, see `integrate` for the available options.

If `dist.type` is `"pdf"`, VaR is not computed, Instead, the partial expectation of the lower tail is computed by numerical integration of ```x * pdf(x)```. Currently the quantile function is required anyway, via argument `qf`, to compute the upper limit of the integral. So, this case is mainly for testing and comparison purposes.

A bunch of expected shortfalls is computed if argument `x` or any of the arguments in `"..."` are of length greater than one. They are recycled to equal length, if necessary, using the normal R recycling rules.

`intercept` and `slope` can be used to compute the expected shortfall for the location-scale transformation `Y = intercept + slope * X`, where the distribution of `X` is as specified by the other parameters and `Y` is the variable of interest. The expected shortfall of `X` is calculated and then transformed to that of `Y`. Note that the distribution of `X` doesn't need to be standardised, although it typically will.

The `intercept` and the `slope` can be vectors. Using them may be particularly useful for cheap calculations in, for example, forecasting, where the predictive distributions are often from the same family, but with different location and scale parameters. Conceptually, the described treatment of `intercept` and `slope` is equivalent to recycling them along with the other arguments, but more efficiently.

The names, `intercept` and `slope`, for the location and scale parameters were chosen for their expressiveness and to minimise the possibility for a clash with parameters of `dist` (e.g., the Gamma distribution has parameter `scale`).

## Usage

 ```1 2``` ```ES(dist, x = 0.05, dist.type = "qf", qf, ..., intercept = 0, slope = 1, control = list()) ```

## Arguments

 `dist` specifies the distribution whose ES is computed, usually a function or a name of a function computing quantiles, cdf, pdf, or a random number generator, see Details. `x` level, default is 0.05 `dist.type` a character string specifying what is computed by `dist`, such as "qf" or "cdf". `qf` quantile function, only used if `dist.type = "pdf"`. `...` passed on to `dist`. `intercept, slope` requests the ES for the linear transformation ```intercept + slope*X```, where `X` has distribution specified by `dist`, see Details. `control` additional control parameters for the numerical integration routine.

a numeric vector

## Examples

 ``` 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37``` ```ES(qnorm) ## Gaussian ES(qnorm, dist.type = "qf") ES(pnorm, dist.type = "cdf") ## t-dist ES(qt, dist.type = "qf", df = 4) ES(pt, dist.type = "cdf", df = 4) ES(pnorm, x= 0.95, dist.type = "cdf") ES(qnorm, x= 0.95, dist.type = "qf") ## - VaRES::esnormal(0.95, 0, 1) ## - PerformanceAnalytics::ETL(p=0.05, method = "gaussian", mu = 0, ## sigma = 1, weights = 1) # same cvar::ES(pnorm, dist.type = "cdf") cvar::ES(qnorm, dist.type = "qf") cvar::ES(pnorm, x= 0.05, dist.type = "cdf") cvar::ES(qnorm, x= 0.05, dist.type = "qf") ## this uses "pdf" cvar::ES(dnorm, x = 0.05, dist.type = "pdf", qf = qnorm) ## this gives warning (it does more than simply computing ES): ## PerformanceAnalytics::ETL(p=0.95, method = "gaussian", mu = 0, sigma = 1, weights = 1) ## run this if VaRRES is present ## Not run: x <- seq(0.01, 0.99, length = 100) y <- sapply(x, function(p) cvar::ES(qnorm, x = p, dist.type = "qf")) yS <- sapply(x, function(p) - VaRES::esnormal(p)) plot(x, y) lines(x, yS, col = "blue") ## End(Not run) ```

cvar documentation built on May 2, 2019, 2:09 p.m.