skfolio.utils.stats.safe_cholesky#
- skfolio.utils.stats.safe_cholesky(covariance, ridge_scale=1e-12, max_tries=3)[source]#
Compute a Cholesky factor \(L\) from covariance \(\Sigma\).
Fast path: try plain Cholesky on the input as-is. Fallback: symmetrize and add ridge \(\lambda I\) with escalation until SPD:
\[\Sigma_{reg} = (\Sigma + \Sigma^T)/2 + \lambda I \approx L L^T\]- Parameters:
- covariancendarray of shape (n_assets, n_assets)
Covariance matrix \(\Sigma\).
- ridge_scalefloat, default=1e-12
Relative ridge size, as a fraction of the average absolute covariance diagonal. If that scale is zero, a positive numerical floor is used.
- max_triesint, default=3
Maximum number of ridge escalations before raising an error.
- Returns:
- cholndarray of shape (n_assets, n_assets)
Lower triangular Cholesky factor \(L\) such that \(\Sigma \approx L L^T\).
- Raises:
- ValueError
If Cholesky decomposition fails after all retry attempts.