Base robust covariance

PortfolioOptimisers.AbstractRobustCovarianceEstimator — Type
abstract type AbstractRobustCovarianceEstimator <: AbstractCovarianceEstimator

Abstract 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 a RobustCovarianceResult.

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

source
PortfolioOptimisers.RobustCovarianceResult — Type
struct RobustCovarianceResult{__T_mu, __T_sigma, __T_d2, __T_w, __T_outlier, __T_intensity} <: AbstractResult

Holds 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 vector assets × 1.
  • sigma: Robust covariance matrix assets × assets.
  • d2: Squared robust distance of each observation from mu in the metric of sigma, 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 of sigma, 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, or nothing for a fit with no shrinkage.

Constructors

RobustCovarianceResult(;    mu::VecNum,    sigma::MatNum,    d2::VecNum,    w::VecNum,    outlier::AbstractVector{Bool},    intensity::Option{<:Number} = nothing) -> RobustCovarianceResult

Keywords correspond to the struct's fields.

Validation

  • sigma is square, and its size is the length of mu.
  • d2, w and outlier have 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 1

Related

source
Statistics.cov — Method
Statistics.cov(ce::AbstractRobustCovarianceEstimator, X::MatNum; dims::Int = 1,
               mean = nothing, kwargs...) -> Matrix

Returns the robust covariance matrix, the sigma of StatsAPI.fit(ce, X; dims, mean, kwargs...).

Arguments

  • ce: The robust 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 the fit.

Returns

  • sigma::MatNum: Covariance matrix assets x assets.

Related

source
Statistics.cor — Method
Statistics.cor(ce::AbstractRobustCovarianceEstimator, X::MatNum; dims::Int = 1,
               mean = nothing, kwargs...) -> Matrix

Returns the robust correlation matrix, the robust covariance matrix rescaled with cov2cor_nan!.

Arguments

  • ce: The robust 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 the fit.

Returns

  • rho::MatNum: Correlation matrix assets x assets.

Related

source