Variance

PortfolioOptimisers.QuadRiskExpr — Type
struct QuadRiskExpr <: VarianceFormulation

Encodes the second moment as an explicit quadratic form in the risk expression.

The risk expression reads no auxiliary variable. It takes two shapes. A risk measure that holds a co-moment matrix uses the first, and a risk measure that builds a deviation vector uses the second.

Mathematical definition

\[\begin{align} R(\boldsymbol{w}) &= \boldsymbol{w}^\intercal \mathbf{\Sigma} \boldsymbol{w}\,,\\ R(\boldsymbol{w}) &= c \, \boldsymbol{d}^\intercal \boldsymbol{d}\,. \end{align}\]

Where:

  • $R(\boldsymbol{w})$: Portfolio risk.
  • $\boldsymbol{w}$: Portfolio weights vector $N \times 1$.
  • $\mathbf{\Sigma}$: N × N co-moment matrix.
  • $\boldsymbol{d}$: Deviation vector $T \times 1$ that the formulation squares. The risk measure supplies it.
  • $c$: Correction factor that the risk measure supplies. It is $1$ when the co-moment matrix already carries it.

Related

source
PortfolioOptimisers.SquaredSOCRiskExpr — Type
struct SquaredSOCRiskExpr <: VarianceFormulation

Encodes the second moment as the square of a second-order cone variable.

The cone bounds the norm of the deviation vector, and the risk expression squares that variable, so the encoding reports the second moment itself.

Mathematical definition

\[\begin{align} R(\boldsymbol{w}) &= c \, t^{2}\,,\\ \text{s.t.} \quad & \left\lVert \boldsymbol{d} \right\rVert_{2} \leq t\,. \end{align}\]

Where:

  • $R(\boldsymbol{w})$: Portfolio risk.
  • $\boldsymbol{d}$: Deviation vector $T \times 1$ that the formulation squares. The risk measure supplies it.
  • $c$: Correction factor that the risk measure supplies. It is $1$ when the co-moment matrix already carries it.
  • $t$: Auxiliary model variable that the cone bounds.
  • $\lVert \cdot \rVert_{2}$: L2 norm. The model states it with a JuMP.SecondOrderCone.

Related

source
PortfolioOptimisers.RSOCRiskExpr — Type
struct RSOCRiskExpr <: SecondMomentFormulation

Encodes the second moment as a variable that a rotated second-order cone bounds.

The cone holds the square, so the risk expression is linear in the auxiliary variable. The row is [t; 1/2; d] in JuMP.RotatedSecondOrderCone(). That cone states $2 t u \geq \lVert \boldsymbol{d} \rVert_{2}^{2}$, and the second entry fixes $u = 1/2$, so the row states $t \geq \lVert \boldsymbol{d} \rVert_{2}^{2}$. The encoding reports the second moment itself.

Mathematical definition

\[\begin{align} R(\boldsymbol{w}) &= c \, t\,,\\ \text{s.t.} \quad & \left\lVert \boldsymbol{d} \right\rVert_{2}^{2} \leq t\,. \end{align}\]

Where:

  • $R(\boldsymbol{w})$: Portfolio risk.
  • $\boldsymbol{d}$: Deviation vector $T \times 1$ that the formulation squares. The risk measure supplies it.
  • $c$: Correction factor that the risk measure supplies. It is $1$ when the co-moment matrix already carries it.
  • $t$: Auxiliary model variable that the cone bounds.
  • $\lVert \cdot \rVert_{2}$: L2 norm. The model states its square with a JuMP.RotatedSecondOrderCone.

Related

source
PortfolioOptimisers.SOCRiskExpr — Type
struct SOCRiskExpr <: SecondMomentFormulation

Encodes the square root of the second moment as a second-order cone variable.

This is the only one of the four encodings that reports a root. A risk measure that takes it reports a standard deviation where the other three report a variance, in the model and in the functor alike. The measure reads a bound in settings.ub in the same units.

Mathematical definition

\[\begin{align} R(\boldsymbol{w}) &= \sqrt{c} \, t\,,\\ \text{s.t.} \quad & \left\lVert \boldsymbol{d} \right\rVert_{2} \leq t\,. \end{align}\]

Where:

  • $R(\boldsymbol{w})$: Portfolio risk.
  • $\boldsymbol{d}$: Deviation vector $T \times 1$ that the formulation squares. The risk measure supplies it.
  • $c$: Correction factor that the risk measure supplies. It is $1$ when the co-moment matrix already carries it.
  • $t$: Auxiliary model variable that the cone bounds.
  • $\lVert \cdot \rVert_{2}$: L2 norm. The model states it with a JuMP.SecondOrderCone.

Related

source
PortfolioOptimisers.RatioFormulation — Type
abstract type RatioFormulation <: AbstractAlgorithm

Abstract supertype for the ratio that MaximumRatio maximises over a variance that the model states on a lifted weight matrix.

The type names the power of the risk in the denominator of the ratio, as SquareRootBound and LinearBound name the power of a bound. The variances that it acts on are the semidefinite Variance and the box, the ellipsoid and the norm ball of UncertaintySetVariance. Their objective term reads the corner of the bordered matrix of a lift, and the corner sets the degree of the term in the homogenised weights and $k$, so it sets the ratio. The field ratio_alg acts only on a term of the objective under MaximumRatio. A bound, every other objective, and a formulation that lifts nothing ignore it.

All concrete types that select the ratio of a lifted variance should subtype RatioFormulation.

Interfaces

In order to implement a new concrete type that works seamlessly with the library, subtype RatioFormulation and implement the following method. The root has no method, so a member without one fails with a MethodError when the model asks it for the flag.

sdp_objective_lift_flag

Arguments

  • model: The JuMP model of the optimisation.
  • ratio_alg: The concrete subtype instance.
  • settings: The settings of the measure.

Returns

  • flag::Bool.

Related

source
PortfolioOptimisers.SquareRootRatio — Type
struct SquareRootRatio <: RatioFormulation

Makes MaximumRatio divide the excess return by the square root of a lifted variance.

It is the default. For a plain variance the ratio is the Sharpe ratio, as under the second-order cone formulation, and for a worst-case variance it is the excess return per unit of the worst-case standard deviation. The model states the objective term on a lift with a constant corner, so the term has degree two. It adds a second lifted matrix for the objective term, with a constant corner $c$ in place of $k$, and keeps the lift with the corner $k$ for the bound. Only this type reads the corner of the measure.

Mathematical definition

\[\begin{align} \begin{bmatrix} \mathbf{W}_c & \boldsymbol{y} \\ \boldsymbol{y}^\intercal & c \end{bmatrix} \succeq 0 \quad&\Rightarrow\quad c\,\mathbf{W}_c \succeq \boldsymbol{y}\boldsymbol{y}^\intercal\,, \\ \mathrm{tr}(\mathbf{\Sigma} \mathbf{W}_c) &\geq \frac{\boldsymbol{y}^\intercal \mathbf{\Sigma} \boldsymbol{y}}{c} = \frac{k^{2} \sigma^{2}(\boldsymbol{w})}{c}\,. \end{align}\]

Where:

  • $\mathbf{W}_c$: The lifted matrix of the objective term, symmetric $N \times N$.
  • $c$: The corner, the corner of the measure, or the corner that set_sdp_lift_corner! derives when it is nothing.
  • $\boldsymbol{y} = k \boldsymbol{w}$: Homogenised weights, the weight variable of the model under the ratio objective.
  • $k$: Variable that scales the budget in the homogenised problem.
  • $\mathbf{\Sigma}$: The covariance matrix of the variance.
  • $\sigma(\boldsymbol{w})$: The portfolio's standard deviation.

$c$ is a constant, so the term has degree two in $(\boldsymbol{y}, k)$ at every $c$, and the corner does not change the weights. It changes the scale of $\mathbf{W}_c$, which is $k^{2} / c$ times a matrix of rank one, and the scale of the term. A corner near the $k$ of the solution keeps both near their scale at $k = 1$, and so keeps the solve well conditioned. The term is $1 / c$ times the variance of $\boldsymbol{y}$, so beside a risk term of another degree its weight in the objective changes with $c$, as the weight of a term of degree two changes with ohf.

Related

source
PortfolioOptimisers.LinearRatio — Type
struct LinearRatio <: RatioFormulation

Makes MaximumRatio divide the excess return by a lifted variance itself, not by its square root.

The model states the objective term on the lift with the corner $k$, so the term has degree one. It ignores the corner of the measure. The objective term and the bound read one lifted matrix, set_sdp_constraints!. The objective $(\mathrm{ret} - r_f) / \sigma^{2}(\boldsymbol{w})$ is a valid objective, but it is not the Sharpe ratio, and the set of a worst-case variance changes it: a compact set states its worst case on the weights, with degree two, under this lift too.

Mathematical definition

\[\begin{align} \begin{bmatrix} \mathbf{W} & \boldsymbol{y} \\ \boldsymbol{y}^\intercal & k \end{bmatrix} \succeq 0 \quad&\Rightarrow\quad k\,\mathbf{W} \succeq \boldsymbol{y}\boldsymbol{y}^\intercal\,, \\ \mathrm{tr}(\mathbf{\Sigma} \mathbf{W}) &\geq \frac{\boldsymbol{y}^\intercal \mathbf{\Sigma} \boldsymbol{y}}{k} = k \sigma^{2}(\boldsymbol{w})\,. \end{align}\]

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$.
  • $\boldsymbol{y} = k \boldsymbol{w}$: Homogenised weights, the weight variable of the model under the ratio objective.
  • $k$: Variable that scales the budget in the homogenised problem.
  • $\mathbf{\Sigma}$: The covariance matrix of the variance.
  • $\sigma(\boldsymbol{w})$: The portfolio's standard deviation.

Related

source
PortfolioOptimisers.Variance — Type
struct Variance{__T_settings, __T_sigma, __T_chol, __T_rc, __T_alg, __T_mtx_sqrt, __T_ratio_alg, __T_corner} <: RiskMeasure

Measures the portfolio variance, the quadratic form of the weights in a covariance matrix.

alg selects the risk expression that the model builds, and each VarianceFormulation reports the variance itself. QuadRiskExpr states the quadratic form $\boldsymbol{w}^\intercal \mathbf{\Sigma} \boldsymbol{w}$, and SquaredSOCRiskExpr states $\sigma^{2}$, the square of a second-order cone variable with $\sigma \geq \lVert \mathbf{G} \boldsymbol{w} \rVert_{2}$ and $\mathbf{G}^\intercal \mathbf{G} = \mathbf{\Sigma}$. The model adds $\sigma$ under both encodings, because the bound in settings.ub and the MaximumRatio objective need an expression of degree one in the weights. The bound acts on $\sigma$ at the square root of settings.ub, so a caller states it in the units of a variance. set_risk_constraints! states the model.

When rc holds rows, the model uses the semidefinite formulation of [190] whatever alg says. A SemiDefinitePhylogeny in the constraints also moves the variance to this formulation. The formulation lifts the weights into a symmetric matrix $\mathbf{W}$, and the variance becomes the trace $\mathrm{Tr}(\mathbf{\Sigma} \mathbf{W})$. Under MaximumRatio the corner of the lift sets the degree of the term, and so the ratio. ratio_alg selects it. SquareRootRatio, the default, gives the Sharpe ratio, as the second-order cone does, and LinearRatio gives the excess return per unit of variance. Formulation 10 of [190] is the second, although that work names it the maximisation of the Sharpe ratio. The first, with its constant corner, is the library's own. corner sets the constant corner of the first. The # Mathematical definition of MaximumRatio states the rule, and rc_variance_constraints! states the rows.

Warning

The semidefinite formulation is a relaxation. The model states $\mathbf{W} \succeq \boldsymbol{w} \boldsymbol{w}^\intercal / k$ and not equality, so the rows bind the returned weights only when the solution has $\mathbf{W} = \boldsymbol{w} \boldsymbol{w}^\intercal / k$. No term of the model forces a matrix of rank one. A solver can add a positive semidefinite part to $\mathbf{W}$ that moves the shares the rows constrain, and the solve still reports success. The rows then hold on $\mathbf{W}$ while the shares of the returned weights miss them, under a MinimumRisk objective as well as a MaximumUtility one. Under MaximumRatio the rows read the lift of the objective term, so SquareRootRatio relaxes them as MinimumRisk does, and LinearRatio relaxes them on the lift with the corner $k$. The two lifts give different weights, and neither is tight in general. To check a result, compute risk_contribution of the returned weights, or factor_risk_contribution under FactorRiskContribution, divide it by its sum, and compare the shares with the rows.

Mathematical definition

\[\begin{align} \mathrm{Variance}(\boldsymbol{w}) &= \boldsymbol{w}^\intercal \mathbf{\Sigma} \boldsymbol{w} = \sum_{i=1}^{N} \mathrm{RC}_{i}(\boldsymbol{w})\,,\\ \mathrm{RC}_{i}(\boldsymbol{w}) &= w_{i} (\mathbf{\Sigma} \boldsymbol{w})_{i}\,,\\ \mathbf{A} \, \mathbf{RC}(\boldsymbol{w}) &\leq \boldsymbol{b} \, \mathrm{Variance}(\boldsymbol{w})\,,\\ \mathbf{C} \, \mathbf{RC}(\boldsymbol{w}) &= \boldsymbol{d} \, \mathrm{Variance}(\boldsymbol{w})\,. \end{align}\]

Where:

  • $\boldsymbol{w}$: Portfolio weights vector $N \times 1$.
  • $\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.
  • $\mathrm{RC}_{i}(\boldsymbol{w})$: Risk contribution of asset $i$. The contributions sum to the variance.
  • $\mathbf{RC}(\boldsymbol{w})$: Vector of the $N$ risk contributions.
  • $\mathbf{A}$, $\boldsymbol{b}$: The inequality rows of rc and their bounds.
  • $\mathbf{C}$, $\boldsymbol{d}$: The equality rows of rc and their targets.

The last two lines state the rows of rc. Each row bounds a share of the variance, and the lines hold only when rc holds rows. Under FactorRiskContribution the rows read the contribution of each factor in place of $\mathrm{RC}_{i}$, the value that factor_risk_contribution reports, as a share of the whole variance.

Fields

  • settings: Risk measure settings.
  • sigma: Optional covariance matrix assets × assets. Also admits a Deferred Quantity — a covariance estimator or a prior estimator that computes the matrix against the optimisation's own prior, at factory time (see SigmaSlot and resolve_deferred_quantities). If nothing, the prior supplies it.
  • chol: Optional Cholesky factorisation of the covariance matrix. Derived from sigma, so it never defers: it arrives as one pair with whatever sigma resolves to. Give it with a matrix sigma and with neither otherwise — stating it without sigma, or while sigma holds a Deferred Quantity, is refused at construction (see assert_derived_slot_has_source). If nothing, the prior supplies the pair, or the kernel derives the factorisation from a stated sigma.
  • rc: Risk contribution constraint.
  • alg: Risk measure optimisation formulation algorithm.
  • mtx_sqrt: Square-root algorithm of the covariance matrix that the cone of the variance reads when no chol is at hand, or nothing for the plain Cholesky factor, which raises a LinearAlgebra.PosDefException on a matrix that is not positive definite. The default takes the square root of the eigendecomposition of a singular positive semidefinite matrix, such as a rank-one estimate. matrix_square_root states each algorithm.
  • ratio_alg: The ratio that MaximumRatio maximises when the model states the measure on a lifted weight matrix. SquareRootRatio divides the excess return by the square root of the measure, which is the Sharpe ratio for a plain variance. LinearRatio divides it by the measure itself. A formulation that lifts nothing, a bound, and every other objective ignore it.
  • corner: The constant corner $c$ of the lift of the objective term, a finite number $c > 0$. Only SquareRootRatio reads it. If nothing, the model derives it from the objective and the prior, set_sdp_lift_corner!. The corner changes the scale of the lifted matrix, and so the conditioning of the solve, but not the weights.

Constructors

Variance(;    settings::RiskMeasureSettings = RiskMeasureSettings(),    sigma::Option{<:SigmaSlot} = nothing,    chol::Option{<:MatNum} = nothing,    rc::Option{<:LcE_Lc} = nothing,    alg::VarianceFormulation = SquaredSOCRiskExpr(),    mtx_sqrt::Option{<:AbstractMatrixSquareRootAlgorithm} = EigenFallbackSquareRoot(),    ratio_alg::RatioFormulation = SquareRootRatio(),    corner::Option{<:Number} = nothing,) -> Variance

Keywords correspond to the struct's fields.

Validation

  • If sigma is an estimator, it is not an AbstractVarianceEstimator. A variance estimator has no cov, so assert_covariance_estimator raises an ArgumentError that names sigma.
  • If sigma is a matrix, !isempty(sigma) and size(sigma, 1) == size(sigma, 2).
  • If chol is a matrix, !isempty(chol).
  • chol is nothing when sigma is nothing or a Deferred Quantity.
  • If corner is a number, isfinite(corner) and corner > 0, assert_lift_corner.
Warning

sigma and chol are a pair, and a stated chol factorises the sigma beside it. A caller who wants one consistent pair names sigma alone. A matrix leaves the factorisation to the model, and a Deferred Quantity fits both from one prior. A caller who states both by hand must make sure that they agree. A stated matrix is also fixed. It crosses a Cross-Validation fold or a subset view as the answer for the whole universe, while a Deferred Quantity crosses unresolved and refits on the subset.

View parameters

Variance defines its own port_opt_view method rather than deriving one from field tags.

  • The method slices a stated sigma to the selected assets on both axes. A Deferred Quantity passes through unsliced, and then resolves on the subset.
  • The method slices chol on its columns alone. Its rows index the factorisation, which the asset selection does not address.
  • The method refuses an rc that is a LinearConstraint. A group constraint cannot be restricted to a part of its own group, and the restriction would break factor risk contribution.
  • settings, rc, alg, mtx_sqrt, ratio_alg and corner pass through unchanged.

Functor

(r::Variance)(w::VecNum)

Computes $\boldsymbol{w}^\intercal \mathbf{\Sigma} \boldsymbol{w}$ with the matrix r.sigma, the value of the risk expression under both encodings. The functor reads sigma as it stands, so a measure whose sigma is nothing or a Deferred Quantity needs factory with a prior result first.

Arguments

  • w::VecNum: Asset weights.

Examples

julia> w = [0.3803452066954233, 0.5900852659955864, 0.029569527308990307];julia> r = Variance(;                    sigma = [0.97780 -0.06400 0.84818;                             -0.06400 3.28564 1.84588;                             0.84818 1.84588 2.16317])Variance   settings ┼ RiskMeasureSettings            │   scale ┼ Float64: 1.0            │      ub ┼ nothing            │     rke ┴ Bool: true      sigma ┼ 3×3 Matrix{Float64}       chol ┼ nothing         rc ┼ nothing        alg ┼ SquaredSOCRiskExpr()   mtx_sqrt ┼ EigenFallbackSquareRoot()  ratio_alg ┼ SquareRootRatio()     corner ┴ nothingjulia> r(w)1.3421705804186579

Related

References

  • [32] H. Markowitz. Portfolio selection. The Journal of Finance 7, 77–91 (1952). Page 81.
  • [190] D. Cajas. A Semidefinite Programming Approach to Risk Parity Portfolio Optimization. Available at SSRN 5097869 (2025). Section 2.3, Formulations 9 and 10.
source
PortfolioOptimisers.StandardDeviation — Type
struct StandardDeviation{__T_settings, __T_sigma, __T_chol, __T_mtx_sqrt} <: RiskMeasure

Measures the portfolio standard deviation, the square root of the variance.

The model states it as a second-order cone variable $\sigma \geq \lVert \mathbf{G} \boldsymbol{w} \rVert_{2}$, which is tight when the objective minimises the risk or when a bound holds it. The variable has degree one in the weights, so the bound in settings.ub acts on it directly and a caller states the bound in the units of a standard deviation. set_risk_constraints! states the model. Under MaximumRatio the objective is the Sharpe ratio.

Mathematical definition

\[\begin{align} \mathrm{StandardDeviation}(\boldsymbol{w}) &= \sqrt{\boldsymbol{w}^\intercal \mathbf{\Sigma} \boldsymbol{w}}\,. \end{align}\]

Where:

  • $\boldsymbol{w}$: Portfolio weights vector $N \times 1$.
  • $\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.

Fields

  • settings: Risk measure settings.
  • sigma: Optional covariance matrix assets × assets. Also admits a Deferred Quantity — a covariance estimator or a prior estimator that computes the matrix against the optimisation's own prior, at factory time (see SigmaSlot and resolve_deferred_quantities). If nothing, the prior supplies it.
  • chol: Optional Cholesky factorisation of the covariance matrix. Derived from sigma, so it never defers: it arrives as one pair with whatever sigma resolves to. Give it with a matrix sigma and with neither otherwise — stating it without sigma, or while sigma holds a Deferred Quantity, is refused at construction (see assert_derived_slot_has_source). If nothing, the prior supplies the pair, or the kernel derives the factorisation from a stated sigma.
  • mtx_sqrt: Square-root algorithm of the covariance matrix that the cone of the standard deviation reads when no chol is at hand, or nothing for the plain Cholesky factor, which raises a LinearAlgebra.PosDefException on a matrix that is not positive definite. The default takes the square root of the eigendecomposition of a singular positive semidefinite matrix. matrix_square_root states each algorithm.

Constructors

StandardDeviation(;    settings::RiskMeasureSettings = RiskMeasureSettings(),    sigma::Option{<:SigmaSlot} = nothing,    chol::Option{<:MatNum} = nothing,    mtx_sqrt::Option{<:AbstractMatrixSquareRootAlgorithm} = EigenFallbackSquareRoot(),) -> StandardDeviation

Keywords correspond to the struct's fields.

Validation

  • If sigma is an estimator, it is not an AbstractVarianceEstimator. A variance estimator has no cov, so assert_covariance_estimator raises an ArgumentError that names sigma.
  • If sigma is a matrix, !isempty(sigma) and size(sigma, 1) == size(sigma, 2).
  • If chol is a matrix, !isempty(chol).
  • chol is nothing when sigma is nothing or a Deferred Quantity.
Warning

sigma and chol are a pair, as in Variance. A caller who wants one consistent pair names sigma alone, and a caller who states both by hand must make sure that they agree. A stated matrix is fixed across a Cross-Validation fold or a subset view, while a Deferred Quantity refits on the subset.

View parameters

StandardDeviation defines its own port_opt_view method rather than deriving one from field tags.

  • The method slices a stated sigma to the selected assets on both axes. A Deferred Quantity passes through unsliced, and then resolves on the subset.
  • The method slices chol on its columns alone. Its rows index the factorisation, which the asset selection does not address.
  • settings and mtx_sqrt pass through unchanged.

Functor

(r::StandardDeviation)(w::VecNum)

Computes $\sqrt{\boldsymbol{w}^\intercal \mathbf{\Sigma} \boldsymbol{w}}$ with the matrix r.sigma. The functor reads sigma as it stands, so a measure whose sigma is nothing or a Deferred Quantity needs factory with a prior result first.

Arguments

  • w::VecNum: Asset weights.

Examples

julia> w = [0.3803452066954233, 0.5900852659955864, 0.029569527308990307];julia> r = StandardDeviation(;                             sigma = [0.97780 -0.06400 0.84818;                                      -0.06400 3.28564 1.84588;                                      0.84818 1.84588 2.16317])StandardDeviation  settings ┼ RiskMeasureSettings           │   scale ┼ Float64: 1.0           │      ub ┼ nothing           │     rke ┴ Bool: true     sigma ┼ 3×3 Matrix{Float64}      chol ┼ nothing  mtx_sqrt ┴ EigenFallbackSquareRoot()julia> r(w)1.1585208588621345

Related

References

  • [32] H. Markowitz. Portfolio selection. The Journal of Finance 7, 77–91 (1952). Pages 80 and 81.
source
PortfolioOptimisers.UncertaintySetVariance — Type
struct UncertaintySetVariance{__T_settings, __T_ucs, __T_sigma, __T_mtx_sqrt, __T_ratio_alg, __T_corner} <: RiskMeasure

Measures the worst-case portfolio variance over an uncertainty set of covariance matrices.

ucs holds the set, as a fitted AbstractUncertaintySetResult or as an estimator that the optimisation fits from its returns data or its prior. Each measure holds its own set, so one model can hold more than one worst-case variance. The model states the worst case of the box, the ellipsoid and the norm ball as a dual problem over the lifted weight matrix $\mathbf{W}$, and the worst case of the compact set as a second-order cone problem in the weights. set_ucs_variance_risk! states the rows and the relaxation. A bound in settings.ub is in the units of a variance.

Under MaximumRatio the corner of the lift sets the degree of the worst case of the box, the ellipsoid and the norm ball, and so the ratio. ratio_alg selects it. SquareRootRatio, the default, gives the excess return per unit of the worst-case standard deviation, as the compact set does, and LinearRatio gives the excess return per unit of the worst-case variance. corner sets the constant corner of the first. The # Mathematical definition of MaximumRatio states the rule.

Mathematical definition

\[\begin{align} \mathrm{UncertaintySetVariance}(\boldsymbol{w}) &= \underset{\mathbf{\Sigma} \in U_{\mathbf{\Sigma}}}{\max} \boldsymbol{w}^\intercal \mathbf{\Sigma} \boldsymbol{w}\,,\\ R_{\mathrm{box}}(\boldsymbol{w}) &= \langle \mathbf{\Sigma}_u, (\boldsymbol{w} \boldsymbol{w}^\intercal)_{+} \rangle - \langle \mathbf{\Sigma}_l, (-\boldsymbol{w} \boldsymbol{w}^\intercal)_{+} \rangle\,,\\ R_{\mathrm{ell}}(\boldsymbol{w}) &= \boldsymbol{w}^\intercal \hat{\mathbf{\Sigma}} \boldsymbol{w} + k_{e} \lVert \mathbf{G}_{\Omega} \, \mathrm{vec}(\boldsymbol{w} \boldsymbol{w}^\intercal) \rVert_{2}\,,\\ R_{\mathrm{nb}}(\boldsymbol{w}) &= \boldsymbol{w}^\intercal \hat{\mathbf{\Sigma}} \boldsymbol{w} + \kappa_{b} \lVert \mathbf{L}^\intercal \mathrm{vec}(\boldsymbol{w} \boldsymbol{w}^\intercal) \rVert_{p^{*}}\,,\\ R_{\mathrm{cpt}}(\boldsymbol{w}) &= \boldsymbol{w}^\intercal \hat{\mathbf{\Sigma}} \boldsymbol{w} + \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:

  • $\boldsymbol{w}$: Portfolio weights vector $N \times 1$.
  • $U_{\mathbf{\Sigma}}$: Uncertainty set of the covariance matrix.
  • $R_{\mathrm{box}}$, $R_{\mathrm{ell}}$, $R_{\mathrm{nb}}$, $R_{\mathrm{cpt}}$: Value of the first line for the box, the ellipsoid and the norm ball without the condition $\mathbf{\Sigma} \succeq 0$, and for the compact set.
  • $\mathbf{\Sigma}_l$, $\mathbf{\Sigma}_u$: Lower and upper bounds of the box, lb and ub.
  • $(\cdot)_{+}$: Positive part, entry by entry.
  • $\hat{\mathbf{\Sigma}}$: Centre of the set, the val of the set when it states one and the sigma of the measure otherwise.
  • $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}$, and its value is $\lVert (\mathbf{I} - \mathbf{Q} \mathbf{Q}^{+}) \mathbf{C} \boldsymbol{w} \rVert_{2}^{2}$, with $\mathbf{Q}^{+}$ the pseudo-inverse.
  • $\kappa \geq 0$: Radius of the compact covariance set, the multiplier of its penalty.
  • $\langle \mathbf{X}, \mathbf{Y} \rangle = \mathrm{Tr}(\mathbf{X}^\intercal \mathbf{Y})$: Inner product of two matrices.

The compact value is the worst case of the first line. The box, the ellipsoid and the norm ball also require $\mathbf{\Sigma} \succeq 0$, and their values above omit that condition, so each lies at or above the worst case of its set. The box value equals that worst case when the bound it reads on each entry gives a positive semidefinite matrix, for example when $\boldsymbol{w} \geq 0$ and $\mathbf{\Sigma}_u \succeq 0$. The model keeps the condition through the dual matrix $\mathbf{E} \succeq 0$ of the ellipsoid and the norm ball, and through the slack of $\mathbf{W} \succeq \boldsymbol{w} \boldsymbol{w}^\intercal / k$ for the box, so its optimum lies at or below these values.

[167] states the worst case over the box as a semidefinite programme, and Proposition 3 of [178] gives its closed form for $\boldsymbol{w} \geq 0$ and $\mathbf{\Sigma}_u \succeq 0$. [53] derives the dual of the worst case over the ellipsoid. The docstrings of NormBallUncertaintySet and CompactCovarianceUncertaintySet cite the sources of the other two sets.

Fields

  • settings: Risk measure settings.
  • ucs: Uncertainty set.
  • sigma: Optional covariance matrix assets × assets. Also admits a Deferred Quantity — a covariance estimator or a prior estimator that computes the matrix against the optimisation's own prior, at factory time (see SigmaSlot and resolve_deferred_quantities). If nothing, the prior supplies it.
  • mtx_sqrt: Square-root algorithm of the matrix of an EllipsoidalUncertaintySet in ucs, and of the centre of a CompactCovarianceUncertaintySet, or nothing for the plain Cholesky factor, which raises a LinearAlgebra.PosDefException on a matrix that is not positive definite. The default takes the square root of the eigendecomposition of a singular positive semidefinite matrix. matrix_square_root states each algorithm. The box and the norm ball read no square root.
  • ratio_alg: The ratio that MaximumRatio maximises when the model states the measure on a lifted weight matrix. SquareRootRatio divides the excess return by the square root of the measure, which is the Sharpe ratio for a plain variance. LinearRatio divides it by the measure itself. A formulation that lifts nothing, a bound, and every other objective ignore it. The compact set lifts nothing.
  • corner: The constant corner $c$ of the lift of the objective term, a finite number $c > 0$. Only SquareRootRatio reads it. If nothing, the model derives it from the objective and the prior, set_sdp_lift_corner!. The corner changes the scale of the lifted matrix, and so the conditioning of the solve, but not the weights.

Constructors

UncertaintySetVariance(;    settings::RiskMeasureSettings = RiskMeasureSettings(),    ucs::Option{<:UcSE_UcS} = NormalUncertaintySet(),    sigma::Option{<:SigmaSlot} = nothing,    mtx_sqrt::Option{<:AbstractMatrixSquareRootAlgorithm} = EigenFallbackSquareRoot(),    ratio_alg::RatioFormulation = SquareRootRatio(),    corner::Option{<:Number} = nothing,) -> UncertaintySetVariance

Keywords correspond to the struct's fields.

Validation

Warning

A stated sigma is fixed. It crosses a Cross-Validation fold or a subset view as the answer for the whole universe, so it does not follow the refit that the optimisation runs, and nothing makes it agree with the set beside it. A caller who wants it to follow the fit names a Deferred Quantity in sigma, or leaves the slot nothing so that the prior supplies it.

View parameters

UncertaintySetVariance defines its own port_opt_view method rather than deriving one from field tags.

  • ucs recurses through port_opt_view with the asset index alone. A set on the covariance axis maps the index to the entries of the vectorised matrix before it slices.
  • The method slices a stated sigma to the selected assets on both axes. A Deferred Quantity passes through unsliced, and then resolves on the subset.
  • settings, mtx_sqrt, ratio_alg and corner pass through unchanged.

Functor

(r::UncertaintySetVariance)(w::VecNum)

Computes the variance of the weights w. The value depends on what ucs holds, because an estimator that is not fitted defines no set.

  • ucs holds an AbstractUncertaintySetResult: the value of the definition above for that set, computed by ucs_variance.
  • ucs holds an estimator or nothing: the nominal variance $\boldsymbol{w}^\intercal \mathbf{\Sigma} \boldsymbol{w}$, with $\mathbf{\Sigma}$ the sigma of the measure.

Arguments

  • w::VecNum: Asset weights.

Examples

julia> w = [0.3803452066954233, 0.5900852659955864, 0.029569527308990307];julia> r = UncertaintySetVariance(;                                  sigma = [0.97780 -0.06400 0.84818;                                           -0.06400 3.28564 1.84588;                                           0.84818 1.84588 2.16317])UncertaintySetVariance   settings ┼ RiskMeasureSettings            │   scale ┼ Float64: 1.0            │      ub ┼ nothing            │     rke ┴ Bool: true        ucs ┼ NormalUncertaintySet            │       pe ┼ EmpiricalPrior            │          │           ce ┼ PortfolioOptimisersCovariance            │          │              │   ce ┼ Covariance            │          │              │      │    me ┼ SimpleExpectedReturns            │          │              │      │       │   w ┴ nothing            │          │              │      │    ce ┼ GeneralCovariance            │          │              │      │       │   ce ┼ StatsBase.SimpleCovariance: StatsBase.SimpleCovariance(true)            │          │              │      │       │    w ┴ nothing            │          │              │      │   alg ┼ FullMoment()            │          │              │      │     w ┴ nothing            │          │              │   mp ┼ MatrixProcessing            │          │              │      │     pdm ┼ Posdef            │          │              │      │         │      alg ┼ UnionAll: NearestCorrelationMatrix.Newton            │          │              │      │         │   kwargs ┴ @NamedTuple{}: NamedTuple()            │          │              │      │      dn ┼ nothing            │          │              │      │      dt ┼ nothing            │          │              │      │     alg ┼ nothing            │          │              │      │   order ┴ NTuple{4, Symbol}: (:pdm, :dn, :dt, :alg)            │          │           me ┼ SimpleExpectedReturns            │          │              │   w ┴ nothing            │          │      horizon ┼ nothing            │          │   fill_limit ┼ nothing            │          │        x_src ┴ nothing            │      alg ┼ BoxUncertaintySetAlgorithm()            │    n_sim ┼ Int64: 3000            │        q ┼ Float64: 0.05            │      rng ┼ Random.TaskLocalRNG: Random.TaskLocalRNG()            │     seed ┼ nothing            │      ens ┼ nothing            │      pdm ┼ Posdef            │          │      alg ┼ UnionAll: NearestCorrelationMatrix.Newton            │          │   kwargs ┴ @NamedTuple{}: NamedTuple()            │       dc ┼ DiagonalOfShape()            │   kwargs ┴ @NamedTuple{}: NamedTuple()      sigma ┼ 3×3 Matrix{Float64}   mtx_sqrt ┼ EigenFallbackSquareRoot()  ratio_alg ┼ SquareRootRatio()     corner ┴ nothingjulia> r(w)1.3421705804186579

Related

References

  • [167] M. Sousa Lobo and S. Boyd. The worst-case risk of a portfolio. Technical report, Stanford University (2000). Section 5.2.6, Equations 6 and 7.
  • [178] R. H. Tütüncü and M. Koenig. Robust Asset Allocation. Annals of Operations Research 132, 157–187 (2004). Section 3.1, Proposition 3.
  • [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.8 to 6.15.
source
PortfolioOptimisers.factory — Method
factory(
    r::Variance,
    pr::AbstractPriorResult,
    args...;
    kwargs...
) -> Variance{RiskMeasureSettings{__T_scale, __T_ub, __T_rke}, _A, _B, _C, var"#s185", _D, <:RatioFormulation} where {__T_scale, __T_ub, __T_rke, _A, _B, _C, var"#s185"<:VarianceFormulation, _D}

Create an instance of Variance that holds a covariance matrix, taken from the measure or from the prior result pr.

The method selects sigma and chol as one pair, not field by field. A stated sigma with no factorisation keeps chol = nothing, because the factorisation of the prior belongs to a different matrix.

Algorithm

  1. Resolve a Deferred Quantity in sigma with resolve_deferred_quantities, giving r.
  2. Select the pair sigma, chol with sigma_chol_selector. A measure that states neither takes pr.sigma and pr.chol, and every other measure keeps its own pair.
  3. Rebuild r with the pair, with rebuild_struct. The settings, rc, alg, mtx_sqrt, ratio_alg and corner of r do not change.

Related

source
PortfolioOptimisers.factory — Method
factory(
    r::StandardDeviation,
    pr::AbstractPriorResult,
    args...;
    kwargs...
) -> StandardDeviation{RiskMeasureSettings{__T_scale, __T_ub, __T_rke}} where {__T_scale, __T_ub, __T_rke}

Create an instance of StandardDeviation that holds a covariance matrix, taken from the measure or from the prior result pr.

The method selects sigma and chol as one pair, as factory(r::Variance, pr::AbstractPriorResult, args...; kwargs...) does.

Algorithm

  1. Resolve a Deferred Quantity in sigma with resolve_deferred_quantities, giving r.
  2. Select the pair sigma, chol with sigma_chol_selector. A measure that states neither takes pr.sigma and pr.chol, and every other measure keeps its own pair.
  3. Rebuild r with the pair, with rebuild_struct. The settings and mtx_sqrt of r do not change.

Related

source
PortfolioOptimisers.factory — Function
factory(r::UncertaintySetVariance, pr::AbstractPriorResult, ::Any,
        ucs::Option{<:UcSE_UcS} = nothing, args...;
        kwargs...)

Create an instance of UncertaintySetVariance whose empty slots take the uncertainty set ucs and the covariance matrix of the prior result pr.

A slot that the measure states keeps its value. So ucs fills r.ucs only when r.ucs is nothing, and it does not replace a set that the measure holds.

Algorithm

  1. Resolve a Deferred Quantity in sigma with resolve_deferred_quantities, giving r.
  2. Select the set with ucs_selector, giving r.ucs when it is not nothing and ucs otherwise.
  3. Select the matrix with nothing_scalar_array_selector, giving r.sigma when it is not nothing and pr.sigma otherwise.
  4. Rebuild r with the set and the matrix, with rebuild_struct. The settings, mtx_sqrt, ratio_alg and corner of r do not change.

Arguments

  • r::UncertaintySetVariance: The measure.
  • pr::AbstractPriorResult: The prior result, which supplies pr.sigma.
  • ::Any: A positional argument that the method ignores, such as a solver.
  • ucs: The uncertainty set for a measure whose ucs is nothing.
  • args..., kwargs...: Ignored.

Returns

  • r_new::UncertaintySetVariance: The new measure.

Related

source
PortfolioOptimisers.factory — Function
factory(
    r::UncertaintySetVariance,
    pr::AbstractPriorResult;
    ...
) -> UncertaintySetVariance{RiskMeasureSettings{__T_scale, __T_ub, __T_rke}, _A, _B, _C, <:RatioFormulation} where {__T_scale, __T_ub, __T_rke, _A, _B, _C}
factory(
    r::UncertaintySetVariance,
    pr::AbstractPriorResult,
    ucs::Union{Nothing, AbstractUncertaintySetEstimator, AbstractUncertaintySetResult};
    kwargs...
) -> UncertaintySetVariance{RiskMeasureSettings{__T_scale, __T_ub, __T_rke}, _A, _B, _C, <:RatioFormulation} where {__T_scale, __T_ub, __T_rke, _A, _B, _C}

Create an instance of UncertaintySetVariance from the prior result pr and the uncertainty set ucs, with no positional argument between them.

It takes the steps of factory(r::UncertaintySetVariance, pr::AbstractPriorResult, ::Any, ucs, args...; kwargs...). So ucs fills r.ucs only when r.ucs is nothing.

Related

source
PortfolioOptimisers.factory — Function
factory(
    r::UncertaintySetVariance,
    ucs::Union{AbstractUncertaintySetEstimator, AbstractUncertaintySetResult};
    ...
) -> UncertaintySetVariance{RiskMeasureSettings{__T_scale, __T_ub, __T_rke}, _A, _B, _C, <:RatioFormulation} where {__T_scale, __T_ub, __T_rke, _A, _B, _C}
factory(
    r::UncertaintySetVariance,
    ucs::Union{AbstractUncertaintySetEstimator, AbstractUncertaintySetResult},
    pr::Union{Nothing, AbstractPriorResult};
    kwargs...
) -> UncertaintySetVariance{RiskMeasureSettings{__T_scale, __T_ub, __T_rke}, _A, _B, _C, <:RatioFormulation} where {__T_scale, __T_ub, __T_rke, _A, _B, _C}

Create an instance of UncertaintySetVariance from the uncertainty set ucs and an optional prior result pr.

ucs fills r.ucs only when r.ucs is nothing. Without pr the method keeps r.sigma as it stands, and with pr it resolves a Deferred Quantity in sigma and fills an empty sigma with pr.sigma.

Related

source
PortfolioOptimisers.obs_weights_view — Method
obs_weights_view(r::UncertaintySetVariance, i) -> UncertaintySetVariance

Return the measure with the observation weights of its uncertainty set estimator cut to the observations i, through obs_weights_fields.

The measure is not @propagatable, so it needs this method of obs_weights_view. An uncertainty set estimator in ucs fits its prior on the returns of the solve, so a cut of those returns, such as the drop of a Shared Series gap, must reach its weights, see shared_series_estimator.

Related

source

References

[32]
H. Markowitz. Portfolio Selection. The Journal of Finance 7, 77–91 (1952).
[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).
[178]
R. H. Tütüncü and M. Koenig. Robust Asset Allocation. Annals of Operations Research 132, 157–187 (2004).
[190]
D. Cajas. A Semidefinite Programming Approach to Risk Parity Portfolio Optimization. Available at SSRN 5097869 (2025).