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

# skfolio.moments.ShrunkMu

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

### *class* skfolio.moments.ShrunkMu(covariance_estimator=None, vol_weighted_target=False, method=JAMES_STEIN)

Shrinkage Expected Returns (Mu) estimator.

Estimates the expected returns using shrinkage.

The sample mean estimator is unbiased but has high variance.
Stein (1955) proved that it’s possible to find an estimator with reduced total
error using shrinkage by trading a small bias against high variance.

The estimator shrinks the sample mean toward a target vector:

> $$
> \hat{\mu} = \alpha\bar{\mu}+\beta \mu_{target}

> $$

with $\bar{\mu}$ the sample mean, $\mu_{target}$ the target vector
and $\alpha$ and $\beta$ two constants to determine.

There are two choices for the target vector $\mu_{target}$ :

> * Grand Mean: constant vector of the mean of the sample mean
> * Volatility-Weighted Grand Mean: volatility-weighted sample mean

And three methods for $\alpha$ and $\beta$ :

> * James-Stein
> * Bayes-Stein
> * Bodnar Okhrin Parolya
* **Parameters:**
  **covariance_estimator** *BaseCovariance, optional*
  : [Covariance estimator](https://skfolio.org/user_guide/covariance.html.md#covariance-estimator) used to estimate the
    covariance in the shrinkage formulae.
    The default (`None`) is to use [`EmpiricalCovariance`](https://skfolio.org/generated/skfolio.moments.EmpiricalCovariance.html.md#skfolio.moments.EmpiricalCovariance).

  **vol_weighted_target** *bool, default=False*
  : If this is set to True, the target vector $\mu_{target}$ is the
    Volatility-Weighted Grand Mean otherwise it is the Grand Mean.
    The default is `False`.

  **method** *ShrunkMuMethods, default=ShrunkMuMethods.JAMES_STEIN*
  : Shrinkage method [`ShrunkMuMethods`](https://skfolio.org/generated/skfolio.moments.ShrunkMuMethods.html.md#skfolio.moments.ShrunkMuMethods).
    <br/>
    Possible values are:
    > * JAMES_STEIN
    > * BAYES_STEIN
    > * BODNAR_OKHRIN
    <br/>
    The default value is `ShrunkMuMethods.JAMES_STEIN`.
* **Attributes:**
  **mu_** *ndarray of shape (n_assets,)*
  : Estimated expected returns of the assets.

  **covariance_estimator_** *BaseCovariance*
  : Fitted `covariance_estimator`.

  **mu_target_** *ndarray of shape (n_assets,)*
  : Target vector $\mu_{target}$.

  **alpha_** *float*
  : Alpha value $\alpha$.

  **beta_** *float*
  : Beta value $\beta$.

  **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 assets names that are all strings.

### Methods

| [`fit`](#skfolio.moments.ShrunkMu.fit)(X[, y])            | Fit the ShrunkMu estimator model.     |
|-------------------------------------------------------------------------|---------------------------------------|
| [`get_metadata_routing`](#skfolio.moments.ShrunkMu.get_metadata_routing)() | Get metadata routing of this object.  |
| [`get_params`](#skfolio.moments.ShrunkMu.get_params)([deep])     | Get parameters for this estimator.    |
| [`set_params`](#skfolio.moments.ShrunkMu.set_params)(\*\*params) | Set the parameters of this estimator. |

### References

* <a id='r579f13f50985-1'>**[1]**</a> “Risk and Asset Allocation”, Attilio Meucci (2005)
* <a id='r579f13f50985-2'>**[2]**</a> “Bayes-stein estimation for portfolio analysis”, Philippe Jorion (1986)
* <a id='r579f13f50985-3'>**[3]**</a> “Optimal shrinkage estimator for high-dimensional mean vector” Bodnar, Okhrin and Parolya (2019)

<a id="skfolio.moments.ShrunkMu.fit"></a>

#### fit(X, y=None, \*\*fit_params)

Fit the ShrunkMu estimator model.

* **Parameters:**
  **X** *array-like of shape (n_observations, n_assets)*
  : Price returns of the assets.

  **y** *Ignored*
  : Not used, present for API consistency by convention.

  **\*\*fit_params** *dict*
  : 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](https://skfolio.org/user_guide/metadata_routing.html.md#metadata-routing) for
    more details.
* **Returns:**
  **self** *ShrunkMu*
  : Fitted estimator.

<a id="skfolio.moments.ShrunkMu.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.ShrunkMu.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.ShrunkMu.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.

