MCD covariance: private API
PortfolioOptimisers.assert_open_probability — Function
assert_open_probability(q::Number, name::Symbol)Refuses a probability outside the open interval from zero to one.
Arguments
q: The probability.name: The name of the field, for the message.
Validation
0 < q < 1. Otherwise, the function raises aDomainError.
Returns
nothing.
Related
PortfolioOptimisers.show_fields — Method
show_fields(_::MCDCovariance) -> NTuple{7, Symbol}
Renders every field of an MCDCovariance except cache.
A cache holds the state of an incremental fit, not a part of the configuration. Set set_show_nothing_fields!(:MCDCovariance, true) to render it.
Arguments
::MCDCovariance: The estimator, read for its type alone.
Returns
fields::Tuple: The names of the fields to render,(:me, :alg, :alpha, :shr, :ssc, :rw, :q).
Related
PortfolioOptimisers.mcd_sample — Function
mcd_sample(shr::Nothing, X::MatNum, centre::Option{<:VecNum}) -> MCDSample
mcd_sample(shr::MCDShrinkage, X::MatNum, centre::Option{<:VecNum}) -> MCDSampleBuilds the data that the fit of an MCDCovariance reads.
The nothing method standardises the data with mcd_standardise. The MCDShrinkage method also builds the target with robust_target from the pilot of mcd_pilot, and multiplies the standardised data by the inverse of the symmetric root of the target. The target is then the identity matrix.
[112] takes the eigenvectors of the target in place of the symmetric root. The search then reads rotated data, and the rotation is not unique when two eigenvalues are equal, as in an equicorrelation target. The two give one target, and differ in the starts of the search alone.
Arguments
shr: The shrinkage, ornothing.X: The data matrix,observations × assets.centre: The fixed centre, ornothing.
Returns
smp::MCDSample: The data of the fit.
Related
References
- [112] K. Boudt, P. J. Rousseeuw, S. Vanduffel and T. Verdonck. The minimum regularized covariance determinant estimator. Statistics and Computing 30, 113–128 (2020). Section 2.2, Equations 6 to 8.
PortfolioOptimisers.mcd_pilot — Function
mcd_pilot(tgt::Union{IdentityTarget, ScaledIdentityTarget, DiagonalTarget, MatNum},
X::MatNum, s::VecNum) -> LinearAlgebra.Diagonal
mcd_pilot(tgt::CovarianceShrinkageTarget, X::MatNum, s::VecNum) -> MatrixReturns the robust pilot covariance that the target rule of an MCDShrinkage reads.
A rule that reads the variances alone gets the diagonal matrix of the robust variances. Another rule gets the sine transform of the Kendall correlations, $\sin(\pi \tau / 2)$, scaled by the robust scales. [112] takes the mean Kendall correlation for its equicorrelation target. The sine transform is an addition of this library. It makes the correlation consistent at an elliptical model. The R package rrcov, version 1.7-7, applies the same transform to the Spearman correlations, for which it is not the consistent one, so the two equicorrelation targets differ.
Arguments
tgt: The target.X: The data matrix,observations × assets.s: The robust scale of each column, zero for a column with no robust scale.
Returns
pilot::AbstractMatrix: The pilot, in the units of the data.
Related
References
- [112] K. Boudt, P. J. Rousseeuw, S. Vanduffel and T. Verdonck. The minimum regularized covariance determinant estimator. Statistics and Computing 30, 113–128 (2020). Section 2.4, Equation 15, and Section 4.
PortfolioOptimisers.subset_shrinkage — Function
subset_shrinkage(rho::Nothing, c::Number, p::Integer) -> Nothing
subset_shrinkage(rho::Number, c::Number, p::Integer) -> SubsetShrinkageReturns the SubsetShrinkage of a search, whose target is the identity matrix.
Arguments
rho: The intensity, ornothing.c: The consistency factor.p: The number of assets.
Returns
reg::Option{<:SubsetShrinkage}: The shrinkage of the search, ornothing.
Related
PortfolioOptimisers.pooled_intensity — Function
pooled_intensity(intensity::Nothing, W::MatNum, starts, c::Number, fixed::Bool)
pooled_intensity(intensity::Union{Number, AbstractSubsetShrinkageIntensity}, W::MatNum,
starts, c::Number, fixed::Bool)Returns one shrinkage intensity for every start of an MCD search, and the starts that it permits.
Every subset must have the same intensity, so that the determinants compare. Steps 3.3 to 3.5 of the algorithm of [112] take the intensity of each start. A start that holds outliers can make its own intensity too large, so a start whose intensity is above the largest of 0.1 and of the median leaves the search. The pooled intensity is the largest one of the starts that stay, the smallest value at which each of them meets the rule. The R package rrcov, version 1.7-7, does the same. The text of [112] takes the cut-off itself when an intensity is above 0.1.
Arguments
intensity: The rule, the intensity, ornothing.W: The data, in the coordinates that turn the target into the identity matrix.starts: The start subsets.c: The consistency factor.fixed: Whether the centre is fixed at zero.
Returns
(rho, starts): The intensity, ornothingwith no shrinkage, and the starts.
Related
References
- [112] K. Boudt, P. J. Rousseeuw, S. Vanduffel and T. Verdonck. The minimum regularized covariance determinant estimator. Statistics and Computing 30, 113–128 (2020). Section 3, steps 3.3 to 3.5 of the algorithm.
PortfolioOptimisers.leave_one_out! — Function
leave_one_out!(d2::VecNum, idx::AbstractVector{<:Integer}, c::Number, fixed::Bool) -> VecNum
leave_one_out!(d2::VecNum, idx::AbstractVector{<:Integer}, reg::SubsetShrinkage, fixed::Bool) -> VecNumReplaces the squared distance of each observation of the subset with its distance from the fit that leaves the observation out.
A scatter of few observations follows each observation that it holds. So the distance of such an observation is too small, and the distance of every other observation looks large beside it. With fewer observations than assets, the two sets do not overlap, and half of the clean observations look like outliers. The distance from the fit that leaves the observation out compares with the distance of an observation outside the subset. The method of a number, the fit with no shrinkage, changes nothing.
Mathematical definition
\[\begin{align} \tilde{d}_t^2 &= \frac{g^2 d_t^2}{1 - g b \, d_t^2}\,, & g &= \frac{k}{k - 1}\,, & b &= \frac{(1 - \rho) c}{k - 1}\,. \end{align}\]
Where:
- $d_t^2$: The squared distance of an observation of the subset.
- $k$: The number of observations of the subset.
- $\rho$: The shrinkage intensity.
- $c$: The factor of the scatter.
The formula keeps the divisor of the scatter. With a fixed centre, $g = 1$ and the divisor is $k$.
Arguments
d2: The squared distance of each observation.idx: The positions of the subset.c,reg: The factor, or the shrinkage.fixed: Whether the centre is fixed.
Returns
d2::VecNum: The input vector.
Related
PortfolioOptimisers.mcd_fit_rows — Function
mcd_fit_rows(X::MatNum, idx::AbstractVector{<:Integer}, centre::Nothing) -> Tuple{VecNum, MatNum}
mcd_fit_rows(X::MatNum, idx::AbstractVector{<:Integer}, centre::VecNum) -> Tuple{VecNum, MatNum}Returns the location and the scatter of the observations idx of X, in the units of the data.
With no fixed centre, these are the mean and the covariance with the divisor $k - 1$ of the $k$ observations. With a fixed centre, the location is the centre and the scatter has the divisor $k$, see mcd_subset_fit.
Arguments
X: The data matrix,observations × assets.idx: The positions of the observations.centre: The fixed centre, ornothing.
Returns
(mu, sigma): The location and the scatter.
Related
References
- [112]
- K. Boudt, P. J. Rousseeuw, S. Vanduffel and T. Verdonck. The minimum regularized covariance determinant estimator. Statistics and Computing 30, 113–128 (2020).