Base robust covariance
PortfolioOptimisers.AbstractRobustCovarianceEstimator — Type
abstract type AbstractRobustCovarianceEstimator <: AbstractCovarianceEstimatorAbstract supertype for the covariance estimators that resist outliers in the returns.
A bad tick, a split that the data source does not record, or one extreme day moves the sample covariance much. A robust estimator gives each observation a weight that falls with its distance from the centre of the data, so a few bad rows cannot control the estimate. MCDCovariance, TylerCovariance, SCovariance and MMCovariance are its subtypes.
Interfaces
A subtype implements one method:
StatsAPI.fit(ce, X::MatNum; dims::Int = 1, mean = nothing, kwargs...) -> RobustCovarianceResult: Fits the robust location and scatter, and returns them with the distance, the weight and the outlier flag of each observation in aRobustCovarianceResult.
The family then gives Statistics.cov(ce, X; dims, mean), which returns the sigma of the fit, and Statistics.cor(ce, X; dims, mean), which rescales it to a correlation matrix. The fallbacks of var and std read the diagonal of cov. So every consumer of a covariance estimator, such as a prior, a distance or an uncertainty set, reads the robust covariance with no change. RobustExpectedReturns reads the mu of the fit.
Related
PortfolioOptimisers.RobustCovarianceResult — Type
struct RobustCovarianceResult{__T_mu, __T_sigma, __T_d2, __T_w, __T_outlier, __T_intensity} <: AbstractResultHolds the fit of a robust covariance estimator: the location, the scatter, and the squared distance, the weight and the outlier flag of each observation.
StatsAPI.fit of an AbstractRobustCovarianceEstimator returns it. The weight of an observation is the weight that it has in the estimate of sigma. The flag marks an observation whose squared distance is above a cut-off of the probability q, the field of the estimator. With no shrinkage, the cut-off is the quantile of the $\chi^2_p$ distribution, see robust_outliers.
Fields
mu: Robust location vectorassets × 1.
sigma: Robust covariance matrixassets × assets.
d2: Squared robust distance of each observation frommuin the metric ofsigma,observations × 1. In a shrunk MCD fit, the distance of an observation of the subset comes from the fit that leaves it out.
w: Weight of each observation in the estimate ofsigma,observations × 1.
outlier: Outlier flag of each observation,observations × 1. An observation is an outlier when its squared distance is above the cut-off of the estimator.
intensity: Shrinkage intensity of the fit, ornothingfor a fit with no shrinkage.
Constructors
RobustCovarianceResult(; mu::VecNum, sigma::MatNum, d2::VecNum, w::VecNum, outlier::AbstractVector{Bool}, intensity::Option{<:Number} = nothing) -> RobustCovarianceResultKeywords correspond to the struct's fields.
Validation
sigmais square, and its size is the length ofmu.d2,wandoutlierhave one length, the number of observations.
Examples
julia> r = RobustCovarianceResult(; mu = [0.0, 0.0], sigma = [1.0 0.0; 0.0 1.0], d2 = [0.5, 9.0], w = [1.0, 0.0], outlier = BitVector([0, 1]));julia> r.outlier2-element BitVector: 0 1Related
Statistics.cov — Method
Statistics.cov(ce::AbstractRobustCovarianceEstimator, X::MatNum; dims::Int = 1,
mean = nothing, kwargs...) -> MatrixReturns the robust covariance matrix, the sigma of StatsAPI.fit(ce, X; dims, mean, kwargs...).
Arguments
ce: The robust 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 for the fit.
Returns
sigma::MatNum: Covariance matrixassets x assets.
Related
Statistics.cor — Method
Statistics.cor(ce::AbstractRobustCovarianceEstimator, X::MatNum; dims::Int = 1,
mean = nothing, kwargs...) -> MatrixReturns the robust correlation matrix, the robust covariance matrix rescaled with cov2cor_nan!.
Arguments
ce: The robust 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 for the fit.
Returns
rho::MatNum: Correlation matrixassets x assets.
Related