Skip to content

Commit

Permalink
TST: Move NPV-IRR congruence check to tests
Browse files Browse the repository at this point in the history
The internal rate of return (irr) is defined as the rate of return
required for the net present values of a series of cashflows to be
zero. i.e the lowest rate of return required for a project to break
even.

This is currently checked by refering to the example output from
the ``irr`` and ``npv`` function documentation. This commit adds a
test to confirm the identity holds.
  • Loading branch information
Kai-Striega committed Sep 14, 2019
1 parent 58dc455 commit 594d0c3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
7 changes: 0 additions & 7 deletions numpy/lib/financial.py
Original file line number Diff line number Diff line change
Expand Up @@ -715,8 +715,6 @@ def irr(values):
>>> round(np.irr([-5, 10.5, 1, -8, 1]), 5)
0.0886
(Compare with the Example given for numpy.lib.financial.npv)
"""
# `np.roots` call is why this function does not support Decimal type.
#
Expand Down Expand Up @@ -785,11 +783,6 @@ def npv(rate, values):
Examples
--------
>>> np.npv(0.281,[-100, 39, 59, 55, 20])
-0.0084785916384548798 # may vary
(Compare with the Example given for numpy.lib.financial.irr)
Consider a potential project with an initial investment of $40 000 and
projected cashflows of $5 000, $8 000, $12 000 and $30 000 at the end of
each period discounted at a rate of 8% per period. To find the project's
Expand Down
6 changes: 6 additions & 0 deletions numpy/lib/tests/test_financial.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@


class TestFinancial(object):
def test_npv_irr_congruence(self):
# IRR is defined as the rate required for the present value of a
# a series of cashflows to be zero i.e. NPV(IRR(x), x) = 0
cashflows = np.array([-40000, 5000, 8000, 12000, 30000])
assert_allclose(np.npv(np.irr(cashflows), cashflows), 0, atol=1e-10, rtol=0)

def test_rate(self):
assert_almost_equal(
np.rate(10, 0, -3500, 10000),
Expand Down

0 comments on commit 594d0c3

Please sign in to comment.