Skip to content
5

Moment Risk Measures

PortfolioOptimisers.FirstLowerMoment Type
julia
struct FirstLowerMoment <: UnstandardisedLowOrderMomentMeasureAlgorithm end

Represents the first lower moment risk measure algorithm in PortfolioOptimisers.jl.

Computes portfolio risk using the first lower moment, which is the negative mean of the deviations of the returns series below a target value.

Related

source
PortfolioOptimisers.MeanAbsoluteDeviation Type
julia
struct MeanAbsoluteDeviation <: UnstandardisedLowOrderMomentMeasureAlgorithm end

Represents the mean absolute deviation risk measure algorithm in PortfolioOptimisers.jl.

Computes portfolio risk as the mean of the absolute deviations of the returns series from a target value.

Related

source
PortfolioOptimisers.SecondMoment Type
julia
struct SecondMoment{T1, T2, T3} <: LowOrderMomentMeasureAlgorithm
    ve::T1
    alg1::T2
    alg2::T3
end

Represents a second moment (variance or standard deviation) risk measure algorithm in PortfolioOptimisers.jl.

Computes portfolio risk using the second central (full) or lower (semi) moment of the return distribution, supporting both full and semi (downside) formulations. The specific formulation is determined by the alg1 and alg2 fields, enabling flexible representation of variance, semi-variance, standard deviation, or semi-standard deviation.

Fields

  • ve: Variance estimator used to compute the second moment.

  • alg1: Moment algorithm specifying whether to use all deviations or only downside deviations.

  • alg2: Second moment formulation specifying the optimisation formulation.

Constructors

julia
SecondMoment(; ve::AbstractVarianceEstimator = SimpleVariance(; me = nothing),
             alg1::AbstractMomentAlgorithm = Full(),
             alg2::SecondMomentFormulation = SquaredSOCRiskExpr())

Keyword arguments correspond to the fields above.

Examples

julia
julia> SecondMoment()
SecondMoment
    ve ┼ SimpleVariance
       │          me ┼ nothing
       │           w ┼ nothing
       │   corrected ┴ Bool: true
  alg1 ┼ Full()
  alg2 ┴ SquaredSOCRiskExpr()

Related

source
PortfolioOptimisers.LowOrderMoment Type
julia
struct LowOrderMoment{T1, T2, T3, T4} <: RiskMeasure
    settings::T1
    w::T2
    mu::T3
    alg::T4
end

Represents a low-order moment risk measure in PortfolioOptimisers.jl.

Computes portfolio risk using a low-order moment algorithm (such as first lower moment, mean absolute deviation, or second moment), optionally with custom weights and target values. This type is used for risk measures based on mean, variance, or related statistics.

Fields

  • settings: Risk measure configuration.

  • w: Optional vector of observation weights.

  • mu: Optional target scalar, vector, or VecScalar value for moment calculation that overrides the prior mu when provided. Also used to compute the moment target, via calc_moment_target. If nothing it is computed from the returns series using the optional weights in w.

  • alg: Low-order moment risk measure algorithm.

Constructors

julia
LowOrderMoment(; settings::RiskMeasureSettings = RiskMeasureSettings(),
               w::Union{Nothing, <:AbstractWeights} = nothing,
               mu::Union{Nothing, <:Real, <:AbstractVector{<:Real}, <:VecScalar} = nothing,
               alg::LowOrderMomentMeasureAlgorithm = FirstLowerMoment())

Keyword arguments correspond to the fields above.

Validation

  • If mu is not nothing:

    • ::Real: isfinite(mu).

    • ::AbstractVector: !isempty(mu) and all(isfinite, mu).

  • If w is not nothing, !isempty(w).

Formulations

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

FirstLowerMoment

The first lower moment is computed as:

FirstLowerMoment(X)=E[max(E[X]X,0)].

Where:

  • X: T×1 vector of portfolio returns.

  • E[]: expected value operator, supports weighted averages.

  • : element-wise function application.

As an optimisation problem, it can be formulated as:

optw,dE[d]s.t.dE[Xw]Xwd0.

Where:

  • w: N×1 asset weights vector.

  • d: T×1 vector of auxiliary decision variables representing deviations below the target.

  • X: T×N return matrix.

  • E[]: expected value operator, supports weighted averages.

MeanAbsoluteDeviation

The mean absolute deviation is computed as:

MeanAbsoluteDeviation(X)=E[|XE[X]|]

Where:

  • X: T×1 vector of portfolio returns.

  • E[]: expected value operator, supports weighted averages.

As an optimisation problem, it can be formulated as:

optw,d2E[d]s.t.dE[Xw]Xwd0.

Where:

  • w: N×1 asset weights vector.

  • d: T×1 vector of auxiliary decision variables representing deviations below the target.

  • X: T×N return matrix.

  • E[]: expected value operator, supports weighted averages.

SecondMoment

Depending on the alg1 field the risk measure can either compute the second central moment or second lower moment.

Info

Regardless of the formulation used, an auxiliary variable representing the square root of the central/lower moment 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.

Both central and lower moments can be formulated as quadratic moments (variance or semi-variance) or their square roots (standard deviation or semi-standard deviation). Regardless of whether they are central or lower moments, they can be formulated in a variety of ways.

Depending on the alg2 field, it can represent the variance (using different formulations in JuMP) or standard deviation.

The (semi-)variance formulations are:

It is computed as:

Variance(X)=E[(XE[X])2].SemiVariance(X)=E[min(XE[X],0)2].

Where:

  • X: T×1 vector of portfolio returns.

  • E[]: expected value operator, supports weighted averages.

The (semi-)standard deviation formulation is:

It is computed as:

StandardDeviation(X)=E[(XE[X])2].SemiStandardDeviation(X)=E[min(XE[X],0)2].

Where:

  • X: T×1 vector of portfolio returns.

  • E[]: expected value operator, supports weighted averages.

SquaredSOCRiskExpr

Represents the (semi-)variance using the square of a second order cone constrained variable.

The variance is formulated as.

optw,dfσ2s.t.d=XwE[Xw]ds=λd(σ,ds)Ksoc

The semi-variance is formulated as.

optw,dfσ2s.t.XwE[Xw]dd0ds=λd(σ,ds)Ksoc

Where:

  • w: N×1 asset weights vector.

  • d: T×1 vector of auxiliary decision variables representing deviations from the target.

  • σ: standard deviation of the portfolio returns.

  • ds: T×1 vector of scaled deviations according to observation weights.

  • X: T×N return matrix.

  • λ: T×1 vector of observation weights.

  • f: observation weights scaling factor, it is a function of the type of observation weights.

  • Ksoc: second order cone.

  • : element-wise (Hadamard) product.

RSOCRiskExpr

Represents the (semi-)variance using a sum of squares formulation via a rotated second order cone.

The variance is formulated as.

optw,dfts.t.d=XwE[Xw]ds=λd(t,0.5,ds)Krsoc

The semi-variance is formulated as.

optw,dfts.t.XwE[Xw]dd0ds=λd(t,0.5,ds)Krsoc

Where:

  • w: N×1 asset weights vector.

  • d: T×1 vector of auxiliary decision variables representing deviations from the target.

  • t: variance of the portfolio returns.

  • ds: T×1 vector of scaled deviations according to observation weights.

  • X: T×N return matrix.

  • λ: T×1 vector of observation weights.

  • f: observation weights scaling factor, it is a function of the type of observation weights.

  • Krsoc: rotated second order cone.

  • : element-wise (Hadamard) product.

QuadRiskExpr

Represents the (semi-)variance using the deviations vector dotted with itself.

The variance is formulated as.

optw,dfdsdss.t.d=XwE[Xw]ds=λd

The semi-variance is formulated as.

optw,dfdsdss.t.XwE[Xw]dd0ds=λd

Where:

  • w: N×1 asset weights vector.

  • d: T×1 vector of auxiliary decision variables representing deviations from the target.

  • ds: T×1 vector of scaled deviations according to observation weights.

  • X: T×N return matrix.

  • μ: minimum acceptable return.

  • λ: T×1 vector of observation weights.

  • f: observation weights scaling factor, it is a function of the type of observation weights.

  • : element-wise (Hadamard) product.

SOCRiskExpr

Represents the (semi-)standard deviation using a second order cone constrained variable.

The standard deviation is formulated as.

optw,dfσs.t.d=XwE[Xw]ds=λd(σ,ds)Ksoc

The semi-standard deviation is formulated as.

optw,dfσs.t.XwE[Xw]dd0ds=λd(σ,ds)Ksoc

Where:

  • w: N×1 asset weights vector.

  • d: T×1 vector of auxiliary decision variables representing deviations from the target.

  • σ: standard deviation of the portfolio returns.

  • ds: T×1 vector of scaled deviations according to observation weights.

  • X: T×N return matrix.

  • μ: minimum acceptable return.

  • λ: T×1 vector of observation weights.

  • f: observation weights scaling factor, it is a function of the type of observation weights.

  • : element-wise (Hadamard) product.

  • Ksoc: second order cone.

Functor

julia
(r::LowOrderMoment)(w::AbstractVector, X::AbstractMatrix;
                    fees::Union{Nothing, <:Fees} = nothing)

Computes the the low order moment risk measure as defined in r using portfolio weights w, return matrix X, and optional fees fees.

Details

  • r.alg defines what low-order moment to compute.

  • The values of r.mu and r.w are optionally used to compute the moment target via calc_moment_target, which is used in calc_deviations_vec to compute the deviation vector.

Examples

julia
julia> LowOrderMoment()
LowOrderMoment
  settings ┼ RiskMeasureSettings
           │   scale ┼ Float64: 1.0
           │      ub ┼ nothing
           │     rke ┴ Bool: true
         w ┼ nothing
        mu ┼ nothing
       alg ┴ FirstLowerMoment()

Related

source
PortfolioOptimisers.ThirdLowerMoment Type
julia
struct ThirdLowerMoment <: UnstandardisedHighOrderMomentMeasureAlgorithm end

Represents the unstandardised semi-skewness risk measure algorithm in PortfolioOptimisers.jl.

Computes portfolio risk using the third lower moment (unstandardised semi-skewness), which quantifies downside asymmetry by considering only the cubed deviations below a target value. This algorithm is unstandardised and operates directly on the return distribution.

Related

source
PortfolioOptimisers.FourthMoment Type
julia
struct FourthMoment{T1} <: UnstandardisedHighOrderMomentMeasureAlgorithm
    alg::T1
end

Represents the unstandardised fourth moment (kurtosis or semi-kurtosis) risk measure algorithm in PortfolioOptimisers.jl.

Computes portfolio risk using the fourth central (full) or lower (semi) moment of the return distribution, depending on the provided moment algorithm. This algorithm quantifies the "tailedness" of the return distribution without normalising by the variance.

Fields

  • alg: Moment algorithm specifying whether to use all deviations or only downside deviations.

Constructors

julia
FourthMoment(; alg::AbstractMomentAlgorithm = Full())

Keyword arguments correspond to the fields above.

Examples

julia
julia> FourthMoment()
FourthMoment
  alg ┴ Full()

Related

source
PortfolioOptimisers.StandardisedHighOrderMoment Type
julia
struct StandardisedHighOrderMoment{T1, T2} <: HighOrderMomentMeasureAlgorithm
    ve::T1
    alg::T2
end

Represents a standardised high-order moment risk measure algorithm in PortfolioOptimisers.jl.

Computes portfolio risk using a high-order moment algorithm (such as semi-skewness or semi-kurtosis), standardised by a variance estimator. This enables risk measures such as standardised semi-skewness or standardised semi-kurtosis, which normalise the risk by the portfolio variance.

Fields

  • ve: Variance estimator used for standardisation.

  • alg: Unstandardised high-order moment algorithm used to compute the risk measure.

Constructors

julia
StandardisedHighOrderMoment(;
                            ve::AbstractVarianceEstimator = SimpleVariance(; me = nothing),
                            alg::UnstandardisedHighOrderMomentMeasureAlgorithm = ThirdLowerMoment())

Keyword arguments correspond to the fields above.

Examples

julia
julia> StandardisedHighOrderMoment()
StandardisedHighOrderMoment
   ve ┼ SimpleVariance
      │          me ┼ nothing
      │           w ┼ nothing
      │   corrected ┴ Bool: true
  alg ┴ ThirdLowerMoment()

Related

source
PortfolioOptimisers.HighOrderMoment Type
julia
struct HighOrderMoment{T1, T2, T3, T4} <: HierarchicalRiskMeasure
    settings::T1
    w::T2
    mu::T3
    alg::T4
end

Represents a high-order moment risk measure in PortfolioOptimisers.jl.

Computes portfolio risk using a high-order moment algorithm (such as semi-skewness, semi-kurtosis, or kurtosis), optionally with custom weights and target values. This type is used for risk measures based on third or fourth moments of the return distribution.

Fields

  • settings: Risk measure configuration.

  • w: Optional vector of observation weights.

  • mu: Optional target scalar, vector, or VecScalar value for moment calculation that overrides the prior mu when provided. Also used to compute the moment target, via calc_moment_target. If nothing it is computed from the returns series using the optional weights in w.

  • alg: High-order moment risk measure algorithm.

Constructors

julia
HighOrderMoment(; settings::RiskMeasureSettings = RiskMeasureSettings(),
                w::Union{Nothing, <:AbstractWeights} = nothing,
                mu::Union{Nothing, <:Real, <:AbstractVector{<:Real}, <:VecScalar} = nothing,
                alg::HighOrderMomentMeasureAlgorithm = ThirdLowerMoment())

Keyword arguments correspond to the fields above.

Validation

  • If mu is not nothing:

    • ::Real: isfinite(mu).

    • ::AbstractVector: !isempty(mu) and all(isfinite, mu).

  • If w is not nothing, !isempty(w).

Formulations

Depending on the alg field, the risk measure is can compute the third lower moment, fourth lower (semi) moment, or fourth central (full) moment. Each can be standardised or unstandardised.

The unstandardised formulations are:

The standardised formulations are:

Unstandardised Moments

All unstandardised central moments have the following formula.

μn=E[(XE[X])n]

All unstandardised lower moments have the following formula.

μn=E[min(XE[X],0)n]

Standardised Moments

All standardised central moments have the following formula.

μn=E[(XE[X])n]E[(XE[X])2]n/2

All standardised lower moments have the following formula.

μn=E[min(XE[X],0)n]E[min(XE[X],0)2]n/2

Where:

  • X: T×1 vector of portfolio returns.

  • E[]: expected value operator, supports weighted averages.

  • : element-wise function application.

Functor

julia
(r::HighOrderMoment)(w::AbstractVector, X::AbstractMatrix;
                    fees::Union{Nothing, <:Fees} = nothing)

Computes the the high order moment risk measure as defined in r using portfolio weights w, return matrix X, and optional fees fees.

Details

  • r.alg defines what low-order moment to compute.

  • The values of r.mu and r.w are optionally used to compute the moment target via calc_moment_target, which is used in calc_deviations_vec to compute the deviation vector.

Examples

julia
julia> HighOrderMoment()
HighOrderMoment
  settings ┼ RiskMeasureSettings
           │   scale ┼ Float64: 1.0
           │      ub ┼ nothing
           │     rke ┴ Bool: true
         w ┼ nothing
        mu ┼ nothing
       alg ┴ ThirdLowerMoment()

Related

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

Abstract supertype for all moment-based risk measure algorithms in PortfolioOptimisers.jl.

Defines the interface for algorithms that compute portfolio risk using statistical moments (e.g., mean, variance, skewness, kurtosis) of the return distribution. All concrete moment risk measure algorithms should subtype MomentMeasureAlgorithm to ensure consistency and composability within the risk measure framework.

Related Types

source
PortfolioOptimisers.LowOrderMomentMeasureAlgorithm Type
julia
abstract type LowOrderMomentMeasureAlgorithm <: MomentMeasureAlgorithm end

Abstract supertype for all low-order moment-based risk measure algorithms in PortfolioOptimisers.jl.

Defines the interface for algorithms that compute portfolio risk using low-order statistical moments (e.g., mean, variance, mean absolute deviation) of the return distribution. All concrete low-order moment risk measure algorithms should subtype LowOrderMomentMeasureAlgorithm to ensure consistency and composability within the risk measure framework.

Related Types

source
PortfolioOptimisers.UnstandardisedLowOrderMomentMeasureAlgorithm Type
julia
abstract type UnstandardisedLowOrderMomentMeasureAlgorithm <: LowOrderMomentMeasureAlgorithm end

Abstract supertype for low-order moment risk measure algorithms that are not standardised by the variance in PortfolioOptimisers.jl.

Defines the interface for algorithms that compute portfolio risk using low-order statistical moments without normalising by the variance. All concrete unstandardised low-order moment risk measure algorithms should subtype UnstandardisedLowOrderMomentMeasureAlgorithm to ensure consistency and composability within the risk measure framework.

Related Types

source
PortfolioOptimisers.HighOrderMomentMeasureAlgorithm Type
julia
abstract type HighOrderMomentMeasureAlgorithm <: MomentMeasureAlgorithm end

Abstract supertype for all high-order moment-based risk measure algorithms in PortfolioOptimisers.jl.

Defines the interface for algorithms that compute portfolio risk using high-order statistical moments (e.g., skewness, kurtosis) of the return distribution. All concrete high-order moment risk measure algorithms should subtype HighOrderMomentMeasureAlgorithm to ensure consistency and composability within the risk measure framework.

Related Types

source
PortfolioOptimisers.UnstandardisedHighOrderMomentMeasureAlgorithm Type
julia
abstract type UnstandardisedHighOrderMomentMeasureAlgorithm <: HighOrderMomentMeasureAlgorithm end

Abstract supertype for high-order moment risk measure algorithms that are not standardised by the variance in PortfolioOptimisers.jl.

Defines the interface for algorithms that compute portfolio risk using high-order statistical moments (such as skewness, kurtosis) without normalising by the variance. All concrete unstandardised high-order moment risk measure algorithms should subtype UnstandardisedHighOrderMomentMeasureAlgorithm to ensure consistency and composability within the risk measure framework.

Related Types

source
PortfolioOptimisers.calc_moment_target Method
julia
calc_moment_target(::Union{<:LowOrderMoment{<:Any, Nothing, Nothing, <:Any},
                           <:HighOrderMoment{<:Any, Nothing, Nothing, <:Any}},
                   ::Any, x::AbstractVector)

Compute the target value for moment calculations when neither a target value (mu) nor observation weights are provided in the risk measure.

Arguments

  • r: A LowOrderMoment or HighOrderMoment risk measure with both w and mu fields set to nothing.

  • _: Unused argument (typically asset weights, ignored in this method).

  • x: Returns vector.

Returns

  • target::eltype(x): The mean of the returns vector.

Related

source
PortfolioOptimisers.calc_moment_target Method
julia
calc_moment_target(r::Union{<:LowOrderMoment{<:Any, <:AbstractWeights, Nothing, <:Any},
                            <:HighOrderMoment{<:Any, <:AbstractWeights, Nothing, <:Any}},
                   ::Any, x::AbstractVector)

Compute the target value for moment calculations when the risk measure provides an observation weights vector but no explicit target value (mu).

Arguments

  • r: A LowOrderMoment or HighOrderMoment risk measure with w set to an observation weights vector and mu set to nothing.

  • _: Unused argument (typically asset weights, ignored in this method).

  • x: Returns vector.

Returns

  • target::eltype(x): The weighted mean of the returns vector, using the observation weights from r.w.

Related

source
PortfolioOptimisers.calc_moment_target Method
julia
calc_moment_target(r::Union{<:LowOrderMoment{<:Any, <:Any, <:AbstractVector, <:Any},
                            <:HighOrderMoment{<:Any, <:Any, <:AbstractVector, <:Any}},
                   w::AbstractVector, ::Any)

Compute the target value for moment calculations when the risk measure provides an explicit expected returns vector (mu).

Arguments

  • r: A LowOrderMoment or HighOrderMoment risk measure with mu set to an expected returns vector.

  • w: Asset weights vector.

  • ::Any: Unused argument (typically the returns vector, ignored in this method).

Returns

  • target::eltype(w): The dot product of the asset weights and the expected returns vector.

Related

source
PortfolioOptimisers.calc_moment_target Method
julia
calc_moment_target(r::Union{<:LowOrderMoment{<:Any, <:Any, <:VecScalar, <:Any},
                            <:HighOrderMoment{<:Any, <:Any, <:VecScalar, <:Any}},
                   w::AbstractVector, ::Any)

Compute the target value for moment calculations when the risk measure provides a VecScalar as the expected returns (mu).

Arguments

  • r: A LowOrderMoment or HighOrderMoment risk measure with mu set to a VecScalar (an object with fields v for the expected returns vector and s for a scalar offset).

  • w: Asset weights vector.

  • ::Any: Unused argument (typically the returns vector, ignored in this method).

Returns

  • target::promote_type(eltype(w), eltype(r.mu.v), typeof(r.mu.s)): The sum of the dot product of the asset weights and the expected returns vector plus the scalar offset, dot(w, r.mu.v) + r.mu.s.

Related

source
PortfolioOptimisers.calc_moment_target Method
julia
calc_moment_target(r::Union{<:LowOrderMoment{<:Any, <:Any, <:Real, <:Any},
                            <:HighOrderMoment{<:Any, <:Any, <:Real, <:Any}}, ::Any, ::Any)

Compute the target value for moment calculations when the risk measure provides a scalar value for the expected returns (mu).

Arguments

  • r: A LowOrderMoment or HighOrderMoment risk measure with mu set to a scalar value.

  • ::Any: Unused argument (typically asset weights, ignored in this method).

  • ::Any: Unused argument (typically the returns vector, ignored in this method).

Returns

  • target::Real: The scalar value of r.mu.

Related

source
PortfolioOptimisers.calc_deviations_vec Function
julia
calc_deviations_vec(r::Union{<:LowOrderMoment, <:HighOrderMoment}, w::AbstractVector,
                X::AbstractMatrix; fees::Union{Nothing, <:Fees} = nothing)

Compute the vector of deviations from the target value for moment-based risk measures.

Arguments

  • r: A LowOrderMoment or HighOrderMoment risk measure specifying the moment calculation algorithm and target.

  • w: Asset weights vector.

  • X: Return matrix.

  • fees: Optional fees object to adjust net returns.

Returns

  • val::AbstractVector: The vector of deviations between net portfolio returns and the computed moment target.

Details

  • Computes net portfolio returns using the provided weights, return matrix, and optional fees.

  • Computes the target value for the moment calculation using calc_moment_target.

  • Returns the element-wise difference between net returns and the target value.

Related

source