MCD covariance
PortfolioOptimisers.AbstractRobustReweighting — Type
abstract type AbstractRobustReweighting <: AbstractAlgorithmAbstract 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
PortfolioOptimisers.MCDReweighting — Type
struct MCDReweighting{__T_q} <: AbstractRobustReweightingFits 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) -> MCDReweightingKeywords correspond to the struct's fields.
Validation
0 < q < 1.
Examples
julia> MCDReweighting()MCDReweighting q ┴ Float64: 0.975Related
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.
PortfolioOptimisers.MCDCovariance — Type
struct MCDCovariance{__T_me, __T_alg, __T_alpha, __T_shr, __T_ssc, __T_rw, __T_q, __T_cache} <: AbstractRobustCovarianceEstimatorEstimates 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:
- The search
algfinds the subset, seeDetMCDandFastMCD. - 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 factorsscof [1], seeMCDSmallSampleCorrection. - The reweighting step
rwfits the location and the scatter again over the observations that the raw fit does not flag, seeMCDReweighting.BisquareReweightinggives soft weights in place of the hard ones.rw = nothinggives 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$.
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. sscisnothing, 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!androbust_outliers. rw = nothinggives 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. Ifnothing, the fit estimates its own robust location.
alg: Search algorithm of the subset of the minimum covariance determinant, a subtype ofAbstractMCDAlgorithm.
alpha: Subset fraction of the minimum covariance determinant,1/2 <= alpha <= 1. The subset holdshobservations,h = (n + p + 1) ÷ 2atalpha = 1/2andh = natalpha = 1. With a shrinkage,h = ⌈alpha n⌉and at leastn ÷ 2 + 1.
shr: Optional shrinkage of the scatter of each subset, anMCDShrinkage. Ifnothing, the scatter is not shrunk.
ssc: Optional small-sample correction of the covariance. Ifnothing, the covariance gets the consistency factor alone. It isnothingwhen the fit shrinks.
rw: Optional reweighting step that follows the raw fit, a subtype ofAbstractRobustReweighting. Ifnothing, 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. Seerobust_outliers.
cache: Optional partial-fit state. It isnothinguntilpartial_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.factorykeeps it unchanged, because a factory call resolves the configuration, not the sample.port_opt_viewcopies the entries of the selected assets into a new state, so the viewed estimator holds the state of those assets alone.obs_weights_viewremoves 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) -> MCDCovarianceKeywords correspond to the struct's fields.
Validation
1/2 <= alpha <= 1.0 < q < 1.shrorsscisnothing.shrisnothingwhenrwis aBisquareReweighting. The M-step needs more observations than assets, and it does not shrink.
Propagated parameters
factory passes its arguments on to these @fprop fields:
View parameters
port_opt_view takes the view of these @vprop fields at the selected indices:
me: Recursively viewed throughport_opt_view.shr: Recursively viewed throughport_opt_view.cache: Sliced to the selected assets throughport_opt_view.
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.975Related
AbstractRobustCovarianceEstimatorRobustCovarianceResultDetMCDFastMCDMCDReweightingMCDSmallSampleCorrectionMCDShrinkageTylerCovarianceRobustExpectedReturns
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.
PortfolioOptimisers.mcd_fit — Function
mcd_fit(ce::MCDCovariance, smp::MCDSample, idx::AbstractVector{<:Integer}, c::Number,
rho::Option{<:Number}) -> RobustCovarianceResultFits the location and the scatter of the observations idx, in the units of the data.
Algorithm
- Compute the location and the scatter with
mcd_fit_rows. - Multiply the scatter by
c, and blend it with the target at the intensityrho, withshrink_scatter!. - Compute the squared distance of each observation with
squared_distances. With a shrinkage, replace the distance of each observation ofidxwithleave_one_out!. - Flag the outliers at
ce.qwithrobust_outliers.
Arguments
ce: The estimator, for itsq.smp: The data of the fit.idx: The positions of the observations.c: The factor of the scatter.rho: The shrinkage intensity, ornothing.
Returns
fit::RobustCovarianceResult: The fit. The weight of an observation is one when it is inidx, and zero otherwise.
Related
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, ornothing.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
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) -> RobustCovarianceResultApplies 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, ornothing.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.
mcd_reweight(rw::BisquareReweighting, ce::MCDCovariance, smp::MCDSample,
raw::RobustCovarianceResult) -> RobustCovarianceResultApplies 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 itsq.smp: The data of the fit.raw: The raw fit.
Returns
fit::RobustCovarianceResult: The fit.
Related
StatsAPI.fit — Method
StatsAPI.fit(ce::MCDCovariance, X::MatNum; dims::Int = 1, mean = nothing, kwargs...)
-> RobustCovarianceResultFits the minimum covariance determinant of MCDCovariance to the data.
Algorithm
- Orient
Xwithdims_oriented, and refuse a gapped sample withassert_finite_sample. - Compute the subset size
hwithmcd_subset_size, which refuses a sample that is too small. - Take the fixed centre with
robust_centre: themeankeyword, the mean ofce.me, ornothingfor a joint location. - Standardise the data with
mcd_sample, and find the subset and the shrinkage intensity withmcd_search. - Fit the raw location and scatter of the subset in the units of the data with
mcd_fit, with the product ofmcd_consistencyath / nand of the raw factor ofmcd_correction. - Reweight with
mcd_reweight.
Arguments
ce: The MCD covariance estimator.X: Data matrixobservations × assetsif thedimskeyword does not exist ordims = 1,assets × observationswhendims = 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 force.me.
Validation
dims in (1, 2).all(isfinite, X).- With
shr = nothing, the number of observations is more thanp. Otherwise, the method raises aDomainErrorthat names the two numbers and the limit. - No column of
Xis constant, seemcd_standardise. - The factor of
ce.sscis positive, seemcd_correction. - The scatter of each subset is positive definite. With
shr = nothingthis means that no subset ofhobservations lies on a hyperplane. Otherwise, the method raises theDomainErrorofsquared_distances.
Returns
res::RobustCovarianceResult: The fit. The weight of an observation comes frommcd_reweight. Withrw = nothingorMCDReweighting, it is one when the observation is in the last subset that definessigma, and zero otherwise.
Related
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).