Variance Estimator#

A variance estimator estimates the variance vector 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 variances in its variance_ attribute.

Variance estimators are useful when only marginal volatility is needed, for example when modelling idiosyncratic risk or working with orthogonalized return series.

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

Available estimators are:

For online learning and streaming workflows, EWVariance and RegimeAdjustedEWVariance support incremental updates with partial_fit. They also support NaN-aware updates with active_mask, which helps distinguish assets that belong to the universe but have missing returns (e.g. holidays), from assets outside the universe (e.g. pre-listing or post-delisting periods). See Missing Data and Changing Universes for the full convention on NaNs, universe membership, estimator warmup and investability.

Example:

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

prices = load_sp500_dataset()
X = prices_to_returns(prices)

model = EmpiricalVariance()
model.fit(X)
print(model.variance_)