<a id="covariance-estimator"></a>

<a id="id1"></a>

# Covariance Estimator

A [covariance estimator](https://skfolio.org/api.html.md#covariance-ref) 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.)

`covariance_` is expressed in the periodicity of `X` (daily returns give a daily
covariance) and is consumed as is by the optimizers, without annualization (see
[Periodicity Convention](https://skfolio.org/user_guide/data_preparation.html.md#periodicity-convention)).

Available estimators are:
: * [`EmpiricalCovariance`](https://skfolio.org/generated/skfolio.moments.EmpiricalCovariance.html.md#skfolio.moments.EmpiricalCovariance)
  * [`EWCovariance`](https://skfolio.org/generated/skfolio.moments.EWCovariance.html.md#skfolio.moments.EWCovariance)
  * [`RegimeAdjustedEWCovariance`](https://skfolio.org/generated/skfolio.moments.RegimeAdjustedEWCovariance.html.md#skfolio.moments.RegimeAdjustedEWCovariance)
  * [`GerberCovariance`](https://skfolio.org/generated/skfolio.moments.GerberCovariance.html.md#skfolio.moments.GerberCovariance)
  * [`DenoiseCovariance`](https://skfolio.org/generated/skfolio.moments.DenoiseCovariance.html.md#skfolio.moments.DenoiseCovariance)
  * [`DetoneCovariance`](https://skfolio.org/generated/skfolio.moments.DetoneCovariance.html.md#skfolio.moments.DetoneCovariance)
  * [`LedoitWolf`](https://skfolio.org/generated/skfolio.moments.LedoitWolf.html.md#skfolio.moments.LedoitWolf)
  * [`OAS`](https://skfolio.org/generated/skfolio.moments.OAS.html.md#skfolio.moments.OAS)
  * [`ShrunkCovariance`](https://skfolio.org/generated/skfolio.moments.ShrunkCovariance.html.md#skfolio.moments.ShrunkCovariance)
  * [`GraphicalLassoCV`](https://skfolio.org/generated/skfolio.moments.GraphicalLassoCV.html.md#skfolio.moments.GraphicalLassoCV)
  * [`ImpliedCovariance`](https://skfolio.org/generated/skfolio.moments.ImpliedCovariance.html.md#skfolio.moments.ImpliedCovariance)

For online learning and streaming workflows, [`EWCovariance`](https://skfolio.org/generated/skfolio.moments.EWCovariance.html.md#skfolio.moments.EWCovariance) and
[`RegimeAdjustedEWCovariance`](https://skfolio.org/generated/skfolio.moments.RegimeAdjustedEWCovariance.html.md#skfolio.moments.RegimeAdjustedEWCovariance) 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) or assets outside the universe (e.g. during pre-listing or
post-delisting periods).
See [Online Learning](https://skfolio.org/user_guide/online_learning.html.md#online-learning) for the full online workflow, including covariance
forecast evaluation and online hyper-parameter tuning.
See [Missing Data and Changing Universes](https://skfolio.org/user_guide/data_representation.html.md#missing-data) for the full convention
on NaNs, universe membership, estimator warmup and investability.

**Example:**

```python
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_)
```
