RiskMeasures

Julia library for computing risk measures for random variables. The random variable represents profits or rewards that are to be maximized. The computed risk value is also better when greater.

The following risk measures are currently supported

  • VaR: Value at risk
  • CVaR: Conditional value at risk
  • ERM: Entropic risk measure
  • EVaR: Entropic value at risk

When supported, the risk measure returns also the optimal distribution

General assumptions

  • Random variables represent rewards (greater value is preferred)
  • Risk measures become less risk-averse with the increasing value of the risk parameter α or β

Supported distributions

  • General discrete distributions (DiscreteNonParametric)

Warning: This is package is in development and the computed values should be treated with caution.

Examples

using RiskMeasures
using Distributions

x̃ = DiscreteNonParametric([1, 5, 6, 7, 20], [0.1, 0.1, 0.2, 0.5, 0.1])
 
VaR(x̃, 0.1)   # value at risk
CVaR(x̃, 0.1)  # conditional value at risk
EVaR(x̃, 0.1)  # entropic value at risk
ERM(x̃, 0.1)   # entropic risk measure
expectile(x̃, 0.1)  # expectile

We can also compute risk measures of transformed random variables

VaR(5*x̃ + 10, 0.1)   # value at risk
CVaR(x̃ - 10, 0.1)  # conditional value at risk

Many methods methods VaR, CVaR, and EVaR also return additional statistics and values, such as the distribution that attains the risk value and the optimal β in EVaR. These are returned as named tuples.

See Also

Functions

Value at Risk

RiskMeasures.VaRFunction
VaR(x̃, α)

Compute the value at risk at risk level α for the random variable .

Risk must satisfy $α ∈ [0,1]$ and α=0.5 computes the median and α=0 computes the essential infimum (smallest value with positive probability) and α=1 returns infinity.

Solves for $\max \{t ∈ \mathbb{R} : \mathbb{P}[x̃ < t] \le α \}$

In general, this function is neither convex nor concave in the random variable x̃.

source

Conditional Value at Risk

RiskMeasures.CVaRFunction
CVaR(x̃, α)

Compute the conditional value at risk at level α for the random variable .

CVaR(values, pmf, α; ...)

Compute CVaR for a discrete random variable with values and the probability mass function pmf.

The risk level α must satisfy $α ∈ [0,1]$. Risk aversion decreases with an increasing α and α = 1 represents the expectation, α = 0 computes the essential infimum (smallest value with positive probability).

Assumes a reward maximization setting and solves the dual form

\[\min_{q ∈ \mathcal{Q}} q^T x̃\]

where

\[\mathcal{Q} = \left\{q ∈ Δ^n : q_i ≤ \frac{p_i}{α}\right\}\]

and $Δ^n$ is the probability simplex, and $p$ is the distribution of $x̃$.

Returns

A named tuple with CVaR value and the pmf that achieves it.

Keyword Arguments:

  • check_inputs=true: check that the inputs are valid.
  • fast=false: use linear-time experimental implementation

More details: https://en.wikipedia.org/wiki/Expected_shortfall

source

Entropic Value at Risk

RiskMeasures.EVaRFunction
EVaR(x̃, α; βmin = 1e-5, βmax = 100, reciprocal = false, check_inputs = true)

Compute the EVaR risk measure of the random variable with risk level α in [0,1].

EVaR(values, pmf, α; ...)

Compute EVaR for a discrete random variable with values and the probability mass function pmf.

When α = 1, the function computes the expected value, and when α = 0, then the function computes the essential infimum (the minimum value with positive probability).

The function solves

\[\max_{β ∈ [βmin, βmax]} \operatorname{ERM}_β (x̃) - β^{-1} \log (1/(α)).\]

Large values of βmax may cause the computation to overflow.

If reciprocal = false, then the quasi-concave problem above is solved directly. If reciprocal = true, then the optimization is reformulated in terms of λ = 1/β to get a concave function that can be solved (probably) more efficiently

The function implicitly assumes that all elements of the probability space have non-zero probability.

Returns

A named tuple with the EVaR value, the optimal β that attains the maximum, and the worst-case pmf. Note that β is numerically unstable when EVaR equals the essential infimum, because the supremum is attained in the limit as β → ∞.

See: Ahmadi-Javid, A. “Entropic Value-at-Risk: A New Coherent Risk Measure.” Journal of Optimization Theory and Applications 155(3), 2012.

source

Entropic Risk Measure

RiskMeasures.ERMFunction
ERM(x̃, β; x̃min = -Inf, check_inputs = true)

Compute the entropic risk measure of the random variable with risk level β.

The optional x̃min parameter is used as an offset in order to avoid overflows when computing the exponential function. If not provided, the minimum value of is used instead.

Assumes a maximization problem. Using β = 0 computes the expectation and β = Inf computes the essential infimum (smallest value with positive probability).

More details: https://en.wikipedia.org/wiki/Entropic_risk_measure

source
RiskMeasures.softminFunction
softmin(x̃, β; x̃min = -Inf, check_inputs = true)

Compute a weighted softmin function for random variable with risk level β. This can be seen as an approximation of the arg min function and not the min function.

The operator computes a distribution p such that

\[p_i = \frac{e^{-β x_i}}{\mathbb{E}[e^{-β x̃}]}\]

The optional x̃min parameter is used as an offset in order to avoid overflows when computing the exponential function. If not provided, the minimum value of is used instead.

The value β must be positive.

source

Expectile

RiskMeasures.expectileFunction
expectile(x̃, α)

Compute the expectile risk measure of the random variable with risk level α ∈ (0,1). When α = 1/2, the function computes the expected value.

expectile(values, pmf, α; ...)

Compute expectile for a discrete random variable with values and the probability mass function pmf.

Expectile is only coherent when α ∈ (0,1/2].

Note that the range for α does not include 0 or 1.

The function solves

\[\argmin_{x \in \mathbb{R}} α \mathbb{E}[(\tilde{x} - x)^2_+] + (1-α) \mathbb{E}[( ilde{x} - x)^2_-]\]

source

Essential Infimum

RiskMeasures.essinfFunction
essinf(x̃)

Compute the essential infimum of the random variable , which is the minimum value with positive probability.

source

Choquet Risk

RiskMeasures.choquet_riskFunction
choquet_risk(x, pmf, c, α)

Compute the risk measure for a given choquet capacity function c and random variable x with probabilities pmf.

The choquet capacity function c that returns a non-negative value and is parametrized by a level α ∈ [0,1].

The runtime of this function can be quadratic depending on the evaluation of the capacity function.

source
RiskMeasures.choquet_distortion_riskFunction
choquet_distortion_risk(x, pmf, g, α)

Compute the choquet risk measure for a law-invariant capacity c(A) = g(P[A]), where g : [0,1] → [0,1] is a distortion function with g(0) = 0 and g(1) = 1.

More efficient than choquet_risk for law-invariant measures: g is evaluated on scalars rather than index sets, and cumulative probabilities are computed once.

source
RiskMeasures.cvar_capacityFunction
cvar_capacity(S, pmf, α)

choquet capacity function equivalent to CVaR at level α. Returns min(sum(pmf[S]) / α, 1), which is the distorted probability g(P(S)) with distortion g(t) = min(t/α, 1).

source
RiskMeasures.closure_cFunction
closure_c(ρ)

Given a risk measure function ρ, return a closure that computes the submodular function c(S) = -ρ(-1_S) where 1_S is the indicator vector of an index set S.

source

Notable Internal Functions

RiskMeasures.partition!Function
partition!(vals::AbstractVector{<:Real}, p::AbstractVector{<:Real}, pivot_ind::Int, f::Int, b::Int)

Partition the values in vals and p between f and b (inclusive) using the Dutch Flag algorithm into less than pivot, equal to pivot, and greater than pivot.

Returns

A tuple (lt, gt) where i < lt => x[i] < pivot_val and i > gt => x[i] > pivot_val and lt ≤ i ≤ gt => x[i] = pivot_val, where pivot_val = vals[pivot_ind].

source
RiskMeasures.qql!Function
qql!(vals, p, α)

Compute VaR in expected linear time without performing correctness checks. The runtime of the algorithm is randomized but the output value is deterministic.

The input must satisfy 0 < α < 1 and p and vals must have the same length.

Returns

A named tuple with VaR value as a float and the index that achieves it.

source