Skip to content
5

Variance

PortfolioOptimisers.QuadRiskExpr Type
julia
struct QuadRiskExpr <: VarianceFormulation end

Direct quadratic risk expression optimisation formulation for variance-like risk measures. The risk measure is implemented using an explicitly quadratic form. This can be in two ways.

Summary statistics

optwwΣw.

Where:

  • w: N×1 asset weights vector.

  • Σ: N×N co-moment matrix.

Scenario-based

optwdd.s.t.dSw.

Where:

  • w: N×1 asset weights vector.

  • d: T×1 deviations vector.

  • Sw: Scenario set for portfolio x.

Related Types

source
PortfolioOptimisers.SquaredSOCRiskExpr Type
julia
struct SquaredSOCRiskExpr <: VarianceFormulation end

Squared second-order cone risk expression optimisation formulation for applicable risk measures. The risk measure is implemented using the square of a variable constrained by a second order cone.

Related

source
PortfolioOptimisers.RSOCRiskExpr Type
julia
struct RSOCRiskExpr <: SecondMomentFormulation end

Rotated second-order cone risk expression optimisation formulation for applicable risk measures. The risk measure using a variable constrained to be in a rotated second order cone representing the sum of squares.

Related Types

source
PortfolioOptimisers.SOCRiskExpr Type
julia
struct SOCRiskExpr <: SecondMomentFormulation end

Second-order cone risk expression optimisation formulation for applicable risk measures. The risk measure is implemented using a variable constrained by a second order cone.

Related

source
PortfolioOptimisers.Variance Type
julia
struct Variance{T1, T2, T3, T4} <: RiskMeasure
    settings::T1
    sigma::T2
    rc::T3
    alg::T4
end

Represents the portfolio variance using a covariance matrix.

Fields

  • settings: Risk measure configuration.

  • sigma: Optional covariance matrix that overrides the prior covariance when provided. Also used to compute the risk represented by a vector.

  • rc: Optional specification of risk contribution constraints.

  • alg: The optimisation formulation used to represent the variance risk expression.

Constructors

julia
Variance(; settings::RiskMeasureSettings = RiskMeasureSettings(),
         sigma::Union{Nothing, <:AbstractMatrix} = nothing,
         rc::Union{Nothing, <:LinearConstraintEstimator, <:LinearConstraint} = nothing,
         alg::VarianceFormulation = SquaredSOCRiskExpr())

Keyword arguments correspond to the fields above.

Validation

  • If sigma is provided, !isempty(sigma) and size(sigma, 1) == size(sigma, 2).

JuMP Formulations

Info

Regardless of the formulation used, an auxiliary variable representing the standard deviation is needed in order to constrain the risk or maximise the risk-adjusted return ratio. This is because quadratic constraints are not strictly convex, and the transformation needed to maximise the risk-adjusted return ratio requires affine variables in the numerator and denominator.

Depending on the alg field, the variance risk measure is formulated using JuMP as follows:

QuadRiskExpr

optwwΣw.

Where:

  • w: N×1 asset weights vector.

  • Σ: N×N covariance matrix.

SquaredSOCRiskExpr

optwσ2s.t.Gw2σ.

Where:

  • w: N×1 asset weights vector.

  • σ: Variable representing the optimised portfolio's standard deviation.

  • G: Suitable factorisation of the N×N covariance matrix, such as the square root matrix, or the Cholesky factorisation.

  • 2: L2 norm, which is modelled as a SecondOrderCone.

Functor

julia
(r::Variance)(w::AbstractVector)

Computes the variance risk of a portfolio with weights w using the covariance matrix r.sigma.

Variance(w,Σ)=wΣw.

Where:

  • w: N×1 asset weights vector.

  • Σ: N×N covariance matrix.

Arguments

  • w::AbstractVector: Asset weights.

Examples

julia
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}
        rc ┼ nothing
       alg ┴ SquaredSOCRiskExpr()

julia> r(w)
1.3421705804186579

Related

source
PortfolioOptimisers.StandardDeviation Type
julia
struct StandardDeviation{T1, T2} <: RiskMeasure
    settings::T1
    sigma::T2
end

Represents the portfolio standard deviation using a covariance matrix. It is the square root of the variance.

Fields

  • settings: Risk measure configuration.

  • sigma: Optional covariance matrix that overrides the prior covariance when provided. Also used to compute the risk represented by a vector.

Constructors

julia
StandardDeviation(; settings::RiskMeasureSettings = RiskMeasureSettings(),
                   sigma::Union{Nothing, <:AbstractMatrix} = nothing)

Keyword arguments correspond to the fields above.

Validation

  • If sigma is provided, !isempty(sigma) and size(sigma, 1) == size(sigma, 2).

JuMP Formulation

optwσs.t.Gw2σ.

Where:

  • w: N×1 asset weights vector.

  • σ: Variable representing the optimised portfolio's standard deviation.

  • G: Suitable factorisation of the N×N covariance matrix, such as the square root matrix, or the Cholesky factorisation.

  • 2: L2 norm, which is modelled as a SecondOrderCone.

Functor

julia
(r::StandardDeviation)(w::AbstractVector)

Computes the standard deviation risk of a portfolio with weights w using the covariance matrix r.sigma.

StandardDeviation(w,Σ)=wΣw.

Where:

  • w: N×1 asset weights vector.

  • Σ: N×N covariance matrix.

Arguments

  • w::AbstractVector: Asset weights.

Examples

julia
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}

julia> r(w)
1.1585208588621345

Related

source
PortfolioOptimisers.UncertaintySetVariance Type
julia
struct UncertaintySetVariance{T1, T2, T3} <: RiskMeasure

Represents the variance risk measure under uncertainty sets. Works the same way as the Variance risk measure but allows specifying uncertainty set estimators or results. These are only used in JuMP-based optimisations because they dictate how the variance is formulated as an optimisation problem. By encapsulating the uncertainty set estimator or result, enables the use of multiple uncertainty set variances in the same optimisation model.

Fields

  • settings: Risk measure configuration.

  • ucs: Uncertainty set estimator or result that defines the uncertainty model for the variance calculation.

  • sigma: Optional covariance matrix that overrides the prior covariance when provided. Also used to compute the risk represented by a vector.

Constructors

julia
UncertaintySetVariance(; settings::RiskMeasureSettings = RiskMeasureSettings(),
                       ucs::Union{Nothing, <:AbstractUncertaintySetResult,
                                  <:AbstractUncertaintySetEstimator} = NormalUncertaintySet(),
                       sigma::Union{Nothing, <:AbstractMatrix{<:Real}} = nothing)

Keyword arguments correspond to the fields above.

Validation

  • If sigma is provided, !isempty(sigma).

JuMP Formulations

When using an uncertainty set on the variance, the optimisation problem becomes:

optwmaxΣUΣwΣw.

Where:

  • w: N×1 asset weights vector.

  • Σ: N×N covariance matrix.

  • UΣ: Uncertainty set for the covariance matrix.

This problem can be reformulated depending on the type of uncertainty set used.

Box uncertainty set

optwTr(AuΣu)Tr(AlΣl)s.t.Au0Al0[Wwwk]0AuAl=W.

Where:

  • w: N×1 asset weights vector.

  • Au, Al, W: N×N auxiliary symmetric matrices.

  • Σl: N×N lower bound of the covariance matrix.

  • Σu: N×N upper bound of the covariance matrix.

  • k: Scalar variable/constant.

    • If the objective risk-adjusted return, it is a non-negative variable.

    • Else it is equal to 1.

  • Tr(): Trace operator.

Ellipse uncertainty set

optwTr(Σ(W+E))+kΣσs.t.[Wwwk]0E0Gvec(W+E)2σ

Where:

  • w: N×1 asset weights vector.

  • Σ: N×N covariance matrix.

  • W, E: N×N auxiliary symmetric matrices.

  • kΣ: Scalar constant defining the size of the uncertainty set.

  • σ: Variable representing the portfolio's variance of the variance.

  • G: Suitable factorisation of the N^2×N^2 covariance of the covariance matrix of the uncertainty set, such as the square root matrix, or the Cholesky factorisation.

  • k: Scalar variable/constant.

    • If the objective risk-adjusted return, it is a non-negative variable.

    • Else it is equal to 1.

  • Tr(): Trace operator.

  • vec(): Vectorisation operator, which unrolls a matrix as a column vector in column-major order.

  • 2: L2 norm, which is modelled as a SecondOrderCone.

Functor

julia
(r::UncertaintySetVariance)(w::AbstractVector)

Computes the variance risk of a portfolio with weights w using the covariance matrix r.sigma.

UncertaintySetVariance(w,Σ)=wΣw.

Where:

  • w: N×1 asset weights vector.

  • Σ: N×N covariance matrix.

Arguments

  • w::AbstractVector: Asset weights.

Examples

julia
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 ┴ Full()
           │         │           │   mp ┼ DefaultMatrixProcessing
           │         │           │      │       pdm ┼ Posdef
           │         │           │      │           │   alg ┴ UnionAll: NearestCorrelationMatrix.Newton
           │         │           │      │   denoise ┼ nothing
           │         │           │      │    detone ┼ nothing
           │         │           │      │       alg ┴ nothing
           │         │        me ┼ SimpleExpectedReturns
           │         │           │   w ┴ nothing
           │         │   horizon ┴ nothing
           │     alg ┼ BoxUncertaintySetAlgorithm()
           │   n_sim ┼ Int64: 3000
           │       q ┼ Float64: 0.05
           │     rng ┼ Random.TaskLocalRNG: Random.TaskLocalRNG()
           │    seed ┴ nothing
     sigma ┴ 3×3 Matrix{Float64}

julia> r(w)
1.3421705804186579

Related

source
PortfolioOptimisers.factory Method
julia
factory(r::Variance, prior::AbstractPriorResult, args...; kwargs...)

Create an instance of Variance by selecting the covariance matrix from the risk-measure instance or falling back to the prior result (see nothing_scalar_array_factory).

Arguments

  • r: Prototype risk measure whose settings, rc and alg fields are reused for the new instance.

  • prior: Prior result providing prior.sigma to use when r.sigma === nothing.

  • args...: Extra positional arguments are accepted for API compatibility but are ignored by this constructor.

  • kwargs... : Keyword arguments are accepted for API compatibility but are ignored by this constructor.

Returns

  • r_new::Variance: A new Variance instance.

Details

Related

source
PortfolioOptimisers.factory Method
julia
factory(r::StandardDeviation, prior::AbstractPriorResult, args...; kwargs...)

Create an instance of StandardDeviation by selecting the covariance matrix from the risk-measure instance or falling back to the prior result (see nothing_scalar_array_factory).

Arguments

  • r: Prototype risk measure whose settings, rc and alg fields are reused for the new instance.

  • prior: Prior result providing prior.sigma to use when r.sigma === nothing.

  • args...: Extra positional arguments are accepted for API compatibility but are ignored by this constructor.

  • kwargs... : Keyword arguments are accepted for API compatibility but are ignored by this constructor.

Returns

  • r_new::StandardDeviation: A new StandardDeviation instance.

Details

Related

source
PortfolioOptimisers.factory Function
julia
factory(r::UncertaintySetVariance, prior::AbstractPriorResult, ::Any,
        ucs::Union{Nothing, <:AbstractUncertaintySetResult,
                   <:AbstractUncertaintySetEstimator} = nothing, args...;
        kwargs...)

Create an instance of UncertaintySetVariance by selecting the uncertainty set and covariance matrix from the risk-measure instance or falling back to the prior result.

Arguments

  • r: Prototype risk measure whose settings and sigma fields are reused for the new instance.

  • prior: Prior result providing prior.sigma to use when r.sigma === nothing.

  • ::Any: Placeholder positional argument for API compatibility.

  • ucs: Optional uncertainty set estimator or result to override r.ucs.

  • args...: Extra positional arguments are accepted for API compatibility but are ignored by this constructor.

  • kwargs...: Keyword arguments are accepted for API compatibility but are ignored by this constructor.

Returns

  • r_new::UncertaintySetVariance: A new UncertaintySetVariance instance.

Details

Related

source
PortfolioOptimisers.SecondMomentFormulation Type
julia
abstract type SecondMomentFormulation <: AbstractAlgorithm end

Abstract supertype for optimisation formulations of second moment risk measures in PortfolioOptimisers.jl.

Related Types

source
PortfolioOptimisers.VarianceFormulation Type
julia
abstract type VarianceFormulation <: SecondMomentFormulation end

Abstract supertype for optimisation formulations of variance-based risk measures in PortfolioOptimisers.jl.

Related Types

source