robertmartin8 / PyPortfolioOpt

Financial portfolio optimisation in python, including classical efficient frontier, Black-Litterman, Hierarchical Risk Parity
https://pyportfolioopt.readthedocs.io/
MIT License
4.25k stars 928 forks source link

Add the assume_PSD flag in calls to cvxpy.quad_form #543

Open AveryLevin opened 1 year ago

AveryLevin commented 1 year ago

Resolves an issue where ArpackNoConvergence errors were being raised by CVXPY when trying to optimize large portfolios. This error is raised when CVXPY checks if the given matrix is Positive Semi-Definite, calling scipy.sparse.linalg.eigsh to determine if the min eigenvalue is negative, which uses Arnoldi Iteration. However, CVXPY relies on SciPy's default maxiter argument for eigsh which is simply the matrix's dimension multiplied by 10 which can fail to converge when checking larger matrices.

Since the covariance matrices being sent to CVXPY are already checked/corrected for PSD in fix_nonpositive_semidefinite, we can use the assume_PSD flag when calling cp.quad_form to prevent these errors from being raised.