S covariance: private API

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

Renders every field of an SCovariance except cache.

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

Arguments

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

Returns

  • fields::Tuple: The names of the fields to render, (:me, :rho, :bdp, :alg, :q).

Related

source
PortfolioOptimisers.srho_fit — Function
srho_fit(rho::AbstractSRho, X::MatNum, mu::VecNum, sigma::MatNum, k::Number, q::Number)
    -> RobustCovarianceResult

Builds the fit of an S or MM estimate from its location and its covariance.

The weight of an observation is srho_weight at its squared distance in the metric of sigma, from squared_distances. The covariance of the fit is sigma times the factor of s_consistency, and the squared distances of the fit are in its metric. The flag of an observation is the one of robust_outliers at q.

Arguments

  • rho: The rho function of the weights.
  • X: The data matrix, observations × assets.
  • mu: The location.
  • sigma: The covariance, the scale times the shape, before the consistency factor.
  • k: The tuning constant of the rho function.
  • q: The probability of the cut-off of the outliers.

Returns

  • res::RobustCovarianceResult: The fit.

Related

source
PortfolioOptimisers.s_search — Function
s_search(alg::AbstractSAlgorithm, rho::AbstractSRho, X::MatNum, centre::Option{<:VecNum},
         h::Integer, k::Number, b::Number, maxsteps::Integer) -> Tuple{VecNum, MatNum, Number}

Returns the location, the shape of determinant one and the M-scale of the best estimate that the search alg finds.

Algorithm

  1. Take the starts with s_starts, and keep the best of a search with many starts with s_refine.
  2. Do at most maxsteps I-steps from each start with s_isteps, until the estimate does not change.
  3. Return the estimate with the smallest M-scale. The first start wins a tie. Warn when that estimate did not converge.

Arguments

  • alg: The search algorithm.
  • rho: The rho function.
  • X: The data matrix, observations × assets.
  • centre: The fixed centre, or nothing.
  • h: The size of a start subset.
  • k: The tuning constant of the rho function.
  • b: The right side of the equation of the M-scale.
  • maxsteps: The largest number of I-steps from one start, S_MAX_ITER in a fit.

Returns

  • (mu, V, s): The location, the shape and the scale.

Related

source
PortfolioOptimisers.fasts_random_start — Function
fasts_random_start(rng::Random.AbstractRNG, X::MatNum, centre::Option{<:VecNum})
    -> Tuple{VecNum, MatNum}

Draws one start of FastS.

The function draws $p + 1$ observations with no repetition. While their covariance matrix is singular, it adds one more observation that it draws from the rest, as fastmcd_random_start does. The start is the location and the scatter of the drawn observations, from mcd_fit_rows.

Arguments

  • rng: The random number generator.
  • X: The data matrix, observations × assets.
  • centre: The fixed centre, or nothing.

Returns

  • (mu, S): The location and the scatter of the start.

Related

source
PortfolioOptimisers.s_isteps — Function
s_isteps(rho::AbstractSRho, X::MatNum, mu::VecNum, S::MatNum, fixed::Bool, k::Number,
         b::Number, maxsteps::Integer) -> Tuple{VecNum, MatNum, Number, Bool}

Does I-steps of an S estimate from the location mu and the scatter S.

An I-step is a step of the fixed-point equations of [129], which state that an S estimate is an M-estimate with the weights of its own rho function. For a rho function that is concave in $t$, such as BisquareRho, the step does not increase the M-scale. RockeRho is convex below $t = 1$, so the step has no such bound, and the search keeps the start with the smallest M-scale. It stops when the relative change of the shape and the change of the location in the metric of the scatter are both below sqrt(eps), or after maxsteps steps.

Algorithm

  1. Scale S to the determinant one with unit_determinant!. Compute the squared distances t with squared_distances, and their M-scale s with m_scale, from the start $\mathrm{med}(t)$.
  2. Repeat at most maxsteps times:
    1. Take the weight of each observation, srho_weight at t / s.
    2. Take the weighted mean and the weighted scatter of determinant one with weighted_shape.
    3. Compute the new distances, and their M-scale from the start s.

Arguments

  • rho: The rho function.
  • X: The data matrix, observations × assets.
  • mu: The start location.
  • S: The start scatter. The method does not change it.
  • fixed: Whether the centre is fixed at mu.
  • k: The tuning constant of the rho function.
  • b: The right side of the equation of the M-scale.
  • maxsteps: The largest number of steps.

Returns

  • (mu, V, s, done): The location, the shape of determinant one, the M-scale, and whether the steps converged.

Related

References

  • [129] H. P. Lopuhaä. On the relation between S-estimators and M-estimators of multivariate location and covariance. The Annals of Statistics 17, 1662–1683 (1989). Not read. The fixed point agrees with the R package rrcov, version 1.7-7.
source
PortfolioOptimisers.shape_converged — Function
shape_converged(mu::VecNum, V::MatNum, mun::VecNum, Vn::MatNum, s::Number, tol::Number) -> Bool

Returns whether a step of a fixed point moved the location and the shape by less than tol.

The relative change of the shape is in the Frobenius norm. The change of the location is its distance in the metric of the old scatter $s \mathbf{V}$, so the test does not change when the data are multiplied by a constant.

Arguments

  • mu, V: The old location and shape.
  • mun, Vn: The new location and shape.
  • s: The scale of the shape, so that $s \mathbf{V}$ is the scatter.
  • tol: The tolerance.

Returns

  • done::Bool: Whether both changes are below tol.

Related

source
PortfolioOptimisers.weighted_shape — Function
weighted_shape(X::MatNum, w::VecNum, mu::VecNum, fixed::Bool) -> Tuple{VecNum, MatNum}

Returns the weighted mean of the observations and their weighted scatter about it, scaled to the determinant one.

With a fixed centre, the location stays at mu, and the scatter is about mu. A common factor of the weights does not change the result.

Arguments

  • X: The data matrix, observations × assets.
  • w: The weight of each observation.
  • mu: The location, used when fixed is true.
  • fixed: Whether the centre is fixed at mu.

Returns

  • (mu, V): The location and the shape.

Related

source

References

[129]
H. P. Lopuhaä. On the relation between S-estimators and M-estimators of multivariate location and covariance. The Annals of Statistics 17, 1662–1683 (1989).