<a id="skfolio-uncertainty-set-bootstrapcovarianceuncertaintyset"></a>

# skfolio.uncertainty_set.BootstrapCovarianceUncertaintySet

<a id="skfolio.uncertainty_set.BootstrapCovarianceUncertaintySet"></a>

### *class* skfolio.uncertainty_set.BootstrapCovarianceUncertaintySet(prior_estimator=None, confidence_level=0.95, diagonal=True, n_bootstrap_samples=1000, block_size=None, seed=None)

Bootstrap Covariance Uncertainty set.

Compute the covariance ellipsoidal uncertainty set using stationary bootstrap:

$$
U_{\Sigma}
=
\left\{
    \Sigma :
    d^\top S^{-1} d \le \kappa^2,
    \Sigma \succeq 0
\right\},
\quad
d =
\operatorname{vec}(\Sigma) - \operatorname{vec}(\hat{\Sigma}).
$$

The radius of the ellipsoid $\kappa$ (confidence region) is computed using:

$$
\kappa^2 = \chi^2_{n_{\text{assets}}^2}(\beta)

$$

with $\chi^2_{n_{\text{assets}}^2}(\beta)$ the inverse cumulative
distribution function of the chi-squared distribution with $n_{\text{assets}}^2$
degrees of freedom at the $\beta$ confidence level.

The shape matrix $S$ of the ellipsoid is the covariance matrix of the
bootstrapped vectorized covariance estimator. If `diagonal` is `True`, only the
diagonal of $S$ is retained and the linear geometry map $L$ is built
directly from it. Otherwise, the estimator stores a full square-root factor
$L = S^{1/2}$.

* **Parameters:**
  **prior_estimator** *BasePrior, optional*
  : The [prior estimator](https://skfolio.org/user_guide/prior.html.md#prior) used to estimate the assets return
    distribution. The default (`None`) is to use [`EmpiricalPrior`](https://skfolio.org/generated/skfolio.prior.EmpiricalPrior.html.md#skfolio.prior.EmpiricalPrior).

  **confidence_level** *float , default=0.95*
  : Confidence level $\beta$ of the inverse cumulative distribution function
    of the chi-squared distribution. The default value is `0.95`.

  **diagonal** *bool, default=True*
  : If `True`, only the diagonal of the ellipsoid shape matrix in vectorized
    covariance space is retained.

  **n_bootstrap_samples** *int, default=1000*
  : Number of bootstrap samples to generate. The default value is `1000`.

  **block_size** *float, optional*
  : Bootstrap block size. The default (`None`) is to estimate the optimal block size
    using Politis & White algorithm for all individual assets.

  **seed** *int, optional*
  : Random seed used to initialize the pseudo-random number generator.
* **Attributes:**
  **uncertainty_set_** *UncertaintySet*
  : Covariance Uncertainty set [`UncertaintySet`](https://skfolio.org/generated/skfolio.uncertainty_set.UncertaintySet.html.md#skfolio.uncertainty_set.UncertaintySet).

  **prior_estimator_** *BasePrior*
  : Fitted `prior_estimator`.

### Methods

| [`fit`](#skfolio.uncertainty_set.BootstrapCovarianceUncertaintySet.fit)(X[, y])            | Fit the Bootstrap Covariance Uncertainty set estimator.   |
|-------------------------------------------------------------------------|-----------------------------------------------------------|
| [`get_metadata_routing`](#skfolio.uncertainty_set.BootstrapCovarianceUncertaintySet.get_metadata_routing)() | Get metadata routing of this object.                      |
| [`get_params`](#skfolio.uncertainty_set.BootstrapCovarianceUncertaintySet.get_params)([deep])     | Get parameters for this estimator.                        |
| [`set_params`](#skfolio.uncertainty_set.BootstrapCovarianceUncertaintySet.set_params)(\*\*params) | Set the parameters of this estimator.                     |

### References

* <a id='r53ffc7e1ab60-1'>**[1]**</a> “Portfolio Optimization: Theory and Application”, Chapter 14, Daniel P. Palomar (2025)
* <a id='r53ffc7e1ab60-2'>**[2]**</a> “Robustness properties of mean-variance portfolios”, Optimization: A Journal of Mathematical Programming and Operations Research, Schöttle & Werner (2009).
* <a id='r53ffc7e1ab60-3'>**[3]**</a> “Automatic Block-Length Selection for the Dependent Bootstrap”, Politis & White (2004).
* <a id='r53ffc7e1ab60-4'>**[4]**</a> “Correction to Automatic Block-Length Selection for the Dependent Bootstrap”, Patton, Politis & White (2009).

<a id="skfolio.uncertainty_set.BootstrapCovarianceUncertaintySet.fit"></a>

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

Fit the Bootstrap Covariance Uncertainty set estimator.

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

  **y** *array-like of shape (n_observations, n_factors), optional*
  : Price returns of factors.
    The default is `None`.

  **\*\*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** *BootstrapCovarianceUncertaintySet*
  : Fitted estimator.

<a id="skfolio.uncertainty_set.BootstrapCovarianceUncertaintySet.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.uncertainty_set.BootstrapCovarianceUncertaintySet.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.uncertainty_set.BootstrapCovarianceUncertaintySet.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.

