Tyler covariance: private API

PortfolioOptimisers.show_fields — Method
show_fields(_::TylerCovariance) -> NTuple{5, Symbol}

Renders every field of a TylerCovariance except cache.

A cache holds the state of an incremental fit, not a part of the configuration. Set set_show_nothing_fields!(:TylerCovariance, true) to render it.

Arguments

  • ::TylerCovariance: The estimator, read for its type alone.

Returns

  • fields::Tuple: The names of the fields to render, (:me, :ve, :shr, :w, :q).

Related

source
PortfolioOptimisers.away_from_centre — Function
away_from_centre(d2::VecNum) -> BitVector

Marks the observations that have a direction from the centre in a fit of TylerCovariance.

An observation at the centre has the squared distance zero, so its term in the equations of the fixed point is not defined. The function reads a distance of at most eps times the median of the distances as zero.

Arguments

  • d2: The squared distance of each observation.

Returns

  • pos::BitVector: The observations away from the centre.

Related

source
PortfolioOptimisers.tyler_fixed_point — Function
tyler_fixed_point(X::MatNum, w::Option{<:StatsBase.AbstractWeights},
                  centre::Option{<:VecNum}, reg::Option{<:ShapeShrinkage})
    -> Tuple{VecNum, MatNum}

Solves the fixed-point equations of TylerCovariance for the shape and, with no fixed centre, for the location.

Algorithm

  1. Start the location at the coordinatewise weighted median, or at centre. Start the shape at the diagonal matrix of the squares of the robust scales of the centred columns, from robust_column_scale, scaled to the trace p. The start does not move the fixed point, and an outlier of any size does not make it singular.
  2. Repeat at most TYLER_MAX_ITER times:
    1. Compute the squared distances d2 in the metric of the shape with squared_distances. An observation that away_from_centre does not mark leaves both sums.
    2. Update the shape with tyler_shape_step, and scale it to the trace p, or shrink it with shrink_shape!.
    3. With no fixed centre, update the location with spatial_median_step.
    4. Stop when the relative change of the shape and the change of the location in the metric of the shape are both below sqrt(eps).
  3. Warn when the iterations do not converge, and return the last iterate.

Arguments

  • X: The data matrix, observations × assets.
  • w: The observation weights, or nothing.
  • centre: The fixed centre, or nothing.
  • reg: The shrinkage to the identity matrix, or nothing.

Returns

  • (mu, V): The location and the shape. The shape has the trace p, unless the form of reg is PenalisedShrinkage.

Related

References

  • [122] D. E. Tyler. A distribution-free M-estimator of multivariate scatter. The Annals of Statistics 15, 234–251 (1987).
  • [123] T. P. Hettmansperger and R. H. Randles. A practical affine equivariant multivariate median. Biometrika 89, 851–860 (2002).
source
PortfolioOptimisers.observation_median — Function
observation_median(x::VecNum, w::Option{<:StatsBase.AbstractWeights}) -> Number

Returns the median of x, weighted by the observation weights w when they are not nothing.

The weighted median is the one of StatsBase. Under StatsBase.FrequencyWeights it is the median of the data with each value repeated by its weight.

Arguments

  • x: The values.
  • w: The observation weights, or nothing.

Returns

  • m::Number: The median.

Related

source
PortfolioOptimisers.tyler_shape_step — Function
tyler_shape_step(D::MatNum, d2::VecNum, wt::VecNum, pos::AbstractVector{Bool}) -> Matrix

Returns one step of the shape equation of TylerCovariance: $p \sum_t w_t \boldsymbol{x}_t \boldsymbol{x}_t^\intercal / d_t^2 \, / \sum_t w_t$ over the observations of pos.

The step multiplies each row by the square root of its weight and takes one product of the result with itself, so the matrix is exactly symmetric.

Arguments

  • D: The data minus the location, observations × assets.
  • d2: The squared distance of each observation.
  • wt: The weight of each observation.
  • pos: The observations away from the centre.

Returns

  • V::Matrix: The new shape, before the normalisation.

Related

source
PortfolioOptimisers.spatial_median_step — Function
spatial_median_step(X::MatNum, mu::VecNum, V::MatNum, d2::VecNum, wt::VecNum,
                    pos::AbstractVector{Bool}) -> Vector

Returns one step of the weighted spatial median in the metric of the shape V, the location equation of TylerCovariance.

The step is the Weiszfeld step $\tilde{\boldsymbol{\mu}} = \sum_t (w_t/d_t) \boldsymbol{x}_t / \sum_t (w_t/d_t)$ over the observations away from the centre. When some observations are at the centre, with the total weight $\eta$, the step is the modification of Vardi and Zhang: $\max(0, 1 - \eta/r) \tilde{\boldsymbol{\mu}} + \min(1, \eta/r) \boldsymbol{\mu}$, where $r$ is the length of $\sum_t w_t (\boldsymbol{x}_t - \boldsymbol{\mu})/d_t$ in the metric of V. The R package ICSNP, version 1.2-0, takes the same step in its spatial median.

Arguments

  • X: The data matrix, observations × assets.
  • mu: The location.
  • V: The shape.
  • d2: The squared distance of each observation.
  • wt: The weight of each observation.
  • pos: The observations away from the centre.

Returns

  • mu::Vector: The new location.

Related

References

  • [123] T. P. Hettmansperger and R. H. Randles. A practical affine equivariant multivariate median. Biometrika 89, 851–860 (2002).
source
PortfolioOptimisers.tyler_scale — Function
tyler_scale(ve::Nothing, X::MatNum, mu::VecNum, V::MatNum, w::Option{<:StatsBase.AbstractWeights},
            v::Nothing; kwargs...) -> Matrix
tyler_scale(ve::Nothing, X::MatNum, mu::VecNum, V::MatNum, w::Option{<:StatsBase.AbstractWeights},
            v::VecNum; kwargs...) -> Matrix
tyler_scale(ve::StatsBase.CovarianceEstimator, X::MatNum, mu::VecNum, V::MatNum,
            w::Option{<:StatsBase.AbstractWeights}, v::Option{<:VecNum}; kwargs...) -> Matrix

Scales the shape of TylerCovariance to a covariance matrix.

The first nothing method multiplies the shape by the weighted median of the squared distances in its metric, divided by the median of the $\chi^2_p$ distribution. At the normal model, half of the squared distances in the metric of the covariance are below that median, so the scale is consistent. The second nothing method is the one of a shrunk shape. It scales the trace to the sum of the robust variances v. The estimator method keeps the correlation of the shape and takes the standard deviations from std(ve, X), through library_covariance_estimator for an estimator of another package.

Arguments

  • ve: The variance estimator, or nothing.
  • X: The data matrix, observations × assets.
  • mu: The location.
  • V: The shape.
  • w: The observation weights, or nothing.
  • v: The robust variance of each asset for a shrunk shape, or nothing.
  • kwargs...: More keyword arguments for std(ve, X).

Returns

  • sigma::Matrix: The covariance matrix.

Related

source

References

[122]
D. E. Tyler. A distribution-free M-estimator of multivariate scatter. The Annals of Statistics 15, 234–251 (1987).
[123]
T. P. Hettmansperger and R. H. Randles. A practical affine equivariant multivariate median. Biometrika 89, 851–860 (2002).