<a id="skfolio-moments-basevariance"></a>

# skfolio.moments.BaseVariance

<a id="skfolio.moments.BaseVariance"></a>

### *class* skfolio.moments.BaseVariance(assume_centered=False)

Base class for all variance estimators in `skfolio`.

Variance estimators estimate the diagonal elements of a covariance matrix,
assuming **zero correlation** between assets. This is appropriate when:

* Estimating **idiosyncratic (specific) risk** in factor models, where residual
  returns are uncorrelated by construction
* Working with **orthogonalized** or **uncorrelated** return series
* The full covariance structure is not needed or is constructed separately

* **Parameters:**
  **assume_centered** *bool, default=False*
  : If False (default), the data are mean-centered before computing the variance.
    This is the standard behavior when working with raw returns where the mean is
    not guaranteed to be zero.
    If True, the estimator assumes the input data are already centered. Use this
    when you know the returns have zero mean, such as pre-demeaned data or
    regression residuals.
* **Attributes:**
  **variance_** *ndarray of shape (n_assets,)*
  : Estimated variance vector $(\\sigma^2_1, ..., \\sigma^2_n)$.

  **location_** *ndarray of shape (n_assets,)*
  : Estimated location, i.e. the estimated mean.
    When `assume_centered=True`, this is zero.
    When `assume_centered=False`, this is the sample mean.

  **n_features_in_** *int*
  : Number of assets seen during `fit`.

  **feature_names_in_** *ndarray of shape (`n_features_in_`,)*
  : Names of assets seen during `fit`. Defined only when `X`
    has asset names that are all strings.

### Methods

| [`get_metadata_routing`](#skfolio.moments.BaseVariance.get_metadata_routing)()   | Get metadata routing of this object.   |
|---------------------------------------------------------------------------|----------------------------------------|
| [`get_params`](#skfolio.moments.BaseVariance.get_params)([deep])       | Get parameters for this estimator.     |
| [`set_params`](#skfolio.moments.BaseVariance.set_params)(\*\*params)   | Set the parameters of this estimator.  |

| **fit**   |    |
|-----------|----|

### Notes

All estimators should specify all the parameters that can be set
at the class level in their `__init__` as explicit keyword
arguments (no `*args` or `**kwargs`).

<a id="skfolio.moments.BaseVariance.get_metadata_routing"></a>

#### get_metadata_routing()

Get metadata routing of this object.

Please check [User Guide](https://skfolio.org/user_guide/metadata_routing.html.md#metadata-routing) on how the routing
mechanism works.

* **Returns:**
  **routing** *MetadataRequest*
  : A `MetadataRequest` encapsulating
    routing information.

<a id="skfolio.moments.BaseVariance.get_params"></a>

#### get_params(deep=True)

Get parameters for this estimator.

* **Parameters:**
  **deep** *bool, default=True*
  : If True, will return the parameters for this estimator and
    contained subobjects that are estimators.
* **Returns:**
  **params** *dict*
  : Parameter names mapped to their values.

<a id="skfolio.moments.BaseVariance.set_params"></a>

#### 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:**
  **\*\*params** *dict*
  : Estimator parameters.
* **Returns:**
  **self** *estimator instance*
  : Estimator instance.

