Skip to content

Commit 68a2fb8

Browse files
committed
ENH: Make tol and `maxiter keywords arguments
1 parent c81a2b5 commit 68a2fb8

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

numpy_financial/_financial.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -671,7 +671,7 @@ def rate(nper, pmt, pv, fv, when='end', guess=None, tol=None, maxiter=100):
671671
return rn
672672

673673

674-
def irr(values, guess=0.1):
674+
def irr(values, guess=0.1, tol=1e-12, maxiter=100):
675675
"""
676676
Return the Internal Rate of Return (IRR).
677677
@@ -691,6 +691,10 @@ def irr(values, guess=0.1):
691691
guess : float, optional
692692
Initial guess of the IRR for the iterative solver. If no guess is
693693
given an initial guess of 0.1 (i.e. 10%) is assumed instead.
694+
tol : float, optional
695+
Required tolerance to accept solution. Default is 1e-12.
696+
maxiter : int, optional
697+
Maximum iterations to perform in finding a solution. Default is 100.
694698
695699
Returns
696700
-------
@@ -764,9 +768,9 @@ def irr(values, guess=0.1):
764768
d_npv = npv_.deriv()
765769
x = 1 / (1 + guess)
766770

767-
for _ in range(100):
771+
for _ in range(maxiter):
768772
x_new = x - (npv_(x) / d_npv(x))
769-
if abs(x_new - x) < 1e-12:
773+
if abs(x_new - x) < tol:
770774
return 1 / x_new - 1
771775
x = x_new
772776

numpy_financial/tests/test_financial.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -551,7 +551,7 @@ def test_some_rates_zero(self):
551551
class TestIrr:
552552
def test_npv_irr_congruence(self):
553553
# IRR is defined as the rate required for the present value of
554-
# a a series of cashflows to be zero, so we should have
554+
# a series of cashflows to be zero, so we should have
555555
#
556556
# NPV(IRR(x), x) = 0.
557557
cashflows = numpy.array([-40000, 5000, 8000, 12000, 30000])

0 commit comments

Comments
 (0)