skfolio.uncertainty_set.EmpiricalCovarianceUncertaintySet#

class skfolio.uncertainty_set.EmpiricalCovarianceUncertaintySet(prior_estimator=None, confidence_level=0.95, diagonal=True, n_eff=None)[source]#

Empirical Covariance Uncertainty set.

Compute the covariance ellipsoidal uncertainty set [1]:

\[U_{\Sigma} = \left\{ \Sigma : d^\top S^{-1} d \le \kappa^2, \Sigma \succeq 0 \right\}, \quad d = \operatorname{vec}(\Sigma) - \operatorname{vec}(\hat{\Sigma}).\]

We consider the Wishart distribution for the covariance matrix:

\[\hat{\Sigma}\sim W(\frac{1}{T-1}\Sigma, T-1)\]

The radius of the ellipsoid \(\kappa\) (confidence region) is computed using:

\[\kappa^2 = \chi^2_{n_{\text{assets}}^2}(\beta)\]

with \(\chi^2_{n_{\text{assets}}^2}(\beta)\) the inverse cumulative distribution function of the chi-squared distribution with \(n_{\text{assets}}^2\) degrees of freedom at the \(\beta\) confidence level.

The shape matrix \(S\) of the ellipsoid is based on the covariance matrix of the Wishart distributed random variable using the vector notation \(\operatorname{vec}(x)\):

\[\operatorname{Cov}[\operatorname{vec}(\hat{\Sigma})] = \frac{1}{n_{\text{eff}}} (I_{n^2} + K_{nn})(\Sigma \otimes \Sigma).\]

where \(K_{nn}\) denotes a commutation matrix and \(\otimes\) represents the Kronecker product. If diagonal is True, the asset covariance estimate is diagonalized and the linear geometry map \(L\) is built directly from the diagonal of \(S\). Otherwise, the estimator stores a full square-root factor \(L = S^{1/2}\).

Parameters:
prior_estimatorBasePrior, optional

The prior estimator used to estimate the assets covariance matrix. The default (None) is to use EmpiricalPrior.

confidence_levelfloat , default=0.95

Confidence level \(\beta\) of the inverse cumulative distribution function of the chi-squared distribution. The default value is 0.95.

diagonalbool, default=True

If True, the non-diagonal elements of the asset covariance matrix are set to zero before building the ellipsoid shape matrix.

n_efffloat, optional

Effective number of observations used for the covariance estimator. If None, the number of observations in X is used. This is useful when the covariance matrix is estimated using a different window length or a weighted estimator (e.g. EWMA), in which case n_eff should be set to the corresponding effective sample size.

Attributes:
uncertainty_set_UncertaintySet

Covariance Uncertainty set UncertaintySet.

prior_estimator_BasePrior

Fitted prior_estimator.

n_eff_float

Effective number of observations actually used to build the uncertainty set.

Methods

fit(X[, y])

Fit the Empirical Covariance Uncertainty set estimator.

get_metadata_routing()

Get metadata routing of this object.

get_params([deep])

Get parameters for this estimator.

set_params(**params)

Set the parameters of this estimator.

References

[1]

“Robustness properties of mean-variance portfolios”, Optimization: A Journal of Mathematical Programming and Operations Research, Schöttle & Werner (2009).

[2]

“Portfolio Optimization: Theory and Application”, Chapter 14, Daniel P. Palomar (2025)

fit(X, y=None, **fit_params)[source]#

Fit the Empirical Covariance Uncertainty set estimator.

Parameters:
Xarray-like of shape (n_observations, n_assets)

Price returns of the assets.

yarray-like of shape (n_observations, n_factors), optional

Price returns of factors. The default is None.

**fit_paramsdict

Parameters to pass to the underlying estimators. Only available if enable_metadata_routing=True, which can be set by using sklearn.set_config(enable_metadata_routing=True). See Metadata Routing User Guide for more details.

Returns:
selfEmpiricalCovarianceUncertaintySet

Fitted estimator.

get_metadata_routing()#

Get metadata routing of this object.

Please check User Guide on how the routing mechanism works.

Returns:
routingMetadataRequest

A MetadataRequest encapsulating routing information.

get_params(deep=True)#

Get parameters for this estimator.

Parameters:
deepbool, default=True

If True, will return the parameters for this estimator and contained subobjects that are estimators.

Returns:
paramsdict

Parameter names mapped to their values.

set_params(**params)#

Set the parameters of this estimator.

The method works on simple estimators as well as on nested objects (such as Pipeline). The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.

Parameters:
**paramsdict

Estimator parameters.

Returns:
selfestimator instance

Estimator instance.