Entropic X at Risk: private API
PortfolioOptimisers.ERM — Function
ERM(x::VecNum, slv::Option{<:Slv_VecSlv}, alpha::Number = 0.05,
w::Option{<:ObsWeights} = nothing) -> NumberCompute the Entropic Value-at-Risk of the returns x with an exponential cone programme.
EntropicValueatRisk states the measure, its Kullback-Leibler ball and its programme. Every call builds a new JuMP model. The model holds the cone rows of the observations of positive weight only. An observation of weight zero does not change the optimum, but the cone row of a large loss can stop the solver far from the optimum.
Algorithm
- Check
wagainstxwithchecked_observation_weights. - Check that
slvis a solver, and not empty when it is a vector, withchecked_kernel_solver. - When
alphais zero, return the largest loss among the observations of positive weight, withworst_positive_weight_loss. This step builds no model. - Build and solve the exponential cone programme that
ERM_modelstates. - When a solver solves the model, return its objective value. Otherwise, return
NaN.
Arguments
x: Vector of portfolio returns.slv: Solver or vector of solvers.alpha: Significance level, $\alpha \in [0, 1)$.w: Observation weights, ornothingfor equal weights.
Validation
wpasseschecked_observation_weightsagainstx. Otherwise that function raises its error.slvis notnothing, elseIsNothingError, and ifslvis aVecSlv:!isempty(slv), elseIsEmptyError. Seechecked_kernel_solver.
The function does not check alpha. The constructors of the measures check it.
Returns
- The Entropic Value-at-Risk of
x, orNaNwhen no solver ofslvsolves the programme.
Related
PortfolioOptimisers.ERM_worst_case — Function
ERM_worst_case(x::VecNum, slv::Option{<:Slv_VecSlv}, alpha::Number = 0.05,
w::Option{<:ObsWeights} = nothing) -> Option{<:VecNum}Compute the Worst-Case Distribution of the Entropic Value-at-Risk of the returns x, from the dual of the programme of ERM_model.
The Entropic Value-at-Risk is the largest expected loss over a Kullback-Leibler ball, and the Worst-Case Distribution $\boldsymbol{q}$ is the distribution in the ball that reaches it. So the expected loss under $\boldsymbol{q}$ equals the value of ERM, to the tolerance of the solver, and $-\boldsymbol{q}$ is the gradient of that value with respect to x. risk_contribution and risk_gradient read it through worst_case_distribution, so that their finite difference does not difference two solves. ERM does not compute it, so a call of expected_risk does not pay for it.
Algorithm
- Check
wagainstxwithchecked_observation_weights. - Check that
slvis a solver, and not empty when it is a vector, withchecked_kernel_solver. - When
alphais zero, return the distribution of the largest loss, withworst_loss_distribution. This step builds no model. - Build and solve the programme with
ERM_model. - When no solver solves the model, or the solver gives no dual, return
nothing. - Otherwise, negate the first entry of the dual of each row of
erm_cone, and expand it toTentries withexpand_positive_weight_rows.
Arguments
x: Vector of portfolio returns.slv: Solver or vector of solvers.alpha: Significance level, $\alpha \in [0, 1)$.w: Observation weights, ornothingfor equal weights.
Validation
wpasseschecked_observation_weightsagainstx. Otherwise that function raises its error.slvis notnothing, elseIsNothingError, and ifslvis aVecSlv:!isempty(slv), elseIsEmptyError. Seechecked_kernel_solver.
Returns
q::VecNum: The Worst-Case Distribution, one entry for each observation. An observation of weight zero has the entry zero.nothing: When no solver ofslvsolves the programme, or the solver gives no dual.
Related
PortfolioOptimisers.ERM_model — Function
ERM_model(x::VecNum, slv::Slv_VecSlv, alpha::Number, w::Option{<:VecNum})
-> Option{JuMP.Model}Build the exponential cone programme of ERM in a new model, and solve it.
ERM reads the objective value of the solved model, and ERM_worst_case reads the dual of its cone rows. The callers check w and slv first, and they answer alpha = 0 without a model.
Algorithm
- Find
rows, the indices of the observations of positive weight, andN, their number. Withoutw,rowsholds every observation. - Build the programme below in a new model. Its radius term reads
aT, which isalphatimes the number of observations withoutw, andalphatimes the sum ofwwith it. The cone rows readxrandur, the entries ofxand ofuinrows. - Solve the model with the solvers of
slvin turn. - When a solver solves the model, return the model. Otherwise, return
nothing.
JuMP formulation
Variables
t: free scalar $t$.z: scalar $z$, bounded below by zero.u: free $T \times 1$ vector $\boldsymbol{u}$. The entry of an observation of weight zero has a zero coefficient in the budget row, and no cone row reads it.
Expressions
risk: $t - z \ln(\alpha T)$ without observation weights, and $t - z \ln(\alpha W_{T})$ with them.
Constraints
No row carries a string name. The model registers these rows:
- $\sum_{i=1}^{T} u_i - z \leq 0$ without observation weights, and $\sum_{i=1}^{T} w_i u_i - z \leq 0$ with them.
erm_cone: $(-x_i - t,\, z,\, u_i) \in \mathcal{K}_{\exp}$, one row for each $i \in \mathcal{I}$.
The cone rows give $u_i \geq z\, e^{(L_i - t)/z}$. So at the optimum, risk is the minimum over $z$ of $z \ln\!\left(\tfrac{1}{\alpha} \sum_{i \in \mathcal{I}} p_i e^{L_i / z}\right)$, the Chernoff bound of EntropicValueatRisk. An observation of weight zero has $p_i = 0$, so it adds no term to that sum.
The first entry of the dual of the cone row of observation $i$ is $-q_i$, where $\boldsymbol{q}$ is the Worst-Case Distribution of the Kullback-Leibler ball. ERM_worst_case reads it.
Objective
- The model minimises
risk.
Where:
- $\boldsymbol{x}$: Portfolio returns vector $T \times 1$.
- $T$: Number of observations.
- $\alpha$: Significance level (left tail probability), $\alpha \in (0, 1)$.
- $L_i = -x_i$: Loss at observation $i$.
- $\mathcal{I}$: Set of the observations of positive weight. Without observation weights, it holds all $T$ observations.
- $w_i$: Observation weight of observation $i$.
- $W_{T} = \sum_{t=1}^{T} w_{t}$: Total observation weight.
- $p_i$: Probability of observation $i$. It is $1/T$ without observation weights, and the $i$-th observation weight divided by the sum of the weights with them.
- $t$, $z$: Scalar variables of the exponential cone programme.
- $u_i$: Variable of observation $i$ in the exponential cone programme.
- $\mathcal{K}_{\exp} = \mathrm{cl}\,\{(a,b,c) : b\, e^{a/b} \leq c,\, b > 0\}$: Exponential cone.
Arguments
x: Vector of portfolio returns.slv: Solver or vector of solvers.alpha: Significance level, $\alpha \in (0, 1)$.w: Checked observation weights, ornothingfor equal weights.
Returns
model::JuMP.Model: The solved model.nothing: When no solver ofslvsolves the programme.
Related