Error in numpy-financials IRR computation - eigenvector did not converge
JDE65 opened this issue · 3 comments
Within a code, I compute the IRR of a set of 1000 cashflows with numpy-financials ("npf"). Each time the code stops and delivers the following message :
File "C:\Users\navag\anaconda3\envs\tf2\lib\site-packages\numpy_financial\_financial.py", line 700, in irr
res = np.roots(values[::-1])
File "<__array_function__ internals>", line 6, in roots
File "C:\Users\navag\AppData\Roaming\Python\Python37\site-packages\numpy\lib\polynomial.py", line 245, in roots
roots = eigvals(A)
File "<__array_function__ internals>", line 6, in eigvals
File "C:\Users\navag\AppData\Roaming\Python\Python37\site-packages\numpy\linalg\linalg.py", line 1054, in eigvals
w = _umath_linalg.eigvals(a, signature=signature, extobj=extobj)
File "C:\Users\navag\AppData\Roaming\Python\Python37\site-packages\numpy\linalg\linalg.py", line 103, in _raise_linalgerror_eigenvalues_nonconvergence
raise LinAlgError("Eigenvalues did not converge")
LinAlgError: Eigenvalues did not converge
When I try manually the line of code : portf_irr_BH = (((npf.irr(invest[:,6])+1)**252) - 1)
, I also get first the same error message, but if I try immediately the line once again, I then get the right result. This does mean that npf is capable of finding the right result ! Does anyone know how to prevent this bug ? Thanks in advance
Updating numpy to version 1.19 solved the problemf or me.
Happy for you. Amazingly, when shifting my code from Tensorflow 2 to Pytorch, the issue disappeared for an unknown reason
NB. I am using numpy 1.19.2.... but as irr is deprecated in numpy, I use numpy-financials...
I'm going to close this issue. We've rewritten npf.irr
to use a different solver which doesn't use eigenvalues anymore