<a id="skfolio-utils-stats-squared-mahalanobis-dist"></a>

# skfolio.utils.stats.squared_mahalanobis_dist

<a id="skfolio.utils.stats.squared_mahalanobis_dist"></a>

### skfolio.utils.stats.squared_mahalanobis_dist(X, covariance, mean=None, ridge_scale=1e-12, max_tries=3)

Squared Mahalanobis distance via Cholesky decomposition.

$$
d^2 = (r - \mu)^\top \Sigma^{-1} (r - \mu)

$$

* **Parameters:**
  **X** *ndarray of shape (n_observations, n_assets) or (n_assets,)*
  : Price returns of the assets. If 1-D, treated as a single observation and a
    scalar is returned.

  **covariance** *ndarray of shape (n_assets, n_assets)*
  : Covariance matrix $\Sigma$.

  **mean** *ndarray of shape (n_assets,), optional*
  : Mean vector $\mu$ subtracted from each row.  If `None`, data
    are assumed already centred.

  **ridge_scale** *float, default=1e-12*
  : Relative ridge size, as a fraction of the average covariance diagonal.

  **max_tries** *int, default=3*
  : Maximum number of ridge escalations before raising an error.
* **Returns:**
  **d2** *ndarray of shape (n_observations,) or float*
  : Squared Mahalanobis distances (non-negative).

