Skip to content
13

Moment Risk Measures

PortfolioOptimisers.FirstLowerMoment Type
julia
struct FirstLowerMoment <: UnstandardisedLowOrderMomentMeasureAlgorithm

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

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{__T_ve, __T_alg1, __T_alg2} <: LowOrderMomentMeasureAlgorithm

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.

  • alg1: First algorithm variant.

  • alg2: Second algorithm variant.

Constructors

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

Keywords correspond to the struct's fields.

Examples

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

Related

source
PortfolioOptimisers.factory Method
julia
factory(
    alg::SecondMoment,
    w::Union{DynamicAbstractWeights, AbstractWeights}
) -> SecondMoment{<:AbstractVarianceEstimator, <:AbstractMomentAlgorithm, <:SecondMomentFormulation}

Return a new SecondMoment with observation weights w applied to the underlying variance estimator.

Related

source
PortfolioOptimisers.EvenMoment Type
julia
struct EvenMoment{__T_p, __T_ddof, __T_alg} <: UnstandardisedLowOrderMomentMeasureAlgorithm

Represents an even-order moment risk measure algorithm in PortfolioOptimisers.jl.

Computes portfolio risk using the 2p-th central (full) or lower (semi) even moment of the return distribution. Despite the potentially high moment order, even moments admit an exact power cone reformulation, keeping the optimisation formulation affine.

Fields

  • p: Power or order parameter.

  • ddof: Degrees-of-freedom correction.

  • alg: Moment algorithm.

Constructors

julia
EvenMoment(;
    p::Integer = 2,
    ddof::Integer = 0,
    alg::AbstractMomentAlgorithm = Full(),
) -> EvenMoment

Keywords correspond to the struct's fields.

Validation

  • p >= 2.

  • ddof >= 0 and isfinite(ddof).

Examples

julia
julia> EvenMoment()
EvenMoment
     p ┼ Int64: 2
  ddof ┼ Int64: 0
   alg ┴ Full()

Related

source
PortfolioOptimisers.LowOrderMoment Type
julia
struct LowOrderMoment{__T_settings, __T_w, __T_mu, __T_alg} <: RiskMeasure

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 settings.

  • w: Optional portfolio weights.

  • mu: Optional mean for centering.

  • alg: Moment algorithm.

Constructors

julia
LowOrderMoment(;
    settings::RiskMeasureSettings = RiskMeasureSettings(),
    w::Option{<:ObsWeights} = nothing,
    mu::Option{<:Num_VecNum_VecScalar} = nothing,
    alg::LowOrderMomentMeasureAlgorithm = FirstLowerMoment(),
) -> LowOrderMoment

Keywords correspond to the struct's fields.

Validation

  • If mu is not nothing:

    • ::Number: isfinite(mu).

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

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

Mathematical definition

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.

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.

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.

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.

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.

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.

  • λ: 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.

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.

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.

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.

EvenMoment

EvenMoment computes the 2p-th central (full) or lower (semi) moment of the return distribution. Although the moment order 2p4 can be arbitrarily high, EvenMoment is not a low-order moment in the classical sense. However, because the exponent is always even, the moment can be expressed as an iterated power of squared deviations, admitting an exact reformulation using power cone constraints. This makes the optimisation problem affine and solvable by standard conic solvers.

The full (central) even moment is computed as:

EvenMomentp(X)=(1Tdt=1T(XtE[X])2p)1/p.

The semi (lower) even moment is computed as:

Semi-EvenMomentp(X)=(1Tdt=1Tmin(XtE[X],0)2p)1/p.

Where:

  • X: T × 1 vector of portfolio returns.

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

  • Td=Tddof: Effective sample size after degrees-of-freedom correction.

  • p2: Order parameter; the moment order is 2p.

  • : Element-wise function application.

As an optimisation problem, the full even moment is formulated using a chain of power cone constraints:

optw,u,s,rrs.t.t=1Tutr(utTd,r,st)Kpow(1p),t=1,,T(st,k,r^tμ)Kpow(12),t=1,,T.

The semi even moment is formulated as:

optw,u,s,d,rrs.t.t=1Tutr(utTd,r,st)Kpow(1p),t=1,,T(st,k,dt)Kpow(12),t=1,,Tr^tμ+dt0,t=1,,Tdt0,t=1,,T.

Where:

  • w: N × 1 asset weights vector.

  • r: Even-moment risk variable.

  • u: T × 1 auxiliary variable vector.

  • s: T × 1 auxiliary variable vector.

  • d: T × 1 lower-deviation auxiliary variables, capturing returns below the target.

  • Td: Effective sample size.

  • k: Budget-scaling / homogenisation variable.

  • p: Order parameter; the moment order is 2p.

  • X: T × N return matrix.

  • r^t=xtw: Portfolio return at time t.

  • μ: Target return.

  • Kpow(α): Power cone {(a,b,c):aαb1α|c|,a,b0}.

Functor

julia
(r::LowOrderMoment)(w::VecNum, X::MatNum;
                    fees::Option{<: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

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{__T_alg} <: UnstandardisedHighOrderMomentMeasureAlgorithm

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.

Constructors

julia
FourthMoment(;
    alg::AbstractMomentAlgorithm = Full(),
) -> FourthMoment

Keywords correspond to the struct's fields.

Examples

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

Related

source
PortfolioOptimisers.StandardisedHighOrderMoment Type
julia
struct StandardisedHighOrderMoment{__T_ve, __T_alg} <: HighOrderMomentMeasureAlgorithm

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.

Fields

  • ve: Variance estimator.

  • alg: Moment algorithm.

Constructors

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

Keywords correspond to the struct's fields.

Examples

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

Related

source
PortfolioOptimisers.factory Method
julia
factory(
    alg::StandardisedHighOrderMoment,
    w::Union{DynamicAbstractWeights, AbstractWeights}
) -> StandardisedHighOrderMoment{<:AbstractVarianceEstimator, <:UnstandardisedHighOrderMomentMeasureAlgorithm}

Return a new StandardisedHighOrderMoment with observation weights w applied to the underlying variance estimator.

Related

source
PortfolioOptimisers.HighOrderMoment Type
julia
struct HighOrderMoment{__T_settings, __T_w, __T_mu, __T_alg} <: HierarchicalRiskMeasure

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 settings.

  • w: Optional portfolio weights.

  • mu: Optional mean for centering.

  • alg: Moment algorithm.

Constructors

julia
HighOrderMoment(;
    settings::RiskMeasureSettings = RiskMeasureSettings(),
    w::Option{<:ObsWeights} = nothing,
    mu::Option{<:Num_VecNum_VecScalar} = nothing,
    alg::HighOrderMomentMeasureAlgorithm = ThirdLowerMoment(),
) -> HighOrderMoment

Keywords correspond to the struct's fields.

Validation

  • If mu is not nothing:

    • ::Number: isfinite(mu).

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

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

Mathematical definition

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].

Where:

  • μn: n-th central moment.

  • X: T × 1 vector of portfolio returns.

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

  • n: Moment order.

All unstandardised lower moments have the following formula.

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

Where:

  • μn: n-th lower moment.

  • X: T × 1 vector of portfolio returns.

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

  • : Element-wise function application.

  • n: Moment order.

Standardised Moments

All standardised central moments have the following formula.

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

Where:

  • μn: n-th standardised central moment.

  • X: T × 1 vector of portfolio returns.

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

  • n: Moment order.

All standardised lower moments have the following formula.

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

Where:

  • μn: n-th standardised lower moment.

  • X: T × 1 vector of portfolio returns.

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

  • : Element-wise function application.

  • n: Moment order.

Functor

julia
(r::HighOrderMoment)(w::VecNum, X::MatNum;
                    fees::Option{<: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

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.factory Method
julia
factory(
    alg::MomentMeasureAlgorithm,
    args...;
    kwargs...
) -> SecondMoment{<:AbstractVarianceEstimator, <:AbstractMomentAlgorithm, <:SecondMomentFormulation}

Return the moment measure algorithm alg unchanged.

Identity pass-through used when a moment measure algorithm is provided in a context that calls factory.

Related

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

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

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

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

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.LoHiOrderMoment Type
julia
const LoHiOrderMoment{T1, T2, T3, T4} = Union{...}

Parameterised union of LowOrderMoment and HighOrderMoment sharing the same type parameters.

Used for unified dispatch on moment-target calculation methods.

Related

source
PortfolioOptimisers.calc_moment_target Method
julia
calc_moment_target(::LoHiOrderMoment{<:Any, Nothing, Nothing, <:Any},
                   ::Any, x::VecNum)

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

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

Related

source
PortfolioOptimisers.calc_moment_target Method
julia
calc_moment_target(r::LoHiOrderMoment{<:Any, <:StatsBase.AbstractWeights, Nothing, <:Any},
                   ::Any, x::VecNum)

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

  • tgt::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::LoHiOrderMoment{<:Any, <:Any, <:VecNum, <:Any},
                   w::VecNum, ::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

  • tgt::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::LoHiOrderMoment{<:Any, <:Any, <:VecScalar, <:Any},
                   w::VecNum, ::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

  • tgt::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, LinearAlgebra.dot(w, r.mu.v) + r.mu.s.

Related

source
PortfolioOptimisers.calc_moment_target Method
julia
calc_moment_target(r::LoHiOrderMoment{<:Any, <:Any, <:Number, <: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

  • tgt::Number: The scalar value of r.mu.

Related

source
PortfolioOptimisers.calc_deviations_vec Function
julia
calc_deviations_vec(r::LoHiOrderMoment, w::VecNum,
                X::MatNum; fees::Option{<: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
PortfolioOptimisers.calc_deviations_vec Method
julia
calc_deviations_vec(
    r::Union{HighOrderMoment{T1, T2, T3, T4}, LowOrderMoment{T1, T2, T3, T4}} where {T1, T2, T3, T4},
    x::AbstractVector{<:Union{var"#s20", var"#s19"} where {var"#s20"<:Number, var"#s19"<:AbstractJuMPScalar}}
) -> Any

Compute the vector of deviations from the target value for a precomputed returns series.

Single-argument form of calc_deviations_vec used by the precomputed-returns functor r(x::VecNum) (ADR 0007).

Related

source
PortfolioOptimisers.factory Method
julia
factory(
    r::LowOrderMoment,
    pr::AbstractPriorResult,
    args...;
    kwargs...
) -> LowOrderMoment{RiskMeasureSettings{__T_scale, __T_ub, __T_rke}, _A, _B, <:LowOrderMomentMeasureAlgorithm} where {__T_scale, __T_ub, __T_rke, _A, _B}

Create an instance of LowOrderMoment by selecting observation weights, expected returns, and algorithm from the risk-measure instance or falling back to the prior result.

Related

source
PortfolioOptimisers.port_opt_view Method
julia
port_opt_view(
    r::LowOrderMoment,
    i,
    args...
) -> LowOrderMoment{RiskMeasureSettings{__T_scale, __T_ub, __T_rke}, _A, _B, <:LowOrderMomentMeasureAlgorithm} where {__T_scale, __T_ub, __T_rke, _A, _B}

Return a view of LowOrderMoment r sliced to asset indices i.

Slices the expected returns mu for cluster-based optimisation.

Related

source
PortfolioOptimisers.factory Method
julia
factory(
    r::HighOrderMoment,
    pr::AbstractPriorResult,
    args...;
    kwargs...
) -> HighOrderMoment{RiskMeasureSettings{__T_scale, __T_ub, __T_rke}, _A, _B, <:HighOrderMomentMeasureAlgorithm} where {__T_scale, __T_ub, __T_rke, _A, _B}

Create an instance of HighOrderMoment by selecting observation weights, expected returns, and algorithm from the risk-measure instance or falling back to the prior result.

Related

source
PortfolioOptimisers.port_opt_view Method
julia
port_opt_view(
    r::HighOrderMoment,
    i,
    args...
) -> HighOrderMoment{RiskMeasureSettings{__T_scale, __T_ub, __T_rke}, _A, _B, <:HighOrderMomentMeasureAlgorithm} where {__T_scale, __T_ub, __T_rke, _A, _B}

Return a view of HighOrderMoment r sliced to asset indices i.

Slices the expected returns mu for cluster-based optimisation.

Related

source
PortfolioOptimisers.supports_precomputed_returns Method
julia
supports_precomputed_returns(
    r::Union{HighOrderMoment{T1, T2, T3, T4}, LowOrderMoment{T1, T2, T3, T4}} where {T1, T2, T3, T4}
) -> Any

Return whether LoHiOrderMoment r supports precomputed-return evaluation.

Delegates to weight_independent_target on r.mu: true iff the target is Nothing, a Number, or a MedianCenteringFunction; false for per-asset targets.

Related

source
PortfolioOptimisers._moment_risk Function
julia
_moment_risk(r::LoHiOrderMoment, val::VecNum)
_moment_risk(r::Kurtosis, val::VecNum)
_moment_risk(r::Skewness, val::VecNum)
_moment_risk(r::MedianAbsoluteDeviation, val::VecNum)
_moment_risk(r::ThirdCentralMoment, val::VecNum)

Shared post-deviation kernel for the moment-family risk measures. Given the vector of deviations val (net portfolio returns minus the measure's target, from calc_deviations_vec), compute the measure's scalar value. Dispatch selects the per-algorithm reduction (lower/full, the power, the standardisation, the formulation).

Both functor arities funnel through this kernel: r(w, X, fees) calls _moment_risk(r, calc_deviations_vec(r, w, X, fees)), and the single-argument precomputed-returns form r(x::VecNum) calls _moment_risk(r, calc_deviations_vec(r, x)), so the two share one definition of the math (ADR 0007).

Related

source