You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I found a situation where npf.rate is not returning the same thing as my BA II Plus financial calculator or npf.irr. Even setting guess to the correct value does not get the expected answer.
The main policy question is whether to restrict the default search to r > -1, and how guess should guide selection when multiple roots exist. We should also handle the zero-rate limit explicitly and check the equation residual before accepting convergence.
I tested Brent, TOMS 748, and bisection on a sign-changing bracket [0, 2]. All found 0.583877911024823 for the corrected inputs.
Would Brent’s method or safeguarded Newton with bisection fallback be worth considering? The latter could reuse the existing derivative without adding a SciPy dependency.
I’ve opened #158 to enforce r > -1 for returned rates. Lower roots can satisfy the equation algebraically, but don’t make sense as compounding rates for conventional loans or investments.
The change keeps Newton for ordinary cases and falls back to bracketed bisection when it converges outside that domain. Guesses at or below −1 are rejected.
The corrected example returns 0.583877911, and the original inputs return 1.671183828.
Activity
Kai-Striega commentedon Jun 14, 2024
Hi @jestover,
Thanks for reporting this, I'll take a look at it.
What version of NumPy-Financial are you using?
jestover commentedon Jun 18, 2024
I'm using version 1.0.0
lcrmorin commentedon Sep 19, 2026
The main policy question is whether to restrict the default search to
r > -1, and howguessshould guide selection when multiple roots exist. We should also handle the zero-rate limit explicitly and check the equation residual before accepting convergence.I tested Brent, TOMS 748, and bisection on a sign-changing bracket
[0, 2]. All found0.583877911024823for the corrected inputs.Would Brent’s method or safeguarded Newton with bisection fallback be worth considering? The latter could reuse the existing derivative without adding a SciPy dependency.
lcrmorin commentedon Sep 28, 2026
I’ve opened #158 to enforce
r > -1for returned rates. Lower roots can satisfy the equation algebraically, but don’t make sense as compounding rates for conventional loans or investments.The change keeps Newton for ordinary cases and falls back to bracketed bisection when it converges outside that domain. Guesses at or below −1 are rejected.
The corrected example returns
0.583877911, and the original inputs return1.671183828.All tests pass locally.