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) # expectileWe 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 riskMany 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.VaR — Function
VaR(x̃, α)Compute the value at risk at risk level α for the random variable x̃.
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̃.
Conditional Value at Risk
RiskMeasures.CVaR — Function
CVaR(x̃, α)Compute the conditional value at risk at level α for the random variable x̃.
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
Entropic Value at Risk
RiskMeasures.EVaR — Function
EVaR(x̃, α; βmin = 1e-5, βmax = 100, reciprocal = false, check_inputs = true)Compute the EVaR risk measure of the random variable x̃ 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.
Entropic Risk Measure
RiskMeasures.ERM — Function
ERM(x̃, β; x̃min = -Inf, check_inputs = true)Compute the entropic risk measure of the random variable x̃ 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 x̃ 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
RiskMeasures.softmin — Function
softmin(x̃, β; x̃min = -Inf, check_inputs = true)Compute a weighted softmin function for random variable x̃ 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 x̃ is used instead.
The value β must be positive.
Expectile
RiskMeasures.expectile — Function
expectile(x̃, α)Compute the expectile risk measure of the random variable x̃ 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_-]\]
Essential Infimum
RiskMeasures.essinf — Function
essinf(x̃)Compute the essential infimum of the random variable x̃, which is the minimum value with positive probability.
Choquet Risk
RiskMeasures.choquet_risk — Function
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.
RiskMeasures.choquet_distortion_risk — Function
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.
RiskMeasures.cvar_capacity — Function
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).
RiskMeasures.cvar_distortion — Function
cvar_distortion(t, α)Distortion function equivalent to CVaR at level α: min(t / α, 1).
RiskMeasures.closure_c — Function
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.
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].
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.