MCD covariance

PortfolioOptimisers.AbstractRobustReweighting — Type
abstract type AbstractRobustReweighting <: AbstractAlgorithm

Abstract supertype for the reweighting steps that follow a raw robust fit.

The raw MCD reads only h of the observations, so its efficiency is low. A reweighting step fits the location and the scatter again from the raw fit. MCDReweighting gives the hard weights of [120] to the observations that the raw fit does not flag. BisquareReweighting gives the soft weights of a bisquare M-step, which is also the second part of MMCovariance.

Interfaces

To implement a new reweighting step, subtype AbstractRobustReweighting, keep each parameter in a field, and implement one method:

  • PortfolioOptimisers.mcd_reweight(rw, ce::MCDCovariance, smp::MCDSample, raw::RobustCovarianceResult) -> RobustCovarianceResult: Returns the fit of the step from the raw fit.

Related

source
PortfolioOptimisers.MCDReweighting — Type
struct MCDReweighting{__T_q} <: AbstractRobustReweighting

Fits the location and the scatter again over the observations that the raw fit does not flag as outliers.

Step 7 of the algorithm of [120] gives the weight one to an observation whose raw squared distance is inside the quantile q of the $\chi^2_p$ distribution, and zero to the rest. With a shrinkage, the cut-off is the one of robust_outliers. The new location is the mean of the kept observations, and the new scatter is their covariance with the divisor $k - 1$, where $k$ is their number. The scatter then gets the consistency factor of mcd_consistency at q, and the small-sample factor of the reweighted MCD when MCDCovariance has one. When every observation is kept, the scatter gets no factor, as in the R package robustbase, version 0.99-7.

Fields

  • q: Probability of the cut-off of the squared distance below which the reweighting step keeps an observation, 0 < q < 1.

Constructors

MCDReweighting(;    q::Number = 0.975) -> MCDReweighting

Keywords correspond to the struct's fields.

Validation

  • 0 < q < 1.

Examples

julia> MCDReweighting()MCDReweighting  q ┴ Float64: 0.975

Related

References

  • [120] P. J. Rousseeuw and K. Van Driessen. A fast algorithm for the minimum covariance determinant estimator. Technometrics 41, 212–223 (1999). Section 4, step 7.
source
PortfolioOptimisers.MCDCovariance — Type
struct MCDCovariance{__T_me, __T_alg, __T_alpha, __T_shr, __T_ssc, __T_rw, __T_q, __T_cache} <: AbstractRobustCovarianceEstimator

Estimates the location and the covariance of the returns from the subset of h observations whose covariance matrix has the smallest determinant.

The minimum covariance determinant of [120] reads only the h observations that are nearest to each other, so up to $n - h$ bad observations cannot move it. At the default subset fraction of one half, $h = \lfloor (n + p + 1)/2 \rfloor$ and the breakdown point is about one half. The estimate goes through these steps:

  1. The search alg finds the subset, see DetMCD and FastMCD.
  2. The raw location is the mean of the subset, and the raw scatter is its covariance. The scatter gets the consistency factor of [121], see mcd_consistency, and the small-sample factor ssc of [1], see MCDSmallSampleCorrection.
  3. The reweighting step rw fits the location and the scatter again over the observations that the raw fit does not flag, see MCDReweighting. BisquareReweighting gives soft weights in place of the hard ones. rw = nothing gives the raw MCD.

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

me = nothing gives the joint location of the MCD. A given me, or a mean keyword, fixes the centre, and the search then reads the scatter of each subset about that centre with the divisor $h$.

Warning

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

shr shrinks the scatter of each subset to a target, see MCDShrinkage. The estimate is then the minimum regularised covariance determinant of [112], and it exists with fewer observations than assets. These rules change:

  • The subset holds $\lceil \alpha n \rceil$ observations, see mcd_subset_size.
  • ssc is nothing, because the small-sample factors hold for a scatter with no shrinkage.
  • The squared distance of an observation of the subset is its distance from the fit that leaves it out, and the cut-off of the outliers does not assume the $\chi^2_p$ distribution, see leave_one_out! and robust_outliers.
  • rw = nothing gives the estimate of [112]. The default reweights it, which is an addition of this library. The last paragraph of that work states that a better cut-off would improve the estimate by reweighting. On normal samples with one factor and the subset fraction one half, the reweighting makes the error of the covariance 46 % smaller with 100 observations of 100 assets, and 24 % smaller with 250 observations of 500 assets.

The estimator has no field of observation weights. factory passes the weights to me, and the scatter ignores them, because no standard weighted MCD exists.

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

Fields

  • me: Optional expected returns estimator that fixes the centre of the robust fit. If nothing, the fit estimates its own robust location.
  • alg: Search algorithm of the subset of the minimum covariance determinant, a subtype of AbstractMCDAlgorithm.
  • alpha: Subset fraction of the minimum covariance determinant, 1/2 <= alpha <= 1. The subset holds h observations, h = (n + p + 1) ÷ 2 at alpha = 1/2 and h = n at alpha = 1. With a shrinkage, h = ⌈alpha n⌉ and at least n ÷ 2 + 1.
  • shr: Optional shrinkage of the scatter of each subset, an MCDShrinkage. If nothing, the scatter is not shrunk.
  • ssc: Optional small-sample correction of the covariance. If nothing, the covariance gets the consistency factor alone. It is nothing when the fit shrinks.
  • rw: Optional reweighting step that follows the raw fit, a subtype of AbstractRobustReweighting. If nothing, the estimate is the raw fit.
  • 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

MCDCovariance(;    me::Option{<:AbstractExpectedReturnsEstimator} = nothing,    alg::AbstractMCDAlgorithm = DetMCD(),    alpha::Number = 0.5,    shr::Option{<:MCDShrinkage} = nothing,    ssc::Option{<:MCDSmallSampleCorrection} = isnothing(shr) ?                                              MCDSmallSampleCorrection() : nothing,    rw::Option{<:AbstractRobustReweighting} = MCDReweighting(),    q::Number = 0.975,    cache::Option{<:AbstractPartialFitState} = nothing) -> MCDCovariance

Keywords correspond to the struct's fields.

Validation

  • 1/2 <= alpha <= 1.
  • 0 < q < 1.
  • shr or ssc is nothing.
  • shr is nothing when rw is a BisquareReweighting. The M-step needs more observations than assets, and it does not shrink.

Propagated parameters

factory passes its arguments on to these @fprop fields:

  • me: 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> MCDCovariance()MCDCovariance     me ┼ nothing    alg ┼ DetMCD()  alpha ┼ Float64: 0.5    shr ┼ nothing    ssc ┼ MCDSmallSampleCorrection()     rw ┼ MCDReweighting        │   q ┴ Float64: 0.975      q ┴ Float64: 0.975

Related

References

  • [120] P. J. Rousseeuw and K. Van Driessen. A fast algorithm for the minimum covariance determinant estimator. Technometrics 41, 212–223 (1999). Sections 2 and 4.
  • [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). Section 3.
  • [121] C. Croux and G. Haesbroeck. Influence function and efficiency of the minimum covariance determinant scatter matrix estimator. Journal of Multivariate Analysis 71, 161–190 (1999). Not read. See mcd_consistency.
  • [1] G. Pison, S. Van Aelst and G. Willems. Small sample corrections for LTS and MCD. Metrika 55, 111–123 (2002). Sections 3 and 4.
  • [112] K. Boudt, P. J. Rousseeuw, S. Vanduffel and T. Verdonck. The minimum regularized covariance determinant estimator. Statistics and Computing 30, 113–128 (2020). Sections 2 and 3.
source
PortfolioOptimisers.mcd_fit — Function
mcd_fit(ce::MCDCovariance, smp::MCDSample, idx::AbstractVector{<:Integer}, c::Number,
        rho::Option{<:Number}) -> RobustCovarianceResult

Fits the location and the scatter of the observations idx, in the units of the data.

Algorithm

  1. Compute the location and the scatter with mcd_fit_rows.
  2. Multiply the scatter by c, and blend it with the target at the intensity rho, with shrink_scatter!.
  3. Compute the squared distance of each observation with squared_distances. With a shrinkage, replace the distance of each observation of idx with leave_one_out!.
  4. Flag the outliers at ce.q with robust_outliers.

Arguments

  • ce: The estimator, for its q.
  • smp: The data of the fit.
  • idx: The positions of the observations.
  • c: The factor of the scatter.
  • rho: The shrinkage intensity, or nothing.

Returns

  • fit::RobustCovarianceResult: The fit. The weight of an observation is one when it is in idx, and zero otherwise.

Related

source
PortfolioOptimisers.mcd_intensity — Function
mcd_intensity(intensity::Nothing, W::MatNum, idx::AbstractVector{<:Integer}, c::Number, fixed::Bool)
mcd_intensity(rho::Number, W::MatNum, idx::AbstractVector{<:Integer}, c::Number, fixed::Bool)
mcd_intensity(rule::ConditionNumberIntensity, W::MatNum, idx::AbstractVector{<:Integer},
              c::Number, fixed::Bool)
mcd_intensity(rule::SphericityIntensity, W::MatNum, idx::AbstractVector{<:Integer},
              c::Number, fixed::Bool)

Returns the shrinkage intensity of one subset of an MCDCovariance.

A number is the intensity, and nothing gives nothing. Each rule states its formula under # Mathematical definition.

Arguments

  • intensity: The rule, the intensity, or nothing.
  • W: The data, in the coordinates that turn the target into the identity matrix.
  • idx: The positions of the subset.
  • c: The factor of the scatter of the subset.
  • fixed: Whether the centre is fixed at zero.

Returns

  • rho::Option{<:Number}: The intensity.

Related

source
PortfolioOptimisers.mcd_reweight — Function
mcd_reweight(rw::Nothing, ce::MCDCovariance, smp::MCDSample, raw::RobustCovarianceResult) -> RobustCovarianceResult
mcd_reweight(rw::MCDReweighting, ce::MCDCovariance, smp::MCDSample, raw::RobustCovarianceResult) -> RobustCovarianceResult

Applies the reweighting step of an MCDCovariance to the raw fit.

The nothing method returns the raw fit. The MCDReweighting method keeps the observations that robust_outliers does not flag at rw.q, and fits them with mcd_fit. When it does not keep every observation, it multiplies the scatter by mcd_consistency at rw.q and by the reweighted factor of mcd_correction. With a shrinkage, it finds the intensity of the kept observations with mcd_intensity.

Arguments

  • rw: The reweighting step, or nothing.
  • ce: The estimator, for its subset fraction and its small-sample correction.
  • smp: The data of the fit.
  • raw: The raw fit.

Returns

  • fit::RobustCovarianceResult: The fit.

Related

References

  • [120] P. J. Rousseeuw and K. Van Driessen. A fast algorithm for the minimum covariance determinant estimator. Technometrics 41, 212–223 (1999). Section 4, step 7.
source
mcd_reweight(rw::BisquareReweighting, ce::MCDCovariance, smp::MCDSample,
             raw::RobustCovarianceResult) -> RobustCovarianceResult

Applies the M-step of BisquareReweighting to the raw fit of an MCDCovariance, with bisquare_mstep.

The scale of the step is the one of the raw covariance, which has the consistency factor and the small-sample factor of the MCD. The fit flags the outliers at ce.q.

Arguments

  • rw: The reweighting step.
  • ce: The estimator, for its q.
  • smp: The data of the fit.
  • raw: The raw fit.

Returns

  • fit::RobustCovarianceResult: The fit.

Related

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

Fits the minimum covariance determinant of MCDCovariance to the data.

Algorithm

  1. Orient X with dims_oriented, and refuse a gapped sample with assert_finite_sample.
  2. Compute the subset size h with mcd_subset_size, which refuses a sample that is too small.
  3. Take the fixed centre with robust_centre: the mean keyword, the mean of ce.me, or nothing for a joint location.
  4. Standardise the data with mcd_sample, and find the subset and the shrinkage intensity with mcd_search.
  5. Fit the raw location and scatter of the subset in the units of the data with mcd_fit, with the product of mcd_consistency at h / n and of the raw factor of mcd_correction.
  6. Reweight with mcd_reweight.

Arguments

  • ce: The MCD 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).
  • With shr = nothing, the number of observations is more than p. Otherwise, the method raises a DomainError that names the two numbers and the limit.
  • No column of X is constant, see mcd_standardise.
  • The factor of ce.ssc is positive, see mcd_correction.
  • The scatter of each subset is positive definite. With shr = nothing this means that no subset of h observations lies on a hyperplane. Otherwise, the method raises the DomainError of squared_distances.

Returns

  • res::RobustCovarianceResult: The fit. The weight of an observation comes from mcd_reweight. With rw = nothing or MCDReweighting, it is one when the observation is in the last subset that defines sigma, and zero otherwise.

Related

source

References

[1]
G. Pison, S. Van Aelst and G. Willems. Small sample corrections for LTS and MCD. Metrika 55, 111–123 (2002).
[112]
K. Boudt, P. J. Rousseeuw, S. Vanduffel and T. Verdonck. The minimum regularized covariance determinant estimator. Statistics and Computing 30, 113–128 (2020).
[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).
[120]
P. J. Rousseeuw and K. Van Driessen. A fast algorithm for the minimum covariance determinant estimator. Technometrics 41, 212–223 (1999).
[121]
C. Croux and G. Haesbroeck. Influence function and efficiency of the minimum covariance determinant scatter matrix estimator. Journal of Multivariate Analysis 71, 161–190 (1999).