Skip to content
13

Non-Optimisation Risk Measures

PortfolioOptimisers.MeanReturn Type
julia
struct MeanReturn{__T_w, __T_flag} <: NonOptimisationRiskMeasure

Represents a simple mean return measure for use in non-optimisation contexts.

MeanReturn computes the arithmetic (or geometric, when flag = true) mean of portfolio returns. It is used as the numerator in risk-adjusted performance ratios such as MeanReturnRiskRatio.

Mathematical definition

For flag = false (arithmetic mean):

x¯=1Tt=1Txt.

Where:

  • x¯: Arithmetic mean portfolio return.

  • x: Portfolio returns vector T×1.

  • T: Number of observations.

For flag = true (log-return mean):

x¯log=1Tt=1Tlog(1+xt).

Where:

  • x¯log: Log-return mean portfolio return.

  • x: Portfolio returns vector T×1.

  • T: Number of observations.

For observation-weighted samples, the weighted mean is used instead.

Fields

  • w: Optional portfolio weights.

  • flag: Algorithm selection flag.

Constructors

julia
MeanReturn(;
    w::Option{<:ObsWeights} = nothing,
    flag::Bool = false
) -> MeanReturn

Keywords correspond to the struct's fields.

Validation

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

Functor

julia
(r::MeanReturn)(x::VecNum)

Computes the mean return of a portfolio returns vector x.

Arguments

  • x::VecNum: Portfolio returns vector.

Examples

julia
julia> MeanReturn()
MeanReturn
     w ┼ nothing
  flag ┴ Bool: false

Related

source
PortfolioOptimisers.factory Method
julia
factory(
    r::MeanReturn,
    pr::AbstractPriorResult,
    args...
) -> MeanReturn{_A, Bool} where _A

Create an instance of MeanReturn by selecting observation weights from the risk-measure instance or falling back to the prior result.

Related

source
PortfolioOptimisers.port_opt_view Method
julia
port_opt_view(r::MeanReturn, _, args...) -> MeanReturn

Return the MeanReturn risk measure r unchanged.

MeanReturn does not have asset-level parameters to slice.

Related

source
PortfolioOptimisers.MeanReturnRiskRatio Type
julia
struct MeanReturnRiskRatio{__T_rt, __T_rk, __T_rf} <: NonOptimisationRiskMeasure

Represents a mean return to risk ratio measure.

MeanReturnRiskRatio computes the ratio of the mean portfolio return (minus a risk-free rate) to a risk measure, used for performance analysis and comparison. It generalises the Sharpe ratio by allowing any risk measure in the denominator.

Mathematical definition

MRRR(x)=x¯rfρ(x).

Where:

  • MRRR(x): Mean return to risk ratio.

  • x: Portfolio returns vector T×1.

  • x¯: Mean portfolio return (computed by rt).

  • rf: Risk-free rate.

  • ρ: Base risk measure (computed by rk).

Fields

  • rt: Mean return estimator.

  • rk: Risk measure for ratio computation.

  • rf: Risk-free rate.

Constructors

julia
MeanReturnRiskRatio(;
    rt::MeanReturn = MeanReturn(),
    rk::AbstractBaseRiskMeasure = ConditionalValueatRisk(),
    rf::Number = 0.0
) -> MeanReturnRiskRatio

Keywords correspond to the struct's fields.

Related

source
PortfolioOptimisers.needs_previous_weights Method
julia
needs_previous_weights(r::MeanReturnRiskRatio) -> Any

Return whether MeanReturnRiskRatio r requires previous portfolio weights.

Delegates to the inner risk measure r.rk.

Related

source
PortfolioOptimisers.factory Method
julia
factory(
    r::MeanReturnRiskRatio,
    args...;
    kwargs...
) -> MeanReturnRiskRatio{MeanReturn{__T_w, __T_flag}, <:AbstractBaseRiskMeasure, <:Number} where {__T_w, __T_flag}

Create an instance of MeanReturnRiskRatio by updating both the return measure and risk measure from the optimisation context.

Related

source
PortfolioOptimisers.factory Method
julia
factory(
    r::MeanReturnRiskRatio,
    w::AbstractVector{<:Union{var"#s20", var"#s19"} where {var"#s20"<:Number, var"#s19"<:AbstractJuMPScalar}}
) -> MeanReturnRiskRatio{MeanReturn{__T_w, __T_flag}, <:AbstractBaseRiskMeasure, <:Number} where {__T_w, __T_flag}

Create an instance of MeanReturnRiskRatio updating the risk measure from new portfolio weights w.

The return measure rt is preserved unchanged.

Related

source
PortfolioOptimisers.ThirdCentralMoment Type
julia
struct ThirdCentralMoment{__T_w, __T_mu} <: NonOptimisationRiskMeasure

Represents the Third Central Moment risk measure.

ThirdCentralMoment computes the third central moment of portfolio returns about a specified centre. It is used as a measure of the asymmetry (skewness) of the return distribution in higher-order portfolio optimisation.

Mathematical definition

Let μ be the specified centre and δt=xtμ the centred deviations. The third central moment is:

m3(x)=1Tt=1Tδt3.

Where:

  • m3(x): Third central moment of portfolio returns.

  • x: Portfolio returns vector T×1.

  • T: Number of observations.

  • μ: Specified centre of the distribution.

  • δt=xtμ: Centred deviation at period t.

For observation-weighted samples, the weighted mean is used.

Fields

  • w: Optional portfolio weights.

  • mu: Optional mean for centering.

Constructors

julia
ThirdCentralMoment(;
    w::Option{<:ObsWeights} = nothing,
    mu::Option{<:Num_VecNum_VecScalar} = nothing
) -> ThirdCentralMoment

Keywords correspond to the struct's fields.

Validation

  • If mu is a VecNum: !isempty(mu).

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

Functor

julia
(r::ThirdCentralMoment)(w::VecNum, X::MatNum, fees = nothing)

Computes the third central moment of the portfolio returns.

Arguments

  • w::VecNum: Portfolio weights vector.

  • X::MatNum: Asset returns matrix (T×N).

  • fees: Optional fee structure.

Examples

julia
julia> ThirdCentralMoment()
ThirdCentralMoment
   w ┼ nothing
  mu ┴ nothing

Related

source
PortfolioOptimisers.factory Method
julia
factory(
    r::ThirdCentralMoment,
    pr::AbstractPriorResult,
    args...;
    kwargs...
) -> ThirdCentralMoment

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

Related

source
PortfolioOptimisers.port_opt_view Method
julia
port_opt_view(
    r::ThirdCentralMoment,
    i,
    args...
) -> ThirdCentralMoment

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

Slices the expected returns mu for cluster-based optimisation.

Related

source
PortfolioOptimisers.TCM_Sk Type
julia
const TCM_Sk{T1, T2} = Union{<:ThirdCentralMoment{T1, T2}, <:Skewness{<:Any, <:Any, T1, T2}}

Parameterised union of ThirdCentralMoment and Skewness sharing the same observation-weight (T1) and target-mean (T2) type parameters.

Used for unified dispatch on moment-target calculation methods.

Related

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

Compute the centering target for ThirdCentralMoment and Skewness risk measures.

Dispatches on the observation-weight type T1 and mean type T2 of TCM_Sk:

  • No weights, no mu: arithmetic mean of x.

  • AbstractWeights, no mu: weighted mean of x.

  • VecNum mu: dot product wμ.

  • VecScalar mu: wμv+μs.

  • Number mu: the scalar r.mu directly.

Related

source
PortfolioOptimisers.calc_deviations_vec Function
julia
calc_deviations_vec(
    r::Union{ThirdCentralMoment{T1, T2}, Skewness{<:Any, <:Any, <:Any, T1, T2}} where {T1, T2},
    w::AbstractVector{<:Union{var"#s20", var"#s19"} where {var"#s20"<:Number, var"#s19"<:AbstractJuMPScalar}},
    X::AbstractMatrix{<:Union{var"#s20", var"#s19"} where {var"#s20"<:Number, var"#s19"<:AbstractJuMPScalar}}
) -> Any
calc_deviations_vec(
    r::Union{ThirdCentralMoment{T1, T2}, Skewness{<:Any, <:Any, <:Any, T1, T2}} where {T1, T2},
    w::AbstractVector{<:Union{var"#s20", var"#s19"} where {var"#s20"<:Number, var"#s19"<:AbstractJuMPScalar}},
    X::AbstractMatrix{<:Union{var"#s20", var"#s19"} where {var"#s20"<:Number, var"#s19"<:AbstractJuMPScalar}},
    fees::Union{Nothing, Fees}
) -> Any

Compute the vector of deviations from the centering target for ThirdCentralMoment and Skewness risk measures.

Related

source
PortfolioOptimisers.calc_deviations_vec Method
julia
calc_deviations_vec(
    r::Union{ThirdCentralMoment{T1, T2}, Skewness{<:Any, <:Any, <:Any, T1, T2}} where {T1, T2},
    x::AbstractVector{<:Union{var"#s20", var"#s19"} where {var"#s20"<:Number, var"#s19"<:AbstractJuMPScalar}}
) -> Any

Compute the vector of deviations from the centering target for a precomputed returns series for ThirdCentralMoment and Skewness risk measures.

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

Related

source
PortfolioOptimisers.supports_precomputed_returns Method
julia
supports_precomputed_returns(r::ThirdCentralMoment) -> Any

Return whether ThirdCentralMoment 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