Skip to content
13

Median Absolute Deviation Risk

PortfolioOptimisers.MedianCenteringFunction Type
julia
abstract type MedianCenteringFunction <: AbstractAlgorithm

Abstract supertype for centering functions used in the Median Absolute Deviation risk measure.

Related Types

source
PortfolioOptimisers.MedianCentering Type
julia
struct MedianCentering <: MedianCenteringFunction

Centres the returns series using the (weighted) median before computing the Median Absolute Deviation.

Related Types

source
PortfolioOptimisers.MeanCentering Type
julia
struct MeanCentering <: MedianCenteringFunction

Centres the returns series using the (weighted) mean before computing the Median Absolute Deviation.

Related Types

source
PortfolioOptimisers.MedAbsDevMu Type
julia
const MedAbsDevMu = Union{<:Num_VecNum_VecScalar, <:MedianCenteringFunction}

Union of valid centring-target types for MedianAbsoluteDeviation.

Accepts a numeric scalar/vector target or a MedianCenteringFunction (e.g. mean or median centering).

Related

source
PortfolioOptimisers.MedianAbsoluteDeviation Type
julia
struct MedianAbsoluteDeviation{__T_settings, __T_w, __T_mu, __T_flag} <: HierarchicalRiskMeasure

Represents the Median Absolute Deviation (MAD) risk measure for hierarchical portfolio optimisation.

MedianAbsoluteDeviation computes the median (or mean) absolute deviation of portfolio returns about a specified centre, providing a robust alternative to variance for measuring dispersion.

Mathematical definition

Let μ be the chosen centre (median or mean of returns, or a user-supplied value). Define the deviations δt=xtμ. The MAD is:

MAD(x)=median1tT(|δt|).

Where:

  • MAD(x): Median absolute deviation of portfolio returns.

  • x: Portfolio returns vector T×1.

  • T: Number of observations.

  • μ: Chosen centre (median, mean, or user-supplied value).

  • δt=xtμ: Deviation of return at period t from the centre.

When flag = true (default), the result is scaled by a consistency factor (Φ1(3/4))11.4826 so that the MAD is a consistent estimator of the standard deviation under normality.

Fields

  • settings: Risk measure settings.

  • w: Optional portfolio weights.

  • mu: Optional mean for centering.

  • flag: Algorithm selection flag.

Constructors

julia
MedianAbsoluteDeviation(;
    settings::HierarchicalRiskMeasureSettings = HierarchicalRiskMeasureSettings(),
    w::Option{<:ObsWeights} = nothing,
    mu::MedAbsDevMu = MedianCentering(),
    flag::Bool = true
) -> MedianAbsoluteDeviation

Keywords correspond to the struct's fields.

Validation

  • If mu is a VecNum: !isempty(mu) and all(isfinite, mu).

  • If mu is a Number: isfinite(mu).

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

Functor

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

Computes the MAD of the portfolio returns series.

Arguments

  • w::VecNum: Portfolio weights vector.

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

  • fees: Optional fee structure.

Examples

julia
julia> MedianAbsoluteDeviation()
MedianAbsoluteDeviation
  settings ┼ HierarchicalRiskMeasureSettings
           │   scale ┴ Float64: 1.0
         w ┼ nothing
        mu ┼ MedianCentering()
      flag ┴ Bool: true

Related

source
PortfolioOptimisers.factory Method
julia
factory(
    r::MedianAbsoluteDeviation,
    pr::AbstractPriorResult,
    args...;
    kwargs...
) -> MedianAbsoluteDeviation{__T_settings, __T_w, __T_mu, Bool} where {__T_settings, __T_w, __T_mu}

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

Related

source
PortfolioOptimisers.nothing_scalar_array_view Method
julia
nothing_scalar_array_view(
    x::MedianCenteringFunction,
    _
) -> MedianCenteringFunction

Return the MedianCenteringFunction x unchanged.

Identity pass-through: centering functions are not sliced by asset index.

Related

source
PortfolioOptimisers.port_opt_view Method
julia
port_opt_view(
    r::MedianAbsoluteDeviation,
    i,
    args...
) -> MedianAbsoluteDeviation{HierarchicalRiskMeasureSettings{__T_scale}, _A, _B, Bool} where {__T_scale, _A, _B}

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

Slices the centering target mu for cluster-based optimisation.

Related

source
PortfolioOptimisers.calc_moment_target Method
julia
calc_moment_target(::MedianAbsoluteDeviation{<:Any, Nothing, <:MeanCentering, ...}, ::Any, x::VecNum)
calc_moment_target(r::MedianAbsoluteDeviation{<:Any, <:ObsWeights, <:MeanCentering, ...}, ::Any, x::VecNum)
calc_moment_target(::MedianAbsoluteDeviation{<:Any, Nothing, <:MedianCentering, ...}, ::Any, x::VecNum)
calc_moment_target(r::MedianAbsoluteDeviation{<:Any, <:ObsWeights, <:MedianCentering, ...}, ::Any, x::VecNum)
calc_moment_target(r::MedianAbsoluteDeviation{<:Any, <:Any, <:VecNum, ...}, w::VecNum, ::Any)
calc_moment_target(r::MedianAbsoluteDeviation{<:Any, <:Any, <:Number, ...}, ::Any, ::Any)
calc_moment_target(r::MedianAbsoluteDeviation{<:Any, <:Any, <:VecScalar, ...}, w::VecNum, ::Any)

Compute the centering target for MedianAbsoluteDeviation risk measure calculations.

Dispatches on the type of r.w and r.mu:

  • No weights + MeanCentering: arithmetic mean of x.

  • ObsWeights + MeanCentering: weighted mean of x.

  • No weights + MedianCentering: median of x.

  • ObsWeights + MedianCentering: weighted median of x.

  • VecNum mu: dot product wμ.

  • Number mu: the scalar r.mu directly.

  • VecScalar mu: wμv+μs.

Related

source
PortfolioOptimisers.calc_deviations_vec Function
julia
calc_deviations_vec(
    r::MedianAbsoluteDeviation,
    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::MedianAbsoluteDeviation,
    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 MedianAbsoluteDeviation risk measures.

Related

source
PortfolioOptimisers.calc_deviations_vec Method
julia
calc_deviations_vec(
    r::MedianAbsoluteDeviation,
    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 MedianAbsoluteDeviation.

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

Related

source
PortfolioOptimisers.weight_independent_target Method
julia
weight_independent_target(
    _::MedianCenteringFunction
) -> Bool

Return true: MedianCenteringFunction targets are weight-independent centering functions and can be evaluated on a bare return series.

Related

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

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