Conditional X at Risk
PortfolioOptimisers.ConditionalValueatRisk — Type
struct ConditionalValueatRisk{__T_settings, __T_alpha, __T_w} <: RiskMeasureMeasures the Conditional Value-at-Risk (CVaR), the average loss over the worst alpha fraction of the portfolio returns.
The measure is also called Expected Shortfall. It is a coherent risk measure, and it is never below the ValueatRisk at the same level. Corollaries 7 and 12 of [201] state both properties.
Mathematical definition
\[\begin{align} \mathrm{CVaR}_{\alpha}(\boldsymbol{x}) &= \underset{\nu}{\min} \left\{ -\nu + \frac{1}{\alpha W_{T}} \sum_{t=1}^{T} w_{t} \max(\nu - x_t,\, 0) \right\}\,. \end{align}\]
The minimum has a closed form on the sorted returns. The tail holds the $k^{\star} - 1$ smallest returns in full and the boundary return in part, so that its weight is $\alpha W_{T}$ exactly. The part is zero when $W_{k^{\star} - 1} = \alpha W_{T}$:
\[\begin{align} \mathrm{CVaR}_{\alpha}(\boldsymbol{x}) &= -\frac{1}{\alpha W_{T}} \left( \sum_{k=1}^{k^{\star} - 1} w_{(k)} x_{(k)} + \left(\alpha W_{T} - W_{k^{\star} - 1}\right) x_{(k^{\star})} \right)\\ &= \mathrm{VaR}_{\alpha}(\boldsymbol{x}) + \frac{1}{\alpha W_{T}} \sum_{t=1}^{T} w_{t} \max\left(-x_{t} - \mathrm{VaR}_{\alpha}(\boldsymbol{x}),\, 0\right)\,. \end{align}\]
The second line holds because $\nu = x_{(k^{\star})} = -\mathrm{VaR}_{\alpha}(\boldsymbol{x})$ is a minimiser. $\mathrm{VaR}_{\alpha}(\boldsymbol{x})$ is the ValueatRisk at the same level, the smallest loss of the minimisers, as Equation 7 of [202] defines it. Theorem 1 of [202] states the minimum, and Proposition 8 of [201] states the closed form for finitely many scenarios with their probabilities, which are the observation weights here. Both works write the level as a confidence, which is $1 - \alpha$ here. The functor reads $k^{\star}$ off the computed $\alpha W_{T}$, so where a rounding error puts that product under a cumulative weight, it reads the position before the one of ValueatRisk, whose slack absorbs the error. That position is the other end of the minimisers, so the value does not change.
Where:
- $\mathrm{CVaR}_{\alpha}(\boldsymbol{x})$: Conditional Value-at-Risk at level $\alpha$.
- $\boldsymbol{x}$: Portfolio returns vector $T \times 1$.
- $\alpha$: Significance level (left tail probability), $\alpha \in (0, 1)$.
- $T$: Number of observations.
- $w_{t}$: Observation weight of observation $t$. Every $w_{t}$ is one when no observation weights are set, and then $W_{T} = T$ and $k^{\star} = \lfloor \alpha T \rfloor + 1$.
- $\nu$: Rockafellar-Uryasev threshold, the variable the tail average is minimised over. The minimisers run from the lower to the upper $\alpha$-quantile of the series, which differ when $\alpha W_{T}$ is a cumulative weight. Minus the largest minimiser, the upper $\alpha$-quantile, is the Value-at-Risk.
- $x_{(k)}$: $k$-th smallest entry of the series, and $w_{(k)}$ its observation weight.
- $W_{k} = \sum_{j=1}^{k} w_{(j)}$: Cumulative weight of the $k$ smallest entries, with $W_{0} = 0$.
- $k^{\star} = \min\{k : W_{k} > \alpha W_{T}\}$: Boundary index, the position of the one entry that the tail holds in part. It is the position of the upper $\alpha$-quantile of the series, the order statistic of the Value-at-Risk.
- $\mathrm{VaR}_{\alpha}(\boldsymbol{x})$: Value-at-Risk at level $\alpha$, $-x_{(k^{\star})}$.
For a continuous distribution the measure equals $-\mathbb{E}[x \mid x \leq -\mathrm{VaR}_{\alpha}(\boldsymbol{x})]$. On a sample that conditional mean can hold more or less than $\alpha W_{T}$ of the weight, and the part taken of the boundary return is what corrects it.
Algorithm
The functor has one method for each kind of w.
Without observation weights:
- Copy
x, so that the caller's vector keeps its order. - Compute
aT, which is $\alpha T$, andidx, which is $k^{\star} = \lfloor \alpha T \rfloor + 1$, capped at $T$. - Partially sort the copy, so that its
idxsmallest entries come first, in ascending order. - Set
varto minus the entry atidx, the Value-at-Risk. - Sum
x[i] + varover theidx - 1entries before it, givingsum_var. - Return
var - sum_var / aT.
With observation weights:
- Read the weights
wwithget_observation_weights, and their sumsw, which is $W_{T}$. - Sort
xwithsortperm, givingorder, and accumulate the sorted weights, givingcum_w. - Set
alphatosw * r.alpha, and findidx, the first position at whichcum_wexceedsalpha. A rounding error incum_wcan putidxone past the end, and thenidxmoves back to the last position. - If
idxis one, return minus the smallest return. - Otherwise, return minus the weighted sum of the
idx - 1smallest returns plus the boundary return timesalpha - cum_w[idx - 1], divided byalpha.
Fields
settings: Risk measure settings.
alpha: Quantile level for the lower tail. The bound isNum_SigCal, so the slot takes the level itself, anAbstractSignificanceCalibrationAlgorithmthat computes it from the prior result, or a plain function of the same five arguments.
w: Optional observation weights vectorobservations × 1, or a concrete subtype ofDynamicAbstractWeights. Ifnothing, the computation is unweighted.
Constructors
ConditionalValueatRisk(; settings::RiskMeasureSettings = RiskMeasureSettings(), alpha::Num_SigCal = 0.05, w::Option{<:ObsWeights} = nothing) -> ConditionalValueatRiskKeywords correspond to the struct's fields.
Validation
- If
alphais a number:0 <= alpha < 1. Atalpha = 0the measure is the largest loss among the observations with positive weight,worst_positive_weight_loss, and an observation with zero weight cannot set it. - If
wis aStatsBase.AbstractWeights, it is not empty, each entry is finite and>= 0, andsum(w) > 0, throughassert_observation_weights. ADynamicAbstractWeightsholds no weights until it reads the data, sochecked_observation_weightschecks it at evaluation, and also checks there that the weights have one entry for each observation.
Propagated parameters
factory passes its arguments on to these @fprop fields:
w: Replaced with the incomingObsWeights.
Observation weight parameters
obs_weights_view indexes these fields to the selected observations:
w: Indexed to the selected observations throughobs_weights_view.
Functor
(r::ConditionalValueatRisk)(x::VecNum)Computes the CVaR of a portfolio returns vector x, and leaves x unchanged.
Arguments
x::VecNum: Portfolio returns vector.
Examples
julia> ConditionalValueatRisk()ConditionalValueatRisk settings ┼ RiskMeasureSettings │ scale ┼ Float64: 1.0 │ ub ┼ nothing │ rke ┴ Bool: true alpha ┼ Float64: 0.05 w ┴ nothingRelated
RiskMeasureRiskMeasureSettingsValueatRiskDistributionallyRobustConditionalValueatRiskConditionalValueatRiskRangeConditionalDrawdownatRiskfactoryobs_weights_view
References
- [202] R. T. Rockafellar and S. Uryasev. Optimization of conditional value-at-risk. Journal of Risk 2, 21–41 (2000). Theorem 1, Equations 5 and 7.
- [201] R. T. Rockafellar and S. Uryasev. Conditional value-at-risk for general loss distributions. Journal of Banking & Finance 26, 1443–1471 (2002). Corollaries 7 and 12, and Proposition 8, Equation 25.
PortfolioOptimisers.DistributionallyRobustConditionalValueatRisk — Type
struct DistributionallyRobustConditionalValueatRisk{__T_settings, __T_alpha, __T_l, __T_r, __T_w} <: RiskMeasureMeasures the worst-case mean-CVaR loss of a portfolio over a Wasserstein ball of distributions around the sample.
It is the distributionally robust mean-CVaR problem of Mohajerin Esfahani and Kuhn [182]. It is a measure of a portfolio, defined on the weights and the scenario matrix, so a realised return series does not carry enough to evaluate it.
Mathematical definition
Let $\hat{\mathbb{P}}$ be the distribution that puts the weight $w_{t} / W_{T}$ on scenario $\boldsymbol{\xi}_{t}$. Let $\mathcal{B}_{r}(\hat{\mathbb{P}})$ be the ball of radius $r$ around it in the type-1 Wasserstein metric, with the 1-norm as the transport cost, over the distributions supported on $\boldsymbol{\xi} \geq -\boldsymbol{1}$. That support says that no asset loses more than all of its value. The measure is the worst-case expected mean-CVaR loss over the ball:
\[\begin{align} \mathrm{DR\text{-}CVaR}_{\alpha, l, r}(\boldsymbol{w}) &= \underset{\tau}{\min} \; \sup_{\mathbb{Q} \in \mathcal{B}_{r}(\hat{\mathbb{P}})} \; \mathbb{E}_{\mathbb{Q}}\left[\ell_{\tau}(\boldsymbol{\xi})\right]\,, \\ \ell_{\tau}(\boldsymbol{\xi}) &= -\boldsymbol{w}^{\intercal} \boldsymbol{\xi} + l \left(\tau + \dfrac{1}{\alpha} \left(-\boldsymbol{w}^{\intercal} \boldsymbol{\xi} - \tau\right)_{+}\right)\,. \end{align}\]
The loss is the larger of two affine pieces $b_{i} \tau + a_{i} \boldsymbol{w}^{\intercal} \boldsymbol{\xi}$, with $a_{1} = -1$, $b_{1} = l$, $a_{2} = -1 - l/\alpha$ and $b_{2} = l (1 - 1/\alpha)$. The dual of the supremum is a finite convex program:
\[\begin{align} \mathrm{DR\text{-}CVaR}_{\alpha, l, r}(\boldsymbol{w}) = \underset{\tau,\, \lambda,\, \boldsymbol{s},\, \boldsymbol{u}}{\min} \quad & r \lambda + \dfrac{1}{W_{T}} \sum_{t=1}^{T} w_{t} s_{t}\\ \textrm{s.t.} \quad & b_{i} \tau + a_{i} \boldsymbol{w}^{\intercal} \boldsymbol{\xi}_{t} + \boldsymbol{u}_{t}^{(i)\intercal} \left(\boldsymbol{\xi}_{t} + \boldsymbol{1}\right) \leq s_{t}\,,\\ & \left\lVert -\boldsymbol{u}_{t}^{(i)} - a_{i} \boldsymbol{w} \right\rVert_{\infty} \leq \lambda\,,\\ & \boldsymbol{u}_{t}^{(i)} \geq \boldsymbol{0} \quad \forall\, t \in 1 \ldots T,\; i \in \{1, 2\}\,. \end{align}\]
This is Equation 27 of [182]. Corollary 5.1 of [182] gives it for the support $C \boldsymbol{\xi} \leq \boldsymbol{d}$ with $C = -I$ and $\boldsymbol{d} = \boldsymbol{1}$. The infinity norm is the dual of the 1-norm of the transport cost. That work puts the weight $1/T$ on each scenario, so the observation weights $w_{t} / W_{T}$ are the library's extension. The CVaR inside the loss is the minimum of Theorem 1 of [202].
The radius $r$ is in the units of the returns. A distribution $\mathbb{Q}$ is in the ball when it moves the scenarios of $\hat{\mathbb{P}}$ by a mean 1-norm distance of at most $r$. The 1-norm adds the moves of the $N$ assets. For example, the default $r = 0.02$ lets the worst case move one asset by 0.02 in every scenario, or each of the $N$ assets by $0.02 / N$. The scale of a radius rule is in the same units.
Where:
- $\mathrm{DR\text{-}CVaR}_{\alpha, l, r}(\boldsymbol{w})$: Distributionally Robust CVaR.
- $\boldsymbol{w}$: Portfolio weights vector $N \times 1$.
- $\boldsymbol{\xi}_{t}$: Asset returns of scenario $t$, $N \times 1$.
- $\alpha$: Significance level (left tail probability), $\alpha \in (0, 1)$.
- $l$: Tail-term weight of the Esfahani-Kuhn loss, $l > 0$. It does not scale the mean term.
- $r$: Ambiguity radius. It is the radius of the Wasserstein ball, $r > 0$.
- $\tau$: Esfahani-Kuhn level, the variable the worst-case expected loss is minimised over.
- $(\cdot)_{+} = \max(\cdot, 0)$: Positive part.
- $T$: Number of observations.
- $w_{t}$: Observation weight of observation $t$. Every $w_{t}$ is one when no observation weights are set.
- $W_{T} = \sum_{t=1}^{T} w_{t}$: Total observation weight.
- $\lambda$: Bound on the Lipschitz modulus of the loss in the dual norm.
- $s_{t}$: Epigraph variable of the worst-case loss at scenario $t$.
- $\boldsymbol{u}_{t}^{(i)}$: Dual variables of the support constraint, for scenario $t$ and piece $i$, $N \times 1$.
Three consequences follow. The first two contradict a reading of the measure as CVaR plus a constant.
- The robustness premium $r \lambda$ is not a constant. $\lambda$ depends on $\boldsymbol{w}$, so $r$ cannot be factored out of the optimisation.
- The loss carries a mean term that $l$ does not scale. As $r \to 0$ the ball collapses to $\hat{\mathbb{P}}$, and the measure goes to $-\mathbb{E}_{\hat{\mathbb{P}}}[\boldsymbol{w}^{\intercal} \boldsymbol{\xi}] + l \, \mathrm{CVaR}_{\alpha}(\boldsymbol{w}^{\intercal} \boldsymbol{\xi})$, not to $\mathrm{CVaR}_{\alpha}$ alone.
- As $r$ grows, the long-only, fully invested portfolio of minimum measure goes to the equally weighted portfolio. This is Proposition 7.2 of [182], for this support.
Fields
settings: Risk measure settings.
alpha: Quantile level for the lower tail. The bound isNum_SigCal, so the slot takes the level itself, anAbstractSignificanceCalibrationAlgorithmthat computes it from the prior result, or a plain function of the same five arguments.
l: Weight of the tail term in the Esfahani-Kuhn loss. The mean term is not scaled by it.
r: Radius of the type-1 Wasserstein ambiguity ball. It multiplies a decision variable, so it is not a constant offset.
w: Optional observation weights vectorobservations × 1, or a concrete subtype ofDynamicAbstractWeights. Ifnothing, the computation is unweighted.
Constructors
DistributionallyRobustConditionalValueatRisk(; settings::RiskMeasureSettings = RiskMeasureSettings(), alpha::Num_SigCal = 0.05, l::Num_AmbTwtCal = 1.0, r::Num_AmbRadCal = 0.02, w::Option{<:ObsWeights} = nothing) -> DistributionallyRobustConditionalValueatRiskKeywords correspond to the struct's fields.
Validation
- If
alphais a number:0 < alpha < 1. - If
lis a number:l > 0and finite. - If
ris a number:r > 0and finite. - If
wis aStatsBase.AbstractWeights, it is not empty, each entry is finite and>= 0, andsum(w) > 0, throughassert_observation_weights. ADynamicAbstractWeightsholds no weights until it reads the data, sochecked_observation_weightschecks it at evaluation, and also checks there that the weights have one entry for each observation.
Propagated parameters
factory passes its arguments on to these @fprop fields:
w: Replaced with the incomingObsWeights.
Observation weight parameters
obs_weights_view indexes these fields to the selected observations:
w: Indexed to the selected observations throughobs_weights_view.
Functor
(r::DistributionallyRobustConditionalValueatRisk)(x::VecNum)Computes the plain CVaR of a portfolio returns vector x at level alpha, and ignores l and r. The functor shares its method with ConditionalValueatRisk through the RMCVaR union, so the # Algorithm of that type is its algorithm.
The robust value needs the weights and the scenario matrix, and a return series carries neither. A JuMP optimisation builds the program of the definition, and the risk it reports is the robust value.
Arguments
x::VecNum: Portfolio returns vector.
Examples
julia> DistributionallyRobustConditionalValueatRisk()DistributionallyRobustConditionalValueatRisk settings ┼ RiskMeasureSettings │ scale ┼ Float64: 1.0 │ ub ┼ nothing │ rke ┴ Bool: true alpha ┼ Float64: 0.05 l ┼ Float64: 1.0 r ┼ Float64: 0.02 w ┴ nothingRelated
RiskMeasureRiskMeasureSettingsConditionalValueatRiskDistributionallyRobustConditionalValueatRiskRangeDistributionallyRobustConditionalDrawdownatRiskfactoryobs_weights_view
References
- [202] R. T. Rockafellar and S. Uryasev. Optimization of conditional value-at-risk. Journal of Risk 2, 21–41 (2000). Theorem 1, Equation 5.
- [182] P. Mohajerin Esfahani and D. Kuhn. Data-driven distributionally robust optimization using the Wasserstein metric: performance guarantees and tractable reformulations. Mathematical Programming 171, 115–166 (2018). Section 7.1, Equation 27, Corollary 5.1 and Proposition 7.2.
PortfolioOptimisers.ConditionalValueatRiskRange — Type
struct ConditionalValueatRiskRange{__T_settings, __T_alpha, __T_beta, __T_w} <: RangeRiskMeasureMeasures the spread between the two tails of the portfolio returns, the CVaR of the losses plus the CVaR of the gains.
The lower tail is the ConditionalValueatRisk at level alpha of the returns, and the upper tail is the same measure at level beta of the negated returns.
Mathematical definition
\[\begin{align} \mathrm{CVaRRange}_{\alpha,\beta}(\boldsymbol{x}) &= \mathrm{CVaR}_{\alpha}(\boldsymbol{x}) + \mathrm{CVaR}_{\beta}(-\boldsymbol{x})\,. \end{align}\]
Where:
- $\mathrm{CVaRRange}_{\alpha,\beta}(\boldsymbol{x})$: CVaR range, the spread between the two tails.
- $\boldsymbol{x}$: Portfolio returns vector $T \times 1$.
- $\mathrm{CVaR}_{\alpha}(\boldsymbol{x})$: Lower-tail expected shortfall at level $\alpha$.
- $\mathrm{CVaR}_{\beta}(-\boldsymbol{x})$: Upper-tail expected surplus at level $\beta$.
The upper tail is the base measure applied to the negated returns $-\boldsymbol{x}$, so both tails are reported on the same sign convention and the range is their sum, not their difference. Both tails read the same observation weights.
Section 7.2.3.2 of [12] defines this range and names [199] as the source of the range measures. No copy of that work was found. Its Equation 7.75 prints a difference of the two tails, but its programme, Equation 7.77, minimises the sum above.
Algorithm
The functor has one method for each kind of w. Each tail follows the steps of the matching method of ConditionalValueatRisk.
Without observation weights:
- Copy
x, so that the caller's vector keeps its order. - Partially sort the copy ascending, and compute
loss, the CVaR at levelalphaof the returns. - Negate the copy and partially sort it ascending, which orders the returns descending, and compute
gain, minus the CVaR at levelbetaof the negated returns. - Return
loss - gain.
With observation weights:
- Sort
xwithsortperm, givingorder, and computelossfrom the ascending returns. - Reverse
order, and computegainfrom the descending returns with the same weights. The method reverses the permutation and never a view, because a view writes through intoxand into the stored weights. - Return
loss - gain.
Fields
settings: Risk measure settings.
alpha: Quantile level for the lower tail. The bound isNum_SigCal, so the slot takes the level itself, anAbstractSignificanceCalibrationAlgorithmthat computes it from the prior result, or a plain function of the same five arguments.
beta: Quantile level for the upper tail. The bound isNum_SigCal, so the slot takes the level itself, anAbstractSignificanceCalibrationAlgorithmthat computes it from the prior result, or a plain function of the same five arguments.
w: Optional observation weights vectorobservations × 1, or a concrete subtype ofDynamicAbstractWeights. Ifnothing, the computation is unweighted.
Constructors
ConditionalValueatRiskRange(; settings::RiskMeasureSettings = RiskMeasureSettings(), alpha::Num_SigCal = 0.05, beta::Num_SigCal = alpha, w::Option{<:ObsWeights} = nothing) -> ConditionalValueatRiskRangeKeywords correspond to the struct's fields.
Validation
- If
alphais a number:0 < alpha < 1. - If
betais a number:0 < beta < 1. - If
wis aStatsBase.AbstractWeights, it is not empty, each entry is finite and>= 0, andsum(w) > 0, throughassert_observation_weights. ADynamicAbstractWeightsholds no weights until it reads the data, sochecked_observation_weightschecks it at evaluation, and also checks there that the weights have one entry for each observation.
Propagated parameters
factory passes its arguments on to these @fprop fields:
w: Replaced with the incomingObsWeights.
Observation weight parameters
obs_weights_view indexes these fields to the selected observations:
w: Indexed to the selected observations throughobs_weights_view.
Functor
(r::ConditionalValueatRiskRange)(x::VecNum)Computes the CVaR Range of a portfolio returns vector x, as the sum of the two tail averages, and leaves x unchanged. The functor shares its method with DistributionallyRobustConditionalValueatRiskRange through the RMCVaRRg union. That method holds the upper tail in the negated convention of ConditionalValueatRisk, so it writes the sum as loss - gain.
Arguments
x::VecNum: Portfolio returns vector.
Examples
julia> ConditionalValueatRiskRange()ConditionalValueatRiskRange settings ┼ RiskMeasureSettings │ scale ┼ Float64: 1.0 │ ub ┼ nothing │ rke ┴ Bool: true alpha ┼ Float64: 0.05 beta ┼ Float64: 0.05 w ┴ nothingRelated
RiskMeasureRiskMeasureSettingsConditionalValueatRiskValueatRiskRangeDistributionallyRobustConditionalValueatRiskRangefactoryobs_weights_view
References
- [202] R. T. Rockafellar and S. Uryasev. Optimization of conditional value-at-risk. Journal of Risk 2, 21–41 (2000). Theorem 1, Equation 5.
- [201] R. T. Rockafellar and S. Uryasev. Conditional value-at-risk for general loss distributions. Journal of Banking & Finance 26, 1443–1471 (2002). Proposition 8, Equation 25.
- [12] D. Cajas. Advanced Portfolio Optimization: A Cutting-edge Quantitative Approach (Springer Nature Switzerland, 2025). Section 7.2.3.2, Equations 7.75 and 7.77. The original source of this formulation was not found. The formulation follows this work and is not checked against the original.
- [199] D. Cajas. OWA portfolio optimization: A disciplined convex programming framework. Available at SSRN 3988927 (2021).
PortfolioOptimisers.DistributionallyRobustConditionalValueatRiskRange — Type
struct DistributionallyRobustConditionalValueatRiskRange{__T_settings, __T_alpha, __T_l_a, __T_r_a, __T_beta, __T_l_b, __T_r_b, __T_w} <: RangeRiskMeasureMeasures the spread between the two robust tails of a portfolio, a worst-case mean-CVaR loss on each side.
Each tail is the program of DistributionallyRobustConditionalValueatRisk with its own significance level, tail weight and radius. That program is Equation 27 of [182], and it treats one tail only. This measure is the library's generalisation of it to two tails.
Mathematical definition
\[\begin{align} \mathrm{DR\text{-}CVaRRange}(\boldsymbol{w}) &= \mathrm{DR\text{-}CVaR}_{\alpha, l_a, r_a}(\boldsymbol{w};\, \boldsymbol{\xi}) + \mathrm{DR\text{-}CVaR}_{\beta, l_b, r_b}(\boldsymbol{w};\, -\boldsymbol{\xi})\,. \end{align}\]
Where:
- $\mathrm{DR\text{-}CVaRRange}(\boldsymbol{w})$: DR-CVaR range.
- $\boldsymbol{w}$: Portfolio weights vector $N \times 1$.
- $\mathrm{DR\text{-}CVaR}_{\alpha, l_a, r_a}(\boldsymbol{w};\, \boldsymbol{\xi})$: Lower-tail DR-CVaR on the scenarios $\boldsymbol{\xi}_{t}$, with the support $\boldsymbol{\xi} \geq -\boldsymbol{1}$.
- $\mathrm{DR\text{-}CVaR}_{\beta, l_b, r_b}(\boldsymbol{w};\, -\boldsymbol{\xi})$: Upper-tail DR-CVaR on the negated scenarios $-\boldsymbol{\xi}_{t}$. Its support $-\boldsymbol{\xi} \geq -\boldsymbol{1}$ says that no asset gains more than all of its value.
The upper tail is the base measure applied to the negated returns $-\boldsymbol{x}$, so both tails are reported on the same sign convention and the range is their sum, not their difference. The two tails have separate Wasserstein balls, and both read the same observation weights.
Each radius is in the units of the returns, as the radius of DistributionallyRobustConditionalValueatRisk is. $r_a$ bounds the mean 1-norm move of the scenarios that the lower tail reads, and $r_b$ bounds the move of the negated scenarios that the upper tail reads.
As both radii go to zero, the two mean terms cancel, and the measure goes to $l_a \, \mathrm{CVaR}_{\alpha}(\boldsymbol{x}) + l_b \, \mathrm{CVaR}_{\beta}(-\boldsymbol{x})$, with $\boldsymbol{x}$ the portfolio returns of the scenarios.
Fields
settings: Risk measure settings.
alpha: Quantile level for the lower tail. The bound isNum_SigCal, so the slot takes the level itself, anAbstractSignificanceCalibrationAlgorithmthat computes it from the prior result, or a plain function of the same five arguments.
l_a: Weight of the tail term in the Esfahani-Kuhn loss of the lower tail. The mean term is not scaled by it. The bound isNum_AmbTwtCal, so the slot takes the weight itself, anAbstractAmbiguityTailWeightCalibrationAlgorithmthat computes it from the prior result, or a plain function of the same five arguments.
r_a: Radius of the type-1 Wasserstein ambiguity ball of the lower tail. It multiplies a decision variable, so it is not a constant offset. The bound isNum_AmbRadCal, so the slot takes the radius itself, anAbstractAmbiguityRadiusCalibrationAlgorithmthat computes it from the prior result, or a plain function of the same five arguments.
beta: Quantile level for the upper tail. The bound isNum_SigCal, so the slot takes the level itself, anAbstractSignificanceCalibrationAlgorithmthat computes it from the prior result, or a plain function of the same five arguments.
l_b: Weight of the tail term in the Esfahani-Kuhn loss of the upper tail. The mean term is not scaled by it. The bound isNum_AmbTwtCal, so the slot takes the weight itself, anAbstractAmbiguityTailWeightCalibrationAlgorithmthat computes it from the prior result, or a plain function of the same five arguments.
r_b: Radius of the type-1 Wasserstein ambiguity ball of the upper tail. It multiplies a decision variable, so it is not a constant offset. The bound isNum_AmbRadCal, so the slot takes the radius itself, anAbstractAmbiguityRadiusCalibrationAlgorithmthat computes it from the prior result, or a plain function of the same five arguments.
w: Optional observation weights vectorobservations × 1, or a concrete subtype ofDynamicAbstractWeights. Ifnothing, the computation is unweighted.
Constructors
DistributionallyRobustConditionalValueatRiskRange(; settings::RiskMeasureSettings = RiskMeasureSettings(), alpha::Num_SigCal = 0.05, l_a::Num_AmbTwtCal = 1.0, r_a::Num_AmbRadCal = 0.02, beta::Num_SigCal = alpha, l_b::Num_AmbTwtCal = 1.0, r_b::Num_AmbRadCal = 0.02, w::Option{<:ObsWeights} = nothing) -> DistributionallyRobustConditionalValueatRiskRangeKeywords correspond to the struct's fields.
Validation
- If
alphais a number:0 < alpha < 1. - If
betais a number:0 < beta < 1. - Each of
l_a,r_a,l_bandr_bthat is a number:> 0and finite. - If
wis aStatsBase.AbstractWeights, it is not empty, each entry is finite and>= 0, andsum(w) > 0, throughassert_observation_weights. ADynamicAbstractWeightsholds no weights until it reads the data, sochecked_observation_weightschecks it at evaluation, and also checks there that the weights have one entry for each observation.
Propagated parameters
factory passes its arguments on to these @fprop fields:
w: Replaced with the incomingObsWeights.
Observation weight parameters
obs_weights_view indexes these fields to the selected observations:
w: Indexed to the selected observations throughobs_weights_view.
Functor
(r::DistributionallyRobustConditionalValueatRiskRange)(x::VecNum)Computes the plain CVaR Range of a portfolio returns vector x at levels alpha and beta, and ignores l_a, r_a, l_b and r_b. The functor shares its method with ConditionalValueatRiskRange through the RMCVaRRg union, so the # Algorithm of that type is its algorithm.
The robust value needs the weights and the scenario matrix, and a return series carries neither. A JuMP optimisation builds the two programs of the definition, and the risk it reports is the robust value.
Arguments
x::VecNum: Portfolio returns vector.
Examples
julia> DistributionallyRobustConditionalValueatRiskRange()DistributionallyRobustConditionalValueatRiskRange settings ┼ RiskMeasureSettings │ scale ┼ Float64: 1.0 │ ub ┼ nothing │ rke ┴ Bool: true alpha ┼ Float64: 0.05 l_a ┼ Float64: 1.0 r_a ┼ Float64: 0.02 beta ┼ Float64: 0.05 l_b ┼ Float64: 1.0 r_b ┼ Float64: 0.02 w ┴ nothingRelated
RiskMeasureRiskMeasureSettingsConditionalValueatRiskRangeDistributionallyRobustConditionalValueatRiskfactoryobs_weights_view
References
- [202] R. T. Rockafellar and S. Uryasev. Optimization of conditional value-at-risk. Journal of Risk 2, 21–41 (2000). Theorem 1, Equation 5.
- [182] P. Mohajerin Esfahani and D. Kuhn. Data-driven distributionally robust optimization using the Wasserstein metric: performance guarantees and tractable reformulations. Mathematical Programming 171, 115–166 (2018). Section 7.1, Equation 27.
PortfolioOptimisers.ConditionalDrawdownatRisk — Type
struct ConditionalDrawdownatRisk{__T_settings, __T_alpha, __T_w} <: RiskMeasureMeasures the Conditional Drawdown-at-Risk (CDaR), the average of the worst alpha fraction of the uncompounded drawdowns.
It is the ConditionalValueatRisk of the drawdown series in place of the returns. The size of each drawdown is a convex and positively homogeneous function of the returns, so the measure is too.
Mathematical definition
\[\begin{align} c_t &= \sum_{s=1}^{t} x_s\,, \quad c_0 = 0\,, \\ d_t &= c_t - \max_{0 \leq s \leq t} c_s\,, \\ \mathrm{CDaR}_{\alpha}(\boldsymbol{x}) &= \underset{\nu}{\min} \left\{ -\nu + \frac{1}{\alpha W_{T}} \sum_{t=1}^{T} w_{t} \max(\nu - d_t,\, 0) \right\}\,. \end{align}\]
Where:
- $\mathrm{CDaR}_{\alpha}(\boldsymbol{x})$: Conditional Drawdown-at-Risk at level $\alpha$.
- $\boldsymbol{x}$: Portfolio returns vector $T \times 1$.
- $c_t$: Cumulative simple portfolio return at period $t$.
- $d_t \leq 0$: Absolute drawdown at period $t$.
- $\alpha$: Significance level (left tail probability), $\alpha \in (0, 1)$.
- $T$: Number of observations.
- $w_{t}$: Observation weight of observation $t$. Every $w_{t}$ is one when no observation weights are set.
- $W_{T} = \sum_{t=1}^{T} w_{t}$: Total observation weight.
- $\nu$: Rockafellar-Uryasev threshold, the variable the tail average is minimised over. The minimisers run from the lower to the upper $\alpha$-quantile of the series, which differ when $\alpha W_{T}$ is a cumulative weight. Minus the largest minimiser, the upper $\alpha$-quantile, is the Value-at-Risk.
The running peak starts at $c_0 = 0$, so a series that falls from its first period is in drawdown from the start. The minimum has the sorted closed form that conditional_drawdown_at_risk states.
Definition 3.4 of [200] defines the measure on one sample path, and Proposition 3.1 of that work states the convexity and the positive homogeneity of the drawdown. That work weighs each drawdown equally, so the observation weights follow Proposition 8 of [201].
Algorithm
- Compute the drawdown series with
absolute_drawdown_vec. - Read the observation weights with
get_observation_weights. - Reduce the drawdown series to its tail average with
conditional_drawdown_at_risk.
Fields
settings: Risk measure settings.
alpha: Quantile level for the lower tail. The bound isNum_SigCal, so the slot takes the level itself, anAbstractSignificanceCalibrationAlgorithmthat computes it from the prior result, or a plain function of the same five arguments.
w: Optional observation weights vectorobservations × 1, or a concrete subtype ofDynamicAbstractWeights. Ifnothing, the computation is unweighted.
Constructors
ConditionalDrawdownatRisk(; settings::RiskMeasureSettings = RiskMeasureSettings(), alpha::Num_SigCal = 0.05, w::Option{<:ObsWeights} = nothing) -> ConditionalDrawdownatRiskKeywords correspond to the struct's fields.
Validation
- If
alphais a number:0 <= alpha < 1. Atalpha = 0the measure is the largest loss among the observations with positive weight,worst_positive_weight_loss, and an observation with zero weight cannot set it. - If
wis aStatsBase.AbstractWeights, it is not empty, each entry is finite and>= 0, andsum(w) > 0, throughassert_observation_weights. ADynamicAbstractWeightsholds no weights until it reads the data, sochecked_observation_weightschecks it at evaluation, and also checks there that the weights have one entry for each observation.
Propagated parameters
factory passes its arguments on to these @fprop fields:
w: Replaced with the incomingObsWeights.
Observation weight parameters
obs_weights_view indexes these fields to the selected observations:
w: Indexed to the selected observations throughobs_weights_view.
Functor
(r::ConditionalDrawdownatRisk)(x::VecNum)Computes the CDaR of a portfolio returns vector x, and leaves x unchanged.
Arguments
x::VecNum: Portfolio returns vector.
Examples
julia> ConditionalDrawdownatRisk()ConditionalDrawdownatRisk settings ┼ RiskMeasureSettings │ scale ┼ Float64: 1.0 │ ub ┼ nothing │ rke ┴ Bool: true alpha ┼ Float64: 0.05 w ┴ nothingRelated
RiskMeasureRiskMeasureSettingsDrawdownatRiskDistributionallyRobustConditionalDrawdownatRiskRelativeConditionalDrawdownatRiskconditional_drawdown_at_riskfactoryobs_weights_view
References
- [200] A. Chekhlov, S. Uryasev and M. Zabarankin. Drawdown measure in portfolio optimization. International Journal of Theoretical and Applied Finance 8, 13–58 (2005). Section 3, Definition 3.4, Equation 3.11, and Proposition 3.1.
- [201] R. T. Rockafellar and S. Uryasev. Conditional value-at-risk for general loss distributions. Journal of Banking & Finance 26, 1443–1471 (2002). Proposition 8, Equation 25.
PortfolioOptimisers.DistributionallyRobustConditionalDrawdownatRisk — Type
struct DistributionallyRobustConditionalDrawdownatRisk{__T_settings, __T_alpha, __T_l, __T_r, __T_w} <: RiskMeasureMeasures the worst-case mean-CDaR loss of a portfolio over a Wasserstein ball of drawdown scenarios around the sample.
It uses the program of DistributionallyRobustConditionalValueatRisk, which is Equation 27 of [182] and treats returns only. This measure is the library's generalisation of that program to drawdowns.
Mathematical definition
Let $d_{t}(\boldsymbol{w}) \geq 0$ be the uncompounded drawdown of the portfolio at period $t$, and let $\mathbf{D}_{t}$ be the vector of the uncompounded drawdowns of the assets at period $t$, each $\leq 0$. The loss is the mean-CDaR loss of the portfolio drawdown:
\[\begin{align} \ell_{\tau}(d) &= d + l \left(\tau + \dfrac{1}{\alpha} \left(d - \tau\right)_{+}\right)\,. \end{align}\]
The measure $\mathrm{DR\text{-}CDaR}_{\alpha, l, r}(\boldsymbol{w})$ is the program of DistributionallyRobustConditionalValueatRisk with two substitutions.
- The rows read the portfolio drawdown, so $-d_{t}(\boldsymbol{w})$ takes the place of $\boldsymbol{w}^{\intercal} \boldsymbol{\xi}_{t}$.
- The transport cost reads the asset drawdowns, so $\mathbf{D}_{t}$ takes the place of $\boldsymbol{\xi}_{t}$, so the support constraint is $\mathbf{D} \geq -\boldsymbol{1}$.
The radius $r$ is in the units of the uncompounded drawdowns, which are cumulative returns. The ball moves the asset drawdowns $\mathbf{D}_{t}$ by a mean 1-norm distance of at most $r$, and the 1-norm adds the moves of the $N$ assets. A drawdown adds many returns, so it is often larger than one return, and a radius that suits the returns can be small for the drawdowns.
Where:
- $\mathrm{DR\text{-}CDaR}_{\alpha, l, r}(\boldsymbol{w})$: Distributionally Robust CDaR.
- $\boldsymbol{w}$: Portfolio weights vector $N \times 1$.
- $d_{t}(\boldsymbol{w})$: Uncompounded drawdown of the portfolio at period $t$, the running peak of the cumulative return minus its current value, with the peak starting at zero.
- $\mathbf{D}_{t}$: Uncompounded drawdowns of the assets at period $t$, $N \times 1$.
- $\alpha$: Significance level (left tail probability), $\alpha \in (0, 1)$.
- $l$: Tail-term weight of the Esfahani-Kuhn loss, $l > 0$. It does not scale the mean term.
- $r$: Ambiguity radius. It is the radius of the Wasserstein ball, $r > 0$.
- $\tau$: Esfahani-Kuhn level, the variable the worst-case expected loss is minimised over.
- $(\cdot)_{+} = \max(\cdot, 0)$: Positive part.
Three consequences follow.
- The radius multiplies a decision variable, so it cannot be factored out, and $l$ does not scale the mean drawdown term. As $r \to 0$ the measure goes to $\mathbb{E}[d] + l \, \mathrm{CDaR}_{\alpha}(d)$, not to $\mathrm{CDaR}_{\alpha}$ alone.
- The rows read $d_{t}(\boldsymbol{w})$, and the robust premium reads the linear function $-\boldsymbol{w}^{\intercal} \mathbf{D}_{t}$. For long-only weights $d_{t}(\boldsymbol{w}) \leq -\boldsymbol{w}^{\intercal} \mathbf{D}_{t}$, with equality when every asset with a positive weight has its peak in the same period as the portfolio.
- The sample lies inside the support when no asset's cumulative return falls more than one below its running peak.
Fields
settings: Risk measure settings.
alpha: Quantile level for the lower tail. The bound isNum_SigCal, so the slot takes the level itself, anAbstractSignificanceCalibrationAlgorithmthat computes it from the prior result, or a plain function of the same five arguments.
l: Weight of the tail term in the Esfahani-Kuhn loss. The mean term is not scaled by it.
r: Radius of the type-1 Wasserstein ambiguity ball. It multiplies a decision variable, so it is not a constant offset.
w: Optional observation weights vectorobservations × 1, or a concrete subtype ofDynamicAbstractWeights. Ifnothing, the computation is unweighted.
Constructors
DistributionallyRobustConditionalDrawdownatRisk(; settings::RiskMeasureSettings = RiskMeasureSettings(), alpha::Num_SigCal = 0.05, l::Num_AmbTwtCal = 1.0, r::Num_AmbRadCal = 0.02, w::Option{<:ObsWeights} = nothing) -> DistributionallyRobustConditionalDrawdownatRiskKeywords correspond to the struct's fields.
Validation
- If
alphais a number:0 < alpha < 1. - If
lis a number:l > 0and finite. - If
ris a number:r > 0and finite. - If
wis aStatsBase.AbstractWeights, it is not empty, each entry is finite and>= 0, andsum(w) > 0, throughassert_observation_weights. ADynamicAbstractWeightsholds no weights until it reads the data, sochecked_observation_weightschecks it at evaluation, and also checks there that the weights have one entry for each observation.
Propagated parameters
factory passes its arguments on to these @fprop fields:
w: Replaced with the incomingObsWeights.
Observation weight parameters
obs_weights_view indexes these fields to the selected observations:
w: Indexed to the selected observations throughobs_weights_view.
Functor
(r::DistributionallyRobustConditionalDrawdownatRisk)(x::VecNum)Computes the plain CDaR of a portfolio returns vector x at level alpha, and ignores l and r. The functor shares its method with ConditionalDrawdownatRisk through the RMCDaR union, so the # Algorithm of that type is its algorithm.
The robust value needs the weights and the asset drawdowns, and a return series carries neither. A JuMP optimisation builds the program of the definition, and the risk it reports is the robust value.
Arguments
x::VecNum: Portfolio returns vector.
Examples
julia> DistributionallyRobustConditionalDrawdownatRisk()DistributionallyRobustConditionalDrawdownatRisk settings ┼ RiskMeasureSettings │ scale ┼ Float64: 1.0 │ ub ┼ nothing │ rke ┴ Bool: true alpha ┼ Float64: 0.05 l ┼ Float64: 1.0 r ┼ Float64: 0.02 w ┴ nothingRelated
RiskMeasureRiskMeasureSettingsConditionalDrawdownatRiskDistributionallyRobustConditionalValueatRiskconditional_drawdown_at_riskfactoryobs_weights_view
References
- [200] A. Chekhlov, S. Uryasev and M. Zabarankin. Drawdown measure in portfolio optimization. International Journal of Theoretical and Applied Finance 8, 13–58 (2005). Section 3, Definition 3.4, Equation 3.11.
- [182] P. Mohajerin Esfahani and D. Kuhn. Data-driven distributionally robust optimization using the Wasserstein metric: performance guarantees and tractable reformulations. Mathematical Programming 171, 115–166 (2018). Section 7.1, Equation 27, and Corollary 5.1.
PortfolioOptimisers.RelativeConditionalDrawdownatRisk — Type
struct RelativeConditionalDrawdownatRisk{__T_settings, __T_alpha, __T_w} <: HierarchicalRiskMeasureMeasures the Relative Conditional Drawdown-at-Risk, the average of the worst alpha fraction of the compounded drawdowns.
It is the ConditionalValueatRisk of the relative drawdown series. The compounded wealth is a product of linear functions of the weights, so the library states no JuMP formulation of the measure, and it is a HierarchicalRiskMeasure.
Mathematical definition
\[\begin{align} C_t &= \prod_{s=1}^{t} (1 + x_s)\,, \quad C_0 = 1\,, \\ rd_t &= \frac{C_t}{\max_{0 \leq s \leq t} C_s} - 1\,, \\ \mathrm{RCDaR}_{\alpha}(\boldsymbol{x}) &= \underset{\nu}{\min} \left\{ -\nu + \frac{1}{\alpha W_{T}} \sum_{t=1}^{T} w_{t} \max(\nu - rd_t,\, 0) \right\}\,. \end{align}\]
Where:
- $\mathrm{RCDaR}_{\alpha}(\boldsymbol{x})$: Relative Conditional Drawdown-at-Risk at level $\alpha$.
- $\boldsymbol{x}$: Portfolio returns vector $T \times 1$.
- $C_t$: Compound wealth process at period $t$.
- $rd_t \leq 0$: Relative drawdown at period $t$.
- $\alpha$: Significance level (left tail probability), $\alpha \in (0, 1)$.
- $T$: Number of observations.
- $w_{t}$: Observation weight of observation $t$. Every $w_{t}$ is one when no observation weights are set.
- $W_{T} = \sum_{t=1}^{T} w_{t}$: Total observation weight.
- $\nu$: Rockafellar-Uryasev threshold, the variable the tail average is minimised over. The minimisers run from the lower to the upper $\alpha$-quantile of the series, which differ when $\alpha W_{T}$ is a cumulative weight. Minus the largest minimiser, the upper $\alpha$-quantile, is the Value-at-Risk.
The running peak starts at $C_0 = 1$, the initial wealth. The minimum has the sorted closed form that conditional_drawdown_at_risk states.
Section 3 of [200] defines the drawdown of the uncompounded cumulative return only. It names the relative drawdown and states that it lacks the properties of the absolute drawdown, but it defines no measure on it. The relative drawdown series above, and the measure of Definition 3.4 of that work on it, are the library's extension.
Algorithm
- Compute the relative drawdown series with
relative_drawdown_vec. - Read the observation weights with
get_observation_weights. - Reduce the series to its tail average with
conditional_drawdown_at_risk.
Fields
settings: Risk measure settings.
alpha: Quantile level for the lower tail. The bound isNum_SigCal, so the slot takes the level itself, anAbstractSignificanceCalibrationAlgorithmthat computes it from the prior result, or a plain function of the same five arguments.
w: Optional observation weights vectorobservations × 1, or a concrete subtype ofDynamicAbstractWeights. Ifnothing, the computation is unweighted.
Constructors
RelativeConditionalDrawdownatRisk(; settings::HierarchicalRiskMeasureSettings = HierarchicalRiskMeasureSettings(), alpha::Num_SigCal = 0.05, w::Option{<:ObsWeights} = nothing) -> RelativeConditionalDrawdownatRiskKeywords correspond to the struct's fields.
Validation
- If
alphais a number:0 <= alpha < 1. Atalpha = 0the measure is the largest loss among the observations with positive weight,worst_positive_weight_loss, and an observation with zero weight cannot set it. - If
wis aStatsBase.AbstractWeights, it is not empty, each entry is finite and>= 0, andsum(w) > 0, throughassert_observation_weights. ADynamicAbstractWeightsholds no weights until it reads the data, sochecked_observation_weightschecks it at evaluation, and also checks there that the weights have one entry for each observation.
Propagated parameters
factory passes its arguments on to these @fprop fields:
w: Replaced with the incomingObsWeights.
Observation weight parameters
obs_weights_view indexes these fields to the selected observations:
w: Indexed to the selected observations throughobs_weights_view.
Functor
(r::RelativeConditionalDrawdownatRisk)(x::VecNum)Computes the Relative CDaR of a portfolio returns vector x, and leaves x unchanged.
Arguments
x::VecNum: Portfolio returns vector.
Examples
julia> RelativeConditionalDrawdownatRisk()RelativeConditionalDrawdownatRisk settings ┼ HierarchicalRiskMeasureSettings │ scale ┴ Float64: 1.0 alpha ┼ Float64: 0.05 w ┴ nothingRelated
HierarchicalRiskMeasureHierarchicalRiskMeasureSettingsConditionalDrawdownatRiskRelativeDrawdownatRiskconditional_drawdown_at_riskfactoryobs_weights_view
References
- [200] A. Chekhlov, S. Uryasev and M. Zabarankin. Drawdown measure in portfolio optimization. International Journal of Theoretical and Applied Finance 8, 13–58 (2005). Section 3, Definition 3.4, Equation 3.11.
- [201] R. T. Rockafellar and S. Uryasev. Conditional value-at-risk for general loss distributions. Journal of Banking & Finance 26, 1443–1471 (2002). Proposition 8, Equation 25.
References
- [12]
- D. Cajas. Advanced Portfolio Optimization: A Cutting-edge Quantitative Approach (Springer Nature Switzerland, 2025).
- [182]
- P. Mohajerin Esfahani and D. Kuhn. Data-driven distributionally robust optimization using the Wasserstein metric: performance guarantees and tractable reformulations. Mathematical Programming 171, 115–166 (2018).
- [199]
- D. Cajas. OWA portfolio optimization: A disciplined convex programming framework. Available at SSRN 3988927 (2021).
- [200]
- A. Chekhlov, S. Uryasev and M. Zabarankin. Drawdown measure in portfolio optimization. International Journal of Theoretical and Applied Finance 8, 13–58 (2005).
- [201]
- R. T. Rockafellar and S. Uryasev. Conditional value-at-risk for general loss distributions. Journal of Banking & Finance 26, 1443–1471 (2002).
- [202]
- R. T. Rockafellar and S. Uryasev. Optimization of conditional value-at-risk. Journal of Risk 2, 21–41 (2000).