Variance Constraints: private API

PortfolioOptimisers.get_chol_or_sigma_pm — Function
get_chol_or_sigma_pm(
    model::Model,
    pr::AbstractPriorResult
) -> Any
get_chol_or_sigma_pm(
    model::Model,
    pr::AbstractPriorResult,
    mtx_sqrt::Union{Nothing, AbstractMatrixSquareRootAlgorithm}
) -> Any

Return the factor of the prior's covariance matrix, and register it in the model on the first call.

The factor is the prior's chol when the prior carries one, and the transpose of the square root of the prior's sigma under mtx_sqrt otherwise, which matrix_square_root takes. The factor of a factor prior is not square, and the second-order cone is well posed on it. G is a shared entry, so every measure of the model that falls back to the prior reads one factor, and a later call returns it without a second factorisation. The first measure that falls back to the prior sets the algorithm. On a positive definite matrix every algorithm gives the Cholesky factor.

JuMP formulation

Expressions

  • G: $\mathbf{G}$, registered on the first call.

Where:

  • $\mathbf{G}$: Covariance factor, with $\mathbf{G}^\intercal \mathbf{G} = \mathbf{\Sigma}$. It need not be square, and $\lVert \mathbf{G} \boldsymbol{w} \rVert_{2}^{2} = \boldsymbol{w}^\intercal \mathbf{\Sigma} \boldsymbol{w}$.

Arguments

  • model::JuMP.Model: The JuMP optimisation model.
  • pr::AbstractPriorResult: The prior result. The function reads its sigma and its chol.
  • mtx_sqrt: Square-root algorithm of pr.sigma, or nothing for the plain Cholesky factor.

Validation

  • When pr.chol is nothing, pr.sigma has a square root under mtx_sqrt, as matrix_square_root states. Raises a LinearAlgebra.PosDefException.

Returns

  • G::AbstractMatrix: The factor of the prior's covariance matrix.

Related

source
PortfolioOptimisers.chol_sigma_selector — Function
chol_sigma_selector(
    model::Model,
    pr::Union{Nothing, AbstractPriorResult},
    r::Union{DistributionValueatRisk, StandardDeviation, Variance}
) -> Any

Return the factor of the covariance matrix that a risk measure reads.

The measure's own matrix wins over the prior's, and a stated factor wins over one computed here:

  • r.chol, when the measure states it.
  • The transpose of the square root of r.sigma under r.mtx_sqrt, which matrix_square_root takes, when the measure states sigma alone.
  • get_chol_or_sigma_pm, the prior's factor, when the measure states neither.

Arguments

  • model::JuMP.Model: The JuMP optimisation model.
  • pr: Prior result.
  • r::CholRM: The measure, or the algorithm of a measure, that carries the optional sigma and chol, and the square-root algorithm mtx_sqrt.

Returns

  • G::AbstractMatrix: The factor, with $\mathbf{G}^\intercal \mathbf{G} = \mathbf{\Sigma}$.

Related

source
PortfolioOptimisers.set_variance_risk_bounds_and_expression! — Function
set_variance_risk_bounds_and_expression!(
    model::Model,
    opt::Union{AbstractProgrammeAllocationSet, RiskJuMPOptimisationEstimator},
    r_expr_ub::AbstractJuMPScalar,
    ub::Union{Nothing, Number, Frontier, AbstractVector{<:Union{Number, AbstractJuMPScalar}}},
    name::Symbol,
    i,
    r_expr::AbstractJuMPScalar,
    settings::JuMPRiskMeasureSettings;
    ...
)
set_variance_risk_bounds_and_expression!(
    model::Model,
    opt::Union{AbstractProgrammeAllocationSet, RiskJuMPOptimisationEstimator},
    r_expr_ub::AbstractJuMPScalar,
    ub::Union{Nothing, Number, Frontier, AbstractVector{<:Union{Number, AbstractJuMPScalar}}},
    name::Symbol,
    i,
    r_expr::AbstractJuMPScalar,
    settings::JuMPRiskMeasureSettings,
    flag::Bool;
    prefix
)

Bound one expression, and add another to the risk that the objective reads.

The row of set_risk_upper_bound! multiplies the bound by $k$, so it holds under a ratio objective only for an expression of degree one in the weights and $k$. A second moment has degree two. The builder passes the square root, of degree one, as r_expr_ub with its bound converted by variance_risk_bounds_val, and the second moment as r_expr. A builder whose risk has degree one passes one expression twice.

Arguments

  • model::JuMP.Model: The JuMP optimisation model.
  • opt::RiskConstraintOwner: The owner of the risk constraint, a risk-based JuMP optimisation estimator or a programme Allocation Set.
  • r_expr_ub::JuMP.AbstractJuMPScalar: The expression that the bound row acts on.
  • ub: The bound, in the units of r_expr_ub, or nothing.
  • name::Symbol: The Model State name of r_expr_ub. The keys of the bound derive from it.
  • i: The index of the measure. name and i compose the key here, so the bound keys cannot differ from the key that the builder registered r_expr_ub under.
  • r_expr::JuMP.AbstractJuMPScalar: The risk expression that the objective reads.
  • settings::JuMPRiskMeasureSettings: The settings of the measure, which give the weight scale and the flag rke.
  • flag::Bool: true for an upper bound, and false for a lower bound (default: true).

Keyword arguments

  • prefix::Symbol: Model State namespace for name (default: empty, i.e. the bare key).

Returns

  • nothing.

Related

source
PortfolioOptimisers.risk_contribution_constraints — Method
risk_contribution_constraints(r::Variance, opt::NonFRCJuMPOpt, pr::AbstractPriorResult)

The risk-contribution rows of a Variance as the RiskConstraintOwner resolves them. On a JuMP optimiser they are r.rc through linear_constraints over the optimiser's sets and strict, in the element type of the prior's returns. A programme Allocation Set answers its own; see ProgrammeAllocationSet.

Related

source
PortfolioOptimisers.set_risk! — Method
set_risk!(
    model::Model,
    i,
    r::StandardDeviation,
    opt::Union{AbstractProgrammeAllocationSet, RiskJuMPOptimisationEstimator},
    pr::Union{Nothing, AbstractPriorResult},
    args...;
    prefix,
    kwargs...
) -> Tuple{VariableRef, Symbol}

Build the risk expression of a standard deviation or of a variance, and return it with the name or the formulation that its bound reads.

The standard-deviation method bounds the norm of $\mathbf{G} \boldsymbol{w}$ with a second-order cone variable. The variance method chooses the formulation with sdp_variance_flag!, builds the expression with set_variance_risk!, and adds the risk-contribution rows of r.rc with rc_variance_constraints!.

Mathematical definition

\[\begin{align} \sigma(\boldsymbol{w}) &= \lVert \mathbf{G} \boldsymbol{w} \rVert_2 = \sqrt{\boldsymbol{w}^\intercal \mathbf{\Sigma} \boldsymbol{w}}\,. \end{align}\]

Where:

  • $\sigma(\boldsymbol{w})$: Portfolio standard deviation.
  • $\mathbf{G}$: Covariance factor, with $\mathbf{G}^\intercal \mathbf{G} = \mathbf{\Sigma}$. It need not be square, and $\lVert \mathbf{G} \boldsymbol{w} \rVert_{2}^{2} = \boldsymbol{w}^\intercal \mathbf{\Sigma} \boldsymbol{w}$.
  • $\mathbf{\Sigma}$: Covariance matrix of the risk measure, $N \times N$. It is the measure's own matrix when the measure states one, and the prior's otherwise.
  • $\boldsymbol{w}$: Portfolio weights vector $N \times 1$.

JuMP formulation

Variables

  • w: read from the model.
  • sd_risk_: $\sigma$, created by the standard-deviation method.

Constraints

  • csd_risk_soc_: $(s_c \sigma, s_c \mathbf{G} \boldsymbol{w}) \in \mathcal{K}_{2}$, which is $\sigma \geq \lVert \mathbf{G} \boldsymbol{w} \rVert_2$.

Each name carries the index i of the measure, and the namespace prefix.

Where:

  • $\sigma$: Standard-deviation epigraph variable, $\sigma \geq \lVert \mathbf{G} \boldsymbol{w} \rVert_{2}$.
  • $\mathcal{K}_{q} = \{(t, \boldsymbol{x}) : t \geq \lVert \boldsymbol{x} \rVert_{q}\}$: Norm cone of order $q$. $\mathcal{K}_{2}$ is the second-order cone.
  • $s_c$: Constraint scale. It multiplies both sides of a row, so a positive value leaves the feasible set unchanged.

Relaxation

The encoding is not exact: the entries below bound the quantity instead of reproducing it, and the bound is tight only under the condition stated here.

  • sd_risk_ lies at or above $\sigma(\boldsymbol{w})$. It is tight when the objective minimises the risk. A bound on it is exact, because the weights satisfy it when their standard deviation is at most the bound.

Arguments

  • model::JuMP.Model: The JuMP optimisation model.
  • i: Constraint index for unique variable and constraint naming.
  • r: The measure, a StandardDeviation or a Variance.
  • opt::RiskConstraintOwner: The owner of the risk constraint, a risk-based JuMP optimisation estimator or a programme Allocation Set.
  • pr: Prior result.
  • pl: Optional phylogeny constraints. The variance method alone reads it.

Returns

  • The standard-deviation method returns (sd_risk, :sd_risk_), the variable and the bare Model State name that the method registers it under. The caller pairs the name with the same index to compose the key of the bound.
  • The variance method returns (variance_risk, flag), the variance expression and the FrontierBoundEstimator of its formulation: LinearBound for the semidefinite one, and SquareRootBound for the second-order cone one.

Related

source
PortfolioOptimisers.sdp_rc_variance_flag! — Function
sdp_rc_variance_flag!(
    _::Model,
    _::Union{AbstractProgrammeAllocationSet, MeanRisk, NearOptimalCentering, RiskBudgeting},
    _::Nothing
) -> Bool

Return whether the risk-contribution rows of a variance need the semidefinite formulation.

The rows state shares of the lifted variance, so any row needs it. The method on nothing returns false, and the method on a LinearConstraint returns true.

Arguments

  • model::JuMP.Model: The JuMP optimisation model.
  • opt::RiskBoundOwner: The owner of the constraint.
  • rc: The resolved rows, nothing or a LinearConstraint.

Returns

  • flag::Bool: Whether the rows need the semidefinite formulation.

Related

source
PortfolioOptimisers.sdp_variance_flag! — Function
sdp_variance_flag!(
    model::Model,
    rc_flag::Bool,
    pl::Union{Nothing, AbstractPhylogenyConstraintResult, AbstractVector{<:AbstractPhylogenyConstraintResult}};
    prefix
) -> Union{LinearBound, SquareRootBound}

Return the FrontierBoundEstimator that names the formulation of a variance.

The function returns LinearBound, the semidefinite formulation, when rc_flag is true, when the namespace that owns the weights carries the rc_variance mark or the sdp_phylogeny mark, or when pl holds a SemiDefinitePhylogeny. It returns SquareRootBound, the second-order cone formulation, otherwise. rc_variance_constraints! sets the rc_variance mark, so a variance built after one with risk-contribution rows on the same weights also takes the semidefinite formulation. A variance built before it keeps the second-order cone, so the formulation of a variance without rows depends on its place in the vector of measures.

mark_sdp_phylogeny! sets the sdp_phylogeny mark in phase 1 of each block that holds a SemiDefinitePhylogeny, before every variance of the model. So a variance reads the semidefinite phylogeny of every block on its weights. pl is the phylogeny of the block of the builder. It also reaches a namespace that owns its own weights, such as the inner build of an IndependentVariableTracking, which no mark of the head reaches.

Arguments

  • model::JuMP.Model: The JuMP optimisation model.
  • rc_flag::Bool: Whether the measure's own rows need the semidefinite formulation.
  • pl: Optional phylogeny constraint result or results of the block of the builder.

Keyword arguments

  • prefix::Symbol: Model State namespace of the build. The mark is read on its owner, weights_prefix.

Returns

  • bound::FrontierBoundEstimator: LinearBound for the semidefinite formulation, and SquareRootBound for the second-order cone formulation.

Related

source
PortfolioOptimisers.set_variance_risk! — Function
set_variance_risk!(
    model::Model,
    i,
    r::Variance{<:Any, <:Any, <:Any, <:Any, <:SquaredSOCRiskExpr},
    pr::Union{Nothing, AbstractPriorResult},
    ::SquareRootBound;
    prefix
) -> QuadExpr

Build the variance expression of the formulation that flag or r.alg selects.

The methods on LinearBound build the semidefinite formulation, and the next docstring states them. The methods on SquareRootBound dispatch on r.alg. Both second-order cone methods build the deviation $\sigma$ with its cone, because the bound acts on $\sigma$ in the units of a standard deviation. SquaredSOCRiskExpr states the variance as $\sigma^2$, and QuadRiskExpr states it as the quadratic form.

JuMP formulation

Variables

  • w: read from the model.
  • dev_: $\sigma$, created by both second-order cone methods.

Expressions

Constraints

  • cdev_soc_: $(s_c \sigma, s_c \mathbf{G} \boldsymbol{w}) \in \mathcal{K}_{2}$, which is $\sigma \geq \lVert \mathbf{G} \boldsymbol{w} \rVert_2$.

Each name carries the index i of the measure, and the namespace prefix.

Where:

  • $\sigma$: Standard-deviation epigraph variable, $\sigma \geq \lVert \mathbf{G} \boldsymbol{w} \rVert_{2}$.
  • $\mathbf{G}$: Covariance factor, with $\mathbf{G}^\intercal \mathbf{G} = \mathbf{\Sigma}$. It need not be square, and $\lVert \mathbf{G} \boldsymbol{w} \rVert_{2}^{2} = \boldsymbol{w}^\intercal \mathbf{\Sigma} \boldsymbol{w}$.
  • $\mathbf{\Sigma}$: Covariance matrix of the risk measure, $N \times N$. It is the measure's own matrix when the measure states one, and the prior's otherwise.
  • $\boldsymbol{w}$: Portfolio weights vector $N \times 1$.
  • $\mathcal{K}_{q} = \{(t, \boldsymbol{x}) : t \geq \lVert \boldsymbol{x} \rVert_{q}\}$: Norm cone of order $q$. $\mathcal{K}_{2}$ is the second-order cone.
  • $s_c$: Constraint scale. It multiplies both sides of a row, so a positive value leaves the feasible set unchanged.

Relaxation

The encoding is not exact: the entries below bound the quantity instead of reproducing it, and the bound is tight only under the condition stated here.

  • dev_ lies at or above $\lVert \mathbf{G} \boldsymbol{w} \rVert_2$, so under SquaredSOCRiskExpr variance_risk_ lies at or above the variance. Both are tight when the objective minimises the risk.
  • Under QuadRiskExpr variance_risk_ is exact, and dev_ serves the bound alone.
  • A bound on dev_ is exact under both, because the weights satisfy it when their variance is at most the square of the bound.

Arguments

  • model::JuMP.Model: The JuMP optimisation model.
  • i: Constraint index for unique variable and constraint naming.
  • r::Variance: The measure.
  • pr::AbstractPriorResult: Prior result containing the covariance matrix sigma.
  • flag:
    • ::LinearBound: The semidefinite formulation.
    • ::SquareRootBound: The second-order cone formulation of r.alg.

Keyword arguments

  • prefix::Symbol: Model State namespace of the build (default: empty, i.e. the bare key).

Returns

  • variance_risk: The variance expression.

Related

source
set_variance_risk!(
    model::Model,
    i,
    r::Variance,
    pr::Union{Nothing, AbstractPriorResult},
    ::LinearBound,
    ::LinearRatio;
    prefix
) -> Any

Build the semidefinite variance expression, the trace of the covariance matrix times the lifted weight matrix.

The trace on the lift of set_sdp_constraints! has degree one in the weights and $k$, where the second-order cone expressions have degree two. So when sdp_objective_lift_flag is true, under MaximumRatio with SquareRootRatio, the objective term reads the lift with a constant corner of set_sdp_objective_lift!, which has degree two, and the model maximises the Sharpe ratio. The bound then reads the trace on the first lift, and the method builds that trace only when settings.ub holds a bound. Otherwise the term and the bound read one trace. The slot ratio_alg defaults to r.ratio_alg, and the method dispatches on it: under LinearRatio the term never reads the lift with a constant corner, so that method builds the one trace. The # Mathematical definition of MaximumRatio states the rule. The bound acts on the trace in the units of a variance.

JuMP formulation

Variables

  • W: read, the lifted matrix that set_sdp_constraints! builds once for the owner of the weights.
  • lift_W: read under the lift of the objective, $\mathbf{W}_c$, which set_sdp_objective_lift! builds once for the owner of the weights.

Expressions

  • sigma_W_: $\mathbf{\Sigma} \mathbf{W}$, registered without the lift of the objective.
  • variance_risk_: $\mathrm{Tr}(\mathbf{\Sigma} \mathbf{W})$, registered without the lift of the objective, and with it when settings.ub holds a bound.
  • lift_sigma_W_: $\mathbf{\Sigma} \mathbf{W}_c$, registered under the lift of the objective.
  • lift_variance_risk_: $\mathrm{Tr}(\mathbf{\Sigma} \mathbf{W}_c)$, the objective term under the lift of the objective.

Each name carries the index i of the measure, and the namespace prefix.

Where:

  • $\mathbf{W}$: Lifted weight matrix, symmetric $N \times N$. set_sdp_constraints! bounds it by $\mathbf{W} \succeq \boldsymbol{w} \boldsymbol{w}^\intercal / k$.
  • $\mathbf{\Sigma}$: Covariance matrix of the risk measure, $N \times N$. It is the measure's own matrix when the measure states one, and the prior's otherwise.
  • $k$: Variable that scales the budget in the homogenised problem.

Relaxation

The encoding is not exact: the entries below bound the quantity instead of reproducing it, and the bound is tight only under the condition stated here.

  • variance_risk_ lies at or above $\boldsymbol{w}^\intercal \mathbf{\Sigma} \boldsymbol{w} / k$, because $\mathbf{W} \succeq \boldsymbol{w} \boldsymbol{w}^\intercal / k$ and the covariance matrix is positive semidefinite. It is tight at $\mathbf{W} = \boldsymbol{w} \boldsymbol{w}^\intercal / k$, which the objective reaches when it minimises the risk and no other row acts on $\mathbf{W}$.
  • A bound on variance_risk_ alone is exact, because the weights satisfy it when their variance is at most the bound. Risk-contribution rows on $\mathbf{W}$ make the bound and the rows one relaxation, which rc_variance_constraints! states.
  • lift_variance_risk_ lies at or above $\boldsymbol{w}^\intercal \mathbf{\Sigma} \boldsymbol{w} / c$, because $\mathbf{W}_c \succeq \boldsymbol{w} \boldsymbol{w}^\intercal / c$. It is tight at rank one, which the objective reaches when it minimises the risk and no other row acts on $\mathbf{W}_c$. The rows of rc then read lift_sigma_W_, so they act on the matrix that the objective holds down.

Arguments

  • model::JuMP.Model: The JuMP optimisation model.
  • i: Constraint index for unique variable and constraint naming.
  • r::Variance: The measure.
  • pr::AbstractPriorResult: Prior result containing the covariance matrix sigma.
  • ::LinearBound: The semidefinite formulation.
  • ratio_alg: The RatioFormulation of the measure. It defaults to r.ratio_alg.

Keyword arguments

  • prefix::Symbol: Model State namespace of the build (default: empty, i.e. the bare key).

Returns

  • variance_risk: The variance expression.

Related

source
PortfolioOptimisers.variance_risk_bounds_expr — Function
variance_risk_bounds_expr(
    model::Model,
    i,
    ::LinearBound;
    prefix
) -> Tuple{Any, Symbol}

Return the expression that the bound of a variance acts on, and its bare Model State name.

The method on LinearBound returns the trace variance_risk_ of the semidefinite formulation, and the method on SquareRootBound returns the deviation dev_ of the second-order cone formulation. Both have degree one in the weights and $k$, so the row of set_risk_upper_bound! holds under a ratio objective.

Arguments

  • model::JuMP.Model: The JuMP optimisation model.
  • i: Constraint index for unique variable and constraint naming.
  • flag:
    • ::LinearBound: The semidefinite formulation.
    • ::SquareRootBound: The second-order cone formulation.

Keyword arguments

  • prefix::Symbol: Model State namespace of the build (default: empty, i.e. the bare key).

Returns

  • (expr, name): The expression, and the bare name that its builder registered it under.

Related

source
PortfolioOptimisers.rc_variance_constraints! — Function
rc_variance_constraints!(
    model::Model,
    i,
    rc::LinearConstraint,
    variance_risk::AbstractJuMPScalar;
    prefix
)

Add linear risk-contribution rows on the variance decomposition to model.

The method on rc = nothing does nothing, and it runs when the measure has no rows. Any other type or arity is a MethodError. The method on a LinearConstraint reads the diagonal of sigma_W_, adds the rows, and sets the rc_variance mark on the namespace that owns the weights, which sdp_variance_flag! reads. When the builder stated the objective term on the lift of set_sdp_objective_lift!, the method reads lift_sigma_W_ in place of sigma_W_, and variance_risk is the term on that lift. The rows are homogeneous in the matrix, so they hold on either lift, and they bind only on the matrix that the objective holds down.

JuMP formulation

Constraints

  • rc_variance_ineq_: $s_c \left(\mathbf{A} \, \mathrm{diag}(\mathbf{S}) - \boldsymbol{b} \, V\right) \leq 0$, registered when rc holds inequality rows.
  • rc_variance_eq_: $s_c \left(\mathbf{C} \, \mathrm{diag}(\mathbf{S}) - \boldsymbol{d} \, V\right) = 0$, registered when rc holds equality rows.

Where:

  • $\mathbf{S}$: The sigma_W_ expression, read from the model. It is $\mathbf{\Sigma} \mathbf{W}$ over the asset weights. Over the decision vector $\boldsymbol{z}$ of FactorRiskContribution it is $\mathbf{B}_1^\intercal \mathbf{\Sigma} \mathbf{P} \mathbf{W}_{z}$, the $N_f$ rows of the factors, with $\mathbf{P}$ the basis that maps $\boldsymbol{z}$ to the asset weights.
  • $\mathbf{W}$, $\mathbf{W}_{z}$: The symmetric matrix variables that set_sdp_constraints! and set_sdp_frc_constraints! bound by $\mathbf{W} \succeq \boldsymbol{w} \boldsymbol{w}^\intercal / k$ and $\mathbf{W}_{z} \succeq \boldsymbol{z} \boldsymbol{z}^\intercal / k$.
  • $\mathbf{A}$, $\boldsymbol{b}$: The inequality rows of rc and their bounds.
  • $\mathbf{C}$, $\boldsymbol{d}$: The equality rows of rc and their targets.
  • $V$: The variance_risk argument. It is $\mathrm{Tr}(\mathbf{S})$ over the asset weights, and $\mathrm{Tr}(\mathbf{P}^\intercal \mathbf{\Sigma} \mathbf{P} \mathbf{W}_{z})$ over $\boldsymbol{z}$.
  • $\boldsymbol{w}$: Portfolio weights vector $N \times 1$.
  • $\boldsymbol{z}$: The decision vector of FactorRiskContribution, the factor weights, followed by the off-factor weights when flag = true. It takes the place of $\boldsymbol{w}$ in the lift.
  • $k$: Variable that scales the budget in the homogenised problem.
  • $s_c$: Constraint scale. It multiplies both sides of a row, so a positive value leaves the feasible set unchanged.

Relaxation

The encoding is not exact: the entries below bound the quantity instead of reproducing it, and the bound is tight only under the condition stated here.

  • The variance $V$ in variance_risk_ lies above its value at $\mathbf{W} = \boldsymbol{w} \boldsymbol{w}^\intercal / k$, because $\mathbf{W} \succeq \boldsymbol{w} \boldsymbol{w}^\intercal / k$ and the covariance matrix is positive semidefinite.
  • The rows bound the shares of $\mathrm{diag}(\mathbf{S})$ in sigma_W_, not the risk contributions of the returned weights. Those can lie on either side of a bound.
  • Both are tight when $\mathbf{W} = \boldsymbol{w} \boldsymbol{w}^\intercal / k$, a matrix of rank one. No term of the model forces this, so a solve that reports success can return weights whose shares miss the rows. This is formulations 9, 10 and 16 of [190], which name the rank-one relaxation as their approximation.

Arguments

  • model::JuMP.Model: The JuMP optimisation model.
  • i: Constraint index for unique variable and constraint naming.
  • rc::LinearConstraint: The resolved risk-contribution rows, or nothing for none.
  • variance_risk::JuMP.AbstractJuMPScalar: The variance expression $V$.

Keyword arguments

  • prefix::Symbol: Model State namespace of the build (default: empty, i.e. the bare key).

Returns

  • nothing.

Related

References

  • [190] D. Cajas. A Semidefinite Programming Approach to Risk Parity Portfolio Optimization. Available at SSRN 5097869 (2025). Formulations 9, 10 and 16.
source
PortfolioOptimisers.set_ucs_variance_risk! — Function
set_ucs_variance_risk!(
    model::Model,
    i,
    ucs::BoxUncertaintySet,
    args...;
    prefix,
    W
) -> Tuple{Any, Symbol}

Build the worst-case variance of an uncertainty set over the covariance matrix.

The box, the ellipsoid and the norm ball bound the covariance matrix, so each lifts the weights into $\mathbf{W}$ with set_sdp_constraints! and states the dual of its worst case over $\mathbf{W}$. A caller can pass another lifted matrix in the keyword W. set_risk_constraints! passes $\mathbf{W}_c$ of set_sdp_objective_lift! for the objective term under MaximumRatio, with the namespace lift_ after prefix, so the dual variables of that term have names of their own. The compact set bounds a quadratic form in the weights, so it lifts nothing and leaves the programme a second-order cone programme. It takes the square root of its centre under the mtx_sqrt of the UncertaintySetVariance, so under the default it accepts a singular centre, as Variance does.

Equation 7 of [167] first states the dual of the box. Its constraint $\mathbf{Z} + \mathbf{\Lambda}_u - \mathbf{\Lambda}_l = -\boldsymbol{w} \boldsymbol{w}^\intercal$ has the wrong sign: the dual of the worst case needs $\mathbf{\Lambda}_u - \mathbf{\Lambda}_l \succeq \boldsymbol{w} \boldsymbol{w}^\intercal$, as Equation 6.11 of [53] states. Equation 6.15 of [53] first states the dual of the ellipsoid. That dual equals the worst case when $\mathbf{K} \mathbf{\Omega} \mathbf{K} = \mathbf{\Omega}$ for the commutation_matrix $\mathbf{K}$, so that the transpose of each matrix of the set is in the set. For another $\mathbf{\Omega}$ it lies at or above the worst case. Equations 11.21 and 11.27 of [12] add the homogenisation $k$ that MaximumRatio needs. The worst case of the compact set is this library's own construction, as OrthogonalUncertaintySet states.

Mathematical definition

\[\begin{align} R_{\mathrm{box}} &= \underset{\mathbf{A}_u,\, \mathbf{A}_l \geq 0,\ \mathbf{A}_u - \mathbf{A}_l = \mathbf{W}}{\min} \langle \mathbf{\Sigma}_u, \mathbf{A}_u \rangle - \langle \mathbf{\Sigma}_l, \mathbf{A}_l \rangle\,, \\ R_{\mathrm{ell}} &= \underset{\mathbf{E} \succeq 0}{\min} \langle \hat{\mathbf{\Sigma}}, \mathbf{W} + \mathbf{E} \rangle + k_{e} \lVert \mathbf{G}_{\Omega} \, \mathrm{vec}(\mathbf{W} + \mathbf{E}) \rVert_{2}\,, \\ R_{\mathrm{nb}} &= \underset{\mathbf{E} \succeq 0}{\min} \langle \hat{\mathbf{\Sigma}}, \mathbf{W} + \mathbf{E} \rangle + \kappa_{b} \lVert \mathbf{L}^\intercal \mathrm{vec}(\mathbf{W} + \mathbf{E}) \rVert_{p^{*}}\,, \\ R_{\mathrm{cpt}} &= \lVert \mathbf{G} \boldsymbol{w} \rVert_{2}^{2} + \kappa \underset{\boldsymbol{z}}{\min} \left( \lVert \mathbf{C} \boldsymbol{w} - \mathbf{Q} \boldsymbol{z} \rVert_{2}^{2} + \lVert \mathbf{R} \boldsymbol{z} \rVert_{2}^{2} \right)\,. \end{align}\]

Where:

  • $R_{\mathrm{box}}$, $R_{\mathrm{ell}}$, $R_{\mathrm{nb}}$, $R_{\mathrm{cpt}}$: Worst-case variance of the box, the ellipsoid, the norm ball and the compact set. The first three state the worst case over $\mathbf{W}$. The ellipsoid and the norm ball give the worst case of $\boldsymbol{w}$ at $\mathbf{W} = \boldsymbol{w} \boldsymbol{w}^\intercal / k$. At that matrix the box gives the worst case over a box that drops the condition $\mathbf{\Sigma} \succeq 0$, which can be larger. The part of $\mathbf{W}$ above $\boldsymbol{w} \boldsymbol{w}^\intercal / k$ takes the place of the dual matrix of that condition, so the minimum over $\mathbf{W}$ is the worst case with it.
  • $\mathbf{\Sigma}_l$, $\mathbf{\Sigma}_u$: Lower and upper bounds of the box, lb and ub.
  • $\mathbf{A}_l$, $\mathbf{A}_u$: Dual matrices of the two sides of the box.
  • $\hat{\mathbf{\Sigma}}$: Centre of the set, the set's val when it states one and sigma otherwise.
  • $\mathbf{E}$: Dual matrix of the condition that the worst covariance is positive semidefinite.
  • $k_{e}$, $\mathbf{G}_{\Omega}$: Radius of the ellipsoid, k, and the transpose of the square root of its matrix $\mathbf{\Omega}$, sigma, that matrix_square_root takes under mtx_sqrt, so $\mathbf{G}_{\Omega}^\intercal \mathbf{G}_{\Omega} = \mathbf{\Omega}$.
  • $\kappa_{b}$, $\mathbf{L}$, $p^{*}$: Radius of the norm ball, its map, and the dual order of its norm.
  • $\mathbf{C}$, $\mathbf{Q}$, $\mathbf{R}$, $\boldsymbol{z}$: Diagonal metric of the compact set, its basis, the factor of the rows a view dropped from the basis, and the free coefficients of the basis. A fitted set has no row in $\mathbf{R}$.
  • $\langle \mathbf{X}, \mathbf{Y} \rangle = \mathrm{Tr}(\mathbf{X}^\intercal \mathbf{Y})$: Inner product of two matrices.
  • $\kappa \geq 0$: Radius of the compact covariance set, the multiplier of its penalty.
  • $\mathbf{W}$: Lifted weight matrix, symmetric $N \times N$. set_sdp_constraints! bounds it by $\mathbf{W} \succeq \boldsymbol{w} \boldsymbol{w}^\intercal / k$.
  • $\mathbf{G}$: Covariance factor, with $\mathbf{G}^\intercal \mathbf{G} = \mathbf{\Sigma}$. It need not be square, and $\lVert \mathbf{G} \boldsymbol{w} \rVert_{2}^{2} = \boldsymbol{w}^\intercal \mathbf{\Sigma} \boldsymbol{w}$.
  • $\boldsymbol{w}$: Portfolio weights vector $N \times 1$.

JuMP formulation

Variables

  • W: read by the box, the ellipsoid and the norm ball. w: read by the compact set.
  • Au, Al: created by the box, $\mathbf{A}_u$ and $\mathbf{A}_l$, symmetric with non-negative entries.
  • E: created by the ellipsoid or the norm ball, $\mathbf{E}$, symmetric.
  • t_eucs: created by the ellipsoid, $t_e$.
  • dev_cucs, t_cucs: created by the compact set, $d$ and $t$.
  • z_cucs: created by the compact set when $\mathbf{Q}$ has a column, $\boldsymbol{z}$.

Expressions

  • bucs_variance_risk_: $\langle \mathbf{\Sigma}_u, \mathbf{A}_u \rangle - \langle \mathbf{\Sigma}_l, \mathbf{A}_l \rangle$.
  • WpE: $\mathbf{W} + \mathbf{E}$.
  • x_eucs: $\mathbf{G}_{\Omega} \, \mathrm{vec}(\mathbf{W} + \mathbf{E})$.
  • eucs_variance_risk_: $\langle \hat{\mathbf{\Sigma}}, \mathbf{W} + \mathbf{E} \rangle + k_{e} t_e$.
  • x_cucs: $[\mathbf{C} \boldsymbol{w} - \mathbf{Q} \boldsymbol{z}; \mathbf{R} \boldsymbol{z}]$, or $\mathbf{C} \boldsymbol{w}$ when $\mathbf{Q}$ has no column. The second block has one entry per row of $\mathbf{R}$, so a fitted set states $\mathbf{C} \boldsymbol{w} - \mathbf{Q} \boldsymbol{z}$ alone.
  • cucs_variance_risk_: $d^{2} + \kappa t^{2}$.
  • x_nbucs_: $\mathbf{L}^\intercal \mathrm{vec}(\mathbf{W} + \mathbf{E})$, registered when $\mathbf{L}$ has a column. norm_ball_dual_norm_epigraph! bounds its norm by $t_b$.
  • nbucs_variance_risk_: $\langle \hat{\mathbf{\Sigma}}, \mathbf{W} + \mathbf{E} \rangle + \kappa_{b} t_b$, or the first term alone when $\mathbf{L}$ has no column.

Constraints

  • cbucs_variance: $s_c (\mathbf{A}_u - \mathbf{A}_l - \mathbf{W}) = 0$.
  • ceucs_variance: $s_c \mathbf{E} \in \mathcal{S}_{+}^{N}$, registered by the ellipsoid or the norm ball.
  • ge_soc: $(s_c t_e, s_c \boldsymbol{x}_e) \in \mathcal{K}_{2}$, with $\boldsymbol{x}_e$ the x_eucs expression.
  • cdev_cucs_soc: $(s_c d, s_c \mathbf{G} \boldsymbol{w}) \in \mathcal{K}_{2}$.
  • gc_soc: $(s_c t, s_c \boldsymbol{x}_c) \in \mathcal{K}_{2}$, with $\boldsymbol{x}_c$ the x_cucs expression.

Au, Al, E, WpE, cbucs_variance and ceucs_variance are built once for each namespace, and carry the namespace prefix alone. Every other name also carries the index i of the measure.

Where:

  • $t_e$, $t_b$: Epigraph variables of the ellipsoidal and the norm-ball penalty.
  • $d$, $t$: Epigraph variables of the two norms of the compact set.
  • $\mathcal{S}_{+}^{N}$: The cone of positive semidefinite $N \times N$ matrices.
  • $\mathcal{K}_{q} = \{(t, \boldsymbol{x}) : t \geq \lVert \boldsymbol{x} \rVert_{q}\}$: Norm cone of order $q$. $\mathcal{K}_{2}$ is the second-order cone.
  • $s_c$: Constraint scale. It multiplies both sides of a row, so a positive value leaves the feasible set unchanged.

Relaxation

The encoding is not exact: the entries below bound the quantity instead of reproducing it, and the bound is tight only under the condition stated here.

  • bucs_variance_risk_, eucs_variance_risk_ and nbucs_variance_risk_ lie at or above their worst case at $\mathbf{W} = \boldsymbol{w} \boldsymbol{w}^\intercal / k$, and the epigraph variables at or above their norms. They are tight when the objective minimises the risk.
  • Two sets of one kind on the same weights share Au and Al, or E. The box shares them at no cost. For bounds with $\mathbf{\Sigma}_u \geq \mathbf{\Sigma}_l$, the best $\mathbf{A}_l$ is the negative part of $\mathbf{W}$ for every box. Each ellipsoid or norm ball lies at or above its own worst case, tight when one $\mathbf{E}$ serves them all.
  • dev_cucs and t_cucs lie at or above their norms, so cucs_variance_risk_ lies at or above the compact worst case. It is tight when the objective minimises the risk.

Arguments

  • model::JuMP.Model: The JuMP optimisation model.
  • i: Constraint index for unique variable and constraint naming.
  • ucs: The uncertainty set, a BoxUncertaintySet, an EllipsoidalUncertaintySet, a CompactCovarianceUncertaintySet or a covariance NormBallUncertaintySet.
  • sigma::MatNum: The fallback centre. The set's own val wins over it, and the box ignores both, because it names no centre.
  • mtx_sqrt: Square-root algorithm of the matrix of an ellipsoid and of the centre of a compact set, the mtx_sqrt of the UncertaintySetVariance, or nothing for the plain Cholesky factor. The box and the norm ball ignore it.

Keyword arguments

  • prefix::Symbol: Model State namespace of the build (default: empty, i.e. the bare key).
  • W::AbstractMatrix: The lifted matrix that the box, the ellipsoid and the norm ball read (default: the matrix of set_sdp_constraints! under prefix). The compact set has no such keyword.

Returns

  • (ucs_variance_risk, name): The worst-case variance, and the bare Model State name that the method registers it under.

Related

References

  • [167] M. Sousa Lobo and S. Boyd. The worst-case risk of a portfolio. Technical report, Stanford University (2000). Sections 4 and 5.2.6, Equation 7.
  • [53] Y. Feng and D. P. Palomar. A signal processing perspective of financial engineering. Foundations and Trends in Signal Processing 9, 1–231 (2016). Section 6.1.3, Equations 6.10 to 6.15.
  • [171] D. Bertsimas, D. B. Brown and C. Caramanis. Theory and Applications of Robust Optimization. SIAM Review 53, 464–501 (2011). Section 2.2, Theorem 2. The original source of this formulation was not found. The formulation follows this work and is not checked against the original.
  • [12] D. Cajas. Advanced Portfolio Optimization: A Cutting-edge Quantitative Approach (Springer Nature Switzerland, 2025). Sections 11.3.1 and 11.3.2, Equations 11.21 and 11.27.
source
PortfolioOptimisers.sdp_lifted_set — Function
sdp_lifted_set(ucs)

Return true when set_ucs_variance_risk! states the worst case of the set ucs on a lifted weight matrix.

The box, the ellipsoid and the covariance norm ball bound the covariance matrix, so their worst case is linear in the lifted matrix and its degree is the degree of the lift. set_risk_constraints! then states the objective term on the lift of set_sdp_objective_lift! when the measure asks for it. The compact set states its worst case on the weights with degree two, and every other set takes the fall-through method.

Returns

  • flag::Bool.

Related

source
PortfolioOptimisers.ucs_variance_risk_bounds! — Function
ucs_variance_risk_bounds!(
    ::Model,
    ,
    ,
    r_expr::AbstractJuMPScalar,
    name::Symbol,
    ub;
    prefix
) -> Tuple{VariableRef, Any, Symbol}

Return the expression that the bound of an uncertainty-set variance acts on, the bound in its units, and the bare Model State name of the expression.

The row of set_risk_upper_bound! multiplies the bound by $k$, so it needs an expression of degree one in the weights and $k$. The box, the ellipsoid and the norm ball state their worst case over the lifted matrix of set_sdp_constraints!, which has degree one, so the fall-through method returns the risk expression, the bound and the name unchanged. The compact worst case $d^2 + \kappa t^2$ has degree two. Its method adds the square root as a second-order cone variable, and converts the bound with variance_risk_bounds_val. A compact set without a bound takes the fall-through method and adds nothing.

JuMP formulation

Variables

  • dev_cucs, t_cucs: read, $d$ and $t$.
  • sd_cucs_: $s$, created by the compact method.

Constraints

  • csd_cucs_soc_: $(s_c s, s_c d, s_c \sqrt{\kappa} t) \in \mathcal{K}_{2}$, which is $s \geq \sqrt{d^{2} + \kappa t^{2}}$.

Each name carries the index i of the measure, and the namespace prefix.

Where:

  • $d$, $t$: Epigraph variables of the two norms of the compact set, which set_ucs_variance_risk! creates.
  • $\kappa \geq 0$: Radius of the compact covariance set, the multiplier of its penalty.
  • $\mathcal{K}_{q} = \{(t, \boldsymbol{x}) : t \geq \lVert \boldsymbol{x} \rVert_{q}\}$: Norm cone of order $q$. $\mathcal{K}_{2}$ is the second-order cone.
  • $s_c$: Constraint scale. It multiplies both sides of a row, so a positive value leaves the feasible set unchanged.

Relaxation

The encoding is not exact: the entries below bound the quantity instead of reproducing it, and the bound is tight only under the condition stated here.

  • sd_cucs_ lies at or above the square root of cucs_variance_risk_. The bound on it is exact. The weights satisfy it when their compact worst-case variance is at most the bound, because $d$, $t$ and $\boldsymbol{z}$ can take their smallest values.

Arguments

  • model::JuMP.Model: The JuMP optimisation model.
  • i: Constraint index for unique variable and constraint naming.
  • ucs: The uncertainty set that set_ucs_variance_risk! built.
  • r_expr::JuMP.AbstractJuMPScalar: The worst-case variance.
  • name::Symbol: The bare Model State name of r_expr.
  • ub: The bound, in the units of a variance, or nothing.

Keyword arguments

  • prefix::Symbol: Model State namespace of the build (default: empty, i.e. the bare key).

Returns

  • (expr, ub, name): The expression that the bound acts on, the bound in its units, and the bare name of the expression.

Related

source

References

[12]
D. Cajas. Advanced Portfolio Optimization: A Cutting-edge Quantitative Approach (Springer Nature Switzerland, 2025).
[53]
Y. Feng and D. P. Palomar. A signal processing perspective of financial engineering. Foundations and Trends in Signal Processing 9, 1–231 (2016).
[167]
M. Sousa Lobo and S. Boyd. The Worst-Case Risk of a Portfolio (Stanford University, 2000).
[171]
D. Bertsimas, D. B. Brown and C. Caramanis. Theory and Applications of Robust Optimization. SIAM Review 53, 464–501 (2011).
[190]
D. Cajas. A Semidefinite Programming Approach to Risk Parity Portfolio Optimization. Available at SSRN 5097869 (2025).