Covariance Estimator#

A covariance estimator estimates the covariance matrix of the assets.

It follows the same API as scikit-learn’s estimator: the fit method takes X as the assets returns and stores the covariance in its covariance_ attribute.

X can be any array-like structure (numpy array, pandas DataFrame, etc.)

Available estimators are:

For online learning and streaming workflows, EWCovariance and RegimeAdjustedEWCovariance support incremental updates with partial_fit. They also support NaN-aware updates with active_mask, which helps distinguish active assets with missing returns, for example on holidays, from structurally inactive assets such as pre-listing or post-delisting periods.

Example:

from skfolio.datasets import load_sp500_dataset
from skfolio.moments import EmpiricalCovariance
from skfolio.preprocessing import prices_to_returns

prices = load_sp500_dataset()
X = prices_to_returns(prices)

model = EmpiricalCovariance()
model.fit(X)
print(model.covariance_)