S covariance

PortfolioOptimisers.AbstractSAlgorithm — Type
abstract type AbstractSAlgorithm <: AbstractAlgorithm

Abstract supertype for the search algorithms of an S estimator of location and scatter.

The S estimate of SCovariance is the location and the scatter of determinant one whose distances have the smallest M-scale. No closed form gives it, and the objective has local minima. A search starts from a set of estimates and improves each one by I-steps, see s_isteps. s_search returns the estimate with the smallest scale.

Interfaces

To implement a new search, subtype AbstractSAlgorithm, keep each parameter in a field, and implement one method:

  • PortfolioOptimisers.s_starts(alg, X::MatNum, centre::Option{<:VecNum}, h::Integer) -> Vector{Tuple{VecNum, MatNum}}: Returns the start locations and scatters of the data X. centre is the fixed centre, or nothing. h is the size of a start subset.

The fit does I-steps from each start until the estimate does not change. A search with many starts can keep a part of them first, with one more method:

  • PortfolioOptimisers.s_refine(alg, rho::AbstractSRho, X::MatNum, starts, fixed::Bool, k::Number, b::Number) -> Vector{Tuple{VecNum, MatNum}}: Returns the starts from which the fit does I-steps until the estimate does not change. The default returns starts.

Related

source
PortfolioOptimisers.DetS — Type
struct DetS <: AbstractSAlgorithm

Searches the S estimate from the six deterministic starts of DetMCD.

The search of [128] takes the six start subsets of [119], see detmcd_initset. Each subset of $h = \lfloor (n + p + 1)/2 \rfloor$ observations gives a start: the mean and the covariance of its observations. The search does I-steps from each start until the estimate does not change, and keeps the estimate with the smallest M-scale. Two calls on the same data give the same estimate, so cov(ce, X) == fit(ce, X).sigma holds.

The estimate agrees with the R package rrcov, version 1.7-7, with method = "sdet", and also with its random search method = "sfast", when both converge to the same minimum.

Examples

julia> DetS()DetS()

Related

References

  • [128] M. Hubert, P. J. Rousseeuw, D. Vanpaemel and T. Verdonck. The DetS and DetMM estimators for multivariate location and scatter. Computational Statistics & Data Analysis 81, 64–75 (2015). Not read. See SCovariance.
  • [119] M. Hubert, P. J. Rousseeuw and T. Verdonck. A deterministic algorithm for robust location and scatter. Journal of Computational and Graphical Statistics 21, 618–637 (2012). Sections 3.1 and 3.2.
source
PortfolioOptimisers.FastS — Type
struct FastS{__T_n_starts, __T_n_refine, __T_n_best, __T_rng, __T_seed} <: AbstractSAlgorithm

Searches the S estimate from random starts.

The search of [127] draws n_starts random subsets of $p + 1$ observations, see fasts_random_start. Each subset gives a start: the mean and the covariance of its observations. The search does n_refine I-steps from each start, keeps the n_best estimates with the smallest M-scales, does I-steps from each until the estimate does not change, and returns the best. The default number of starts is the number that the manual of the R package rrcov, version 1.7-7, states for method = "sfast".

The search draws random numbers, so the type has the fields rng and seed. resolve_rng combines them when the search runs. With seed = nothing, two calls can give two estimates. DetS is the default of SCovariance for that reason.

Fields

  • n_starts: Number of random start subsets.
  • n_refine: Number of I-steps from each start before the search keeps the best starts.
  • n_best: Number of the best starts that the search iterates until their subsets do not change.
  • rng: Random number generator.
  • seed: Optional seed. If set, the draws come from a copy of rng seeded with it, so rng does not advance and every call draws the same values. If nothing, the draws come from rng itself.

Constructors

FastS(;    n_starts::Integer = 20,    n_refine::Integer = 2,    n_best::Integer = 5,    rng::Random.AbstractRNG = Random.default_rng(),    seed::Option{<:Integer} = nothing) -> FastS

Keywords correspond to the struct's fields.

Validation

  • n_starts, n_refine and n_best are positive.
  • n_best <= n_starts.

Examples

julia> FastS(; seed = 42)FastS  n_starts ┼ Int64: 20  n_refine ┼ Int64: 2    n_best ┼ Int64: 5       rng ┼ Random.TaskLocalRNG: Random.TaskLocalRNG()      seed ┴ Int64: 42

Related

References

  • [127] M. Salibián-Barrera, S. Van Aelst and G. Willems. Principal components analysis based on multivariate MM estimators with fast and robust bootstrap. Journal of the American Statistical Association 101, 1198–1211 (2006). Not read. The estimate agrees with the R package rrcov, version 1.7-7.
source
PortfolioOptimisers.RobustStartS — Type
struct RobustStartS{__T_ce} <: AbstractSAlgorithm

Searches the S estimate from the fit of another robust estimator.

The search takes one start, the location and the covariance of the fit of ce, and does I-steps from it until the estimate does not change. An MCD fit with DetMCD, the default, is deterministic, so two calls give the same estimate. The S estimate is then the nearest minimum of the M-scale to the MCD fit, and it has the efficiency of an S estimate, which the MCD has not. A fixed centre of the S fit is the mean keyword of the fit of ce, so it wins over the me of ce.

Fields

Constructors

RobustStartS(;    ce::AbstractRobustCovarianceEstimator = MCDCovariance()) -> RobustStartS

Keywords correspond to the struct's fields.

Propagated parameters

factory passes its arguments on to these @fprop fields:

  • ce: Recursively updated through factory.

View parameters

port_opt_view takes the view of these @vprop fields at the selected indices:

Examples

julia> RobustStartS(; ce = TylerCovariance())RobustStartS  ce ┼ TylerCovariance     │    me ┼ nothing     │    ve ┼ nothing     │   shr ┼ nothing     │     w ┼ nothing     │     q ┴ Float64: 0.975

Related

source
PortfolioOptimisers.SCovariance — Type
struct SCovariance{__T_me, __T_rho, __T_bdp, __T_alg, __T_q, __T_cache} <: AbstractRobustCovarianceEstimator

Estimates the location and the covariance of the returns with an S estimator, which has a high breakdown point.

The S estimator of [124] takes the location $\boldsymbol{\mu}$ and the shape $\mathbf{V}$ of determinant one that make the M-scale $s$ of the squared distances smallest. The covariance is $s \mathbf{V}$. The rho function rho is bounded, so a share of outliers below the breakdown point bdp cannot move the estimate without bound. Each observation has the continuous weight of the rho function, see srho_weight, so an outlier has a weight near zero and the estimate needs no hard cut-off. The estimate goes through these steps:

  1. The search alg finds the starts, see DetS, FastS and RobustStartS.
  2. The I-steps of s_isteps improve each start until it does not change.
  3. The fit keeps the estimate with the smallest M-scale, and multiplies its covariance by the consistency factor of the rho function, see s_consistency. The factor is one for BisquareRho.

With many assets, RockeRho gives a better balance of efficiency and resistance than the bisquare rho.

At bdp = 0.5, the efficiency of the S estimate at the normal model is low for few assets. MMCovariance takes an M-step from it to a high efficiency, with the same breakdown point.

StatsAPI.fit returns the location, the covariance, and the squared distance, the weight and the outlier flag of each observation in a RobustCovarianceResult. cov returns the covariance of that fit.

me = nothing gives the joint location of the S estimate. A given me, or a mean keyword, fixes the centre, and the fit then estimates the shape and the scale alone.

Warning

A fixed centre that is not robust moves with the outliers. The fit then measures the distances from a wrong centre. SimpleExpectedReturns is such an estimator. Use me = nothing, a MedianExpectedReturns, or a RobustExpectedReturns.

The estimator has no field of observation weights. factory passes the weights to me, and the scatter ignores them.

The estimator has no exact update, so an Online wrapper refits it over the rows of its Sample Buffer, see SampleBufferState.

Mathematical definition

\[\begin{align} (\boldsymbol{\mu}, \mathbf{V}) &= \underset{\boldsymbol{m}, \, \lvert \mathbf{A} \rvert = 1}{\arg\min} \; s(\boldsymbol{m}, \mathbf{A})\,, & \frac{1}{T} \sum_{t=1}^{T} \rho\left(\frac{(\boldsymbol{x}_t - \boldsymbol{m})^\intercal \mathbf{A}^{-1} (\boldsymbol{x}_t - \boldsymbol{m})}{s(\boldsymbol{m}, \mathbf{A})}\right) &= b\,. \end{align}\]

Where:

  • $s$: The M-scale of the squared distances, see m_scale.
  • $\rho$: The rho function rho.
  • $b$: The right side of the equation of the scale, see s_tuning.
  • $T$: Number of observations.

Fields

  • me: Optional expected returns estimator that fixes the centre of the robust fit. If nothing, the fit estimates its own robust location.
  • rho: Rho function of the M-scale of the S estimate, a subtype of AbstractSRho.
  • bdp: Breakdown point of the S estimate, the largest share of outliers that cannot move it without bound, 0 < bdp <= 1/2.
  • q: Probability of the cut-off of the squared distance above which an observation is an outlier, 0 < q < 1. See robust_outliers.
  • cache: Optional partial-fit state. It is nothing until partial_fit! writes one. When the caller gives no data matrix, the batch verb of the estimator reads it. Each propagation channel does one thing with it. factory keeps it unchanged, because a factory call resolves the configuration, not the sample. port_opt_view copies the entries of the selected assets into a new state, so the viewed estimator holds the state of those assets alone. obs_weights_view removes it, because a state has no slice on the observation axis. Only a type with an observation-weights field has that channel. A type with no such field falls through to the identity method, so it keeps its state. A family whose state has no exact asset slice removes it on both axes and names the reason.

Constructors

SCovariance(;    me::Option{<:AbstractExpectedReturnsEstimator} = nothing,    rho::AbstractSRho = BisquareRho(),    bdp::Number = 0.5,    alg::AbstractSAlgorithm = DetS(),    q::Number = 0.975,    cache::Option{<:AbstractPartialFitState} = nothing) -> SCovariance

Keywords correspond to the struct's fields.

Validation

  • 0 < bdp <= 1/2.
  • 0 < q < 1.

Propagated parameters

factory passes its arguments on to these @fprop fields:

  • me: Recursively updated through factory.
  • alg: Recursively updated through factory.
  • cache: Carried unchanged through factory.

View parameters

port_opt_view takes the view of these @vprop fields at the selected indices:

Examples

julia> SCovariance()SCovariance   me ┼ nothing  rho ┼ BisquareRho()  bdp ┼ Float64: 0.5  alg ┼ DetS()    q ┴ Float64: 0.975

Related

References

  • [124] P. L. Davies. Asymptotic behaviour of S-estimates of multivariate location parameters and dispersion matrices. The Annals of Statistics 15, 1269–1292 (1987). Not read. The estimate agrees with the R package rrcov, version 1.7-7.
  • [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. See s_isteps.
  • [128] M. Hubert, P. J. Rousseeuw, D. Vanpaemel and T. Verdonck. The DetS and DetMM estimators for multivariate location and scatter. Computational Statistics & Data Analysis 81, 64–75 (2015). Not read. See DetS.
source
PortfolioOptimisers.s_starts — Function
s_starts(alg::DetS, X::MatNum, centre::Option{<:VecNum}, h::Integer) -> Vector{Tuple{VecNum, MatNum}}
s_starts(alg::FastS, X::MatNum, centre::Option{<:VecNum}, h::Integer) -> Vector{Tuple{VecNum, MatNum}}
s_starts(alg::RobustStartS, X::MatNum, centre::Option{<:VecNum}, h::Integer) -> Vector{Tuple{VecNum, MatNum}}

Returns the start locations and scatters of the search alg.

The DetS method standardises the data with mcd_standardise, takes the six start subsets of detmcd_initset over the directions of detmcd_directions, and fits each subset in the units of the data with mcd_fit_rows. With a fixed centre, the location of each start is the centre. The FastS method resolves the generator from alg.rng and alg.seed with resolve_rng, and draws alg.n_starts starts with fasts_random_start. The RobustStartS method fits alg.ce with the centre as its mean keyword, and returns its location and its covariance.

Arguments

  • alg: The search algorithm.
  • X: The data matrix, observations × assets.
  • centre: The fixed centre, or nothing.
  • h: The size of a start subset.

Returns

  • starts::Vector{Tuple{VecNum, MatNum}}: The start locations and scatters.

Related

References

  • [128] M. Hubert, P. J. Rousseeuw, D. Vanpaemel and T. Verdonck. The DetS and DetMM estimators for multivariate location and scatter. Computational Statistics & Data Analysis 81, 64–75 (2015). Not read. See DetS.
source
PortfolioOptimisers.s_refine — Function
s_refine(alg::AbstractSAlgorithm, rho::AbstractSRho, X::MatNum, starts, fixed::Bool,
         k::Number, b::Number) -> Vector{Tuple{VecNum, MatNum}}
s_refine(alg::FastS, rho::AbstractSRho, X::MatNum, starts, fixed::Bool,
         k::Number, b::Number) -> Vector{Tuple{VecNum, MatNum}}

Keeps the best starts of a search.

The default method keeps every start. The FastS method does alg.n_refine I-steps from each start with s_isteps, and returns the alg.n_best estimates with the smallest M-scales, in increasing order of the scale.

Arguments

  • alg: The search algorithm.
  • rho: The rho function.
  • X: The data matrix, observations × assets.
  • starts: The start locations and scatters.
  • fixed: Whether the centre is fixed.
  • k: The tuning constant of the rho function.
  • b: The right side of the equation of the M-scale.

Returns

  • starts::Vector{Tuple{VecNum, MatNum}}: The starts from which the fit does I-steps until the estimate does not change.

Related

source
StatsAPI.fit — Method
StatsAPI.fit(ce::SCovariance, X::MatNum; dims::Int = 1, mean = nothing, kwargs...)
    -> RobustCovarianceResult

Fits the S estimate of SCovariance to the data.

Algorithm

  1. Orient X with dims_oriented, and refuse a gapped sample with assert_finite_sample.
  2. Refuse a sample whose start subsets of $h = \lfloor (n + p + 1)/2 \rfloor$ observations are too small, with assert_robust_rows.
  3. Take the fixed centre with robust_centre: the mean keyword, the mean of ce.me, or nothing for a joint location.
  4. Take the tuning constant and the right side of the M-scale with s_tuning.
  5. Find the location, the shape and the scale with s_search.
  6. Build the fit with srho_fit.

Arguments

  • ce: The S covariance estimator.
  • X: Data matrix observations × assets if the dims keyword does not exist or dims = 1, assets × observations when dims = 2.
  • dims: Dimension along which the computation runs.
  • mean: Optional precomputed centre of the data. A given centre fixes the location of the fit.
  • kwargs...: More keyword arguments for ce.me.

Validation

  • dims in (1, 2).
  • all(isfinite, X).
  • h > p. Otherwise, the method raises a DomainError that names h, p and the limit.
  • No column of X is constant, see mcd_standardise.
  • The scatter of each step is positive definite. Otherwise, the method raises the DomainError of squared_distances or of unit_determinant!.

Returns

  • res::RobustCovarianceResult: The fit. The weight of an observation is its weight of the rho function, see srho_weight.

Related

source

References

[119]
M. Hubert, P. J. Rousseeuw and T. Verdonck. A deterministic algorithm for robust location and scatter. Journal of Computational and Graphical Statistics 21, 618–637 (2012).
[124]
P. L. Davies. Asymptotic behaviour of S-estimates of multivariate location parameters and dispersion matrices. The Annals of Statistics 15, 1269–1292 (1987).
[127]
M. Salibián-Barrera, S. Van Aelst and G. Willems. Principal components analysis based on multivariate MM estimators with fast and robust bootstrap. Journal of the American Statistical Association 101, 1198–1211 (2006).
[128]
M. Hubert, P. J. Rousseeuw, D. Vanpaemel and T. Verdonck. The DetS and DetMM estimators for multivariate location and scatter. Computational Statistics & Data Analysis 81, 64–75 (2015).
[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).