[![CRANStatusBadge](https://www.r-pkg.org/badges/version/cvar)](https://cran.r-project.org/package=cvar)
[![CRAN RStudio mirror downloads](https://cranlogs.r-pkg.org/badges/cvar)](https://www.r-pkg.org/pkg/cvar)
[![CRAN RStudio mirror downloads](https://cranlogs.r-pkg.org/badges/grand-total/cvar?color=blue)](https://r-pkg.org/pkg/cvar)
[![R-CMD-check](https://github.com/GeoBosh/cvar/workflows/R-CMD-check/badge.svg)](https://github.com/GeoBosh/cvar/actions)
[![codecov](https://codecov.io/gh/GeoBosh/cvar/branch/master/graph/badge.svg?token=2SW9HKG71Y)](https://app.codecov.io/gh/GeoBosh/cvar)

 
## Overview

Compute expected shortfall (ES) and Value at Risk (VaR) from a
quantile function, distribution function, random number generator or
probability density function.  ES is also known as Conditional Value
at Risk (CVaR). Virtually any continuous distribution can be
specified.  The functions are vectorised over the arguments.
The computations are done directly from the definitions, see e.g. Acerbi
and Tasche (2002). Some support for GARCH models is provided, as well.


## Installing cvar

The [latest stable version](https://cran.r-project.org/package=cvar) is on CRAN. 

    install.packages("cvar")

The vignette
[Guide_cvar]( https://CRAN.R-project.org/package=cvar/vignettes/Guide_cvar.pdf) shipping
with the package gives illustrative examples (can also be opened from R with
`vignette("Guide_cvar", package = "cvar")`).

You can install the [development version](https://github.com/GeoBosh/cvar) of `cvar` from Github:

    library(devtools)
    install_github("GeoBosh/cvar")


## Overview

Package `cvar` is a small `R` package with, essentially two
functions &#x2014; `ES` for computing the expected shortfall
and `VaR` for Value at Risk.  The user specifies the
distribution by supplying one of the functions that define a
continuous distribution&#x2014;currently this can be a quantile
function (qf), cumulative distribution function (cdf) or
probability density function (pdf). Virtually any continuous
distribution can be specified.

The functions are vectorised over the parameters of the
distributions, making bulk computations more convenient, for
example for forecasting or model evaluation.

The name of this package, "cvar", comes from *Conditional Value at
Risk* (CVaR), which is an alternative term for expected shortfall.

We chose to use the standard names `ES` and `VaR`,
despite the possibility for name clashes with same named
functions in other packages, rather than invent possibly
difficult to remember alternatives. Just call the functions as
`cvar::ES` and `cvar::VaR` if necessary.

Locations-scale transformations can be specified separately
from the other distribution parameters. This is useful when
such parameters are not provided directly by the distribution
at hand. The use of these parameters often leads to more
efficient computations and better numerical accuracy even if
the distribution has its own parameters for this purpose. Some
of the examples for `VaR` and `ES` illustrate this
for the Gaussian distribution.

Since VaR is a quantile, functions computing it for a given
distribution are convenience functions. `VaR` exported by
`cvar` could be attractive in certain workflows because of
its vectorised distribution parameters, the location-scale
transformation and the possibility to compute it from cdf's
when quantile functions are not available.

