skfolio.utils.stats.squared_mahalanobis_dist#

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

Squared Mahalanobis distance via Cholesky decomposition.

\[d^2 = (r - \mu)^\top \Sigma^{-1} (r - \mu)\]
Parameters:
Xndarray 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.

covariancendarray of shape (n_assets, n_assets)

Covariance matrix \(\Sigma\).

meanndarray of shape (n_assets,), optional

Mean vector \(\mu\) subtracted from each row. If None, data are assumed already centred.

ridge_scalefloat, default=1e-12

Relative ridge size, as a fraction of the average covariance diagonal.

max_triesint, default=3

Maximum number of ridge escalations before raising an error.

Returns:
d2ndarray of shape (n_observations,) or float

Squared Mahalanobis distances (non-negative).