-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Description
Is your feature request related to a problem?
Yes. While fix_nonpositive_semidefinite correctly detects and fixes non-PSD covariance matrices, covariance matrices that are positive semidefinite but highly ill-conditioned can still lead to numerical instability during inversion and optimization (e.g. in EfficientFrontier solvers). Currently, these cases pass silently despite being potentially problematic.
Describe the feature you'd like
I propose emitting a warning when a covariance matrix is positive semidefinite but has a very large condition number, indicating numerical ill-conditioning. The warning would suggest using shrinkage estimators (e.g. Ledoit-Wolf or OAS) to improve numerical stability.
This would not change the public API or default behavior of the library — it would only add a warning in potentially unstable cases.
Additional context
This is motivated by standard numerical linear algebra practice, where PSD does not imply stable inversion if the condition number is large. Similar warnings are commonly used in scientific computing libraries to guide users toward more stable estimators without enforcing behavioral changes.
I am happy to add unit tests to ensure the warning is raised appropriately and does not affect existing functionality.