|
9 | 9 | )
|
10 | 10 |
|
11 | 11 | import numpy_financial as npf
|
| 12 | +import pytest |
12 | 13 |
|
13 | 14 |
|
14 | 15 | class TestFinancial(object):
|
@@ -410,3 +411,30 @@ def test_broadcast_decimal(self):
|
410 | 411 | [Decimal('-74.998201'), Decimal('-75.62318601'),
|
411 | 412 | Decimal('-75.62318601'), Decimal('-76.88882405'),
|
412 | 413 | Decimal('-76.88882405')], 4)
|
| 414 | + |
| 415 | + @pytest.mark.parametrize('number_type', [Decimal, float]) |
| 416 | + def test_rate_nan(self, number_type): |
| 417 | + """ |
| 418 | + Test for checking inputs whose output is NaN |
| 419 | + Rate will return NaN, if newton raphson method's change or diff was not able to become |
| 420 | + less than default tolerance value i.e. 1e-6 in max iterations possible, |
| 421 | + Both payments and present value are positive, it is impossible to pay off the existing balance |
| 422 | + by making further withdrawals, regardless of the rate. |
| 423 | + """ |
| 424 | + rate = npf.rate(number_type(12.0), number_type('400.0'), number_type('10000.0'), number_type(0)) |
| 425 | + assert_equal(numpy.nan, float(rate)) |
| 426 | + rate = npf.rate(number_type(12.0), number_type('400.0'), number_type('10000.0'), number_type(5000)) |
| 427 | + assert_equal(numpy.nan, float(rate)) |
| 428 | + |
| 429 | + # begin |
| 430 | + rate = npf.rate(number_type(12.0), number_type('400.0'), number_type('10000.0'), number_type(20000), 1) |
| 431 | + assert_equal(numpy.nan, float(rate)) |
| 432 | + rate = npf.rate(number_type(12.0), number_type('400.0'), number_type('10000.0'), number_type(20000), 'begin') |
| 433 | + assert_equal(numpy.nan, float(rate)) |
| 434 | + |
| 435 | + # end |
| 436 | + rate = npf.rate(number_type(12.0), number_type('400.0'), number_type('10000.0'), number_type(0)) |
| 437 | + assert_equal(numpy.nan, float(rate)) |
| 438 | + rate = npf.rate(number_type(12.0), number_type('400.0'), number_type('10000.0'), number_type(0), 'end') |
| 439 | + assert_equal(numpy.nan, float(rate)) |
| 440 | + |
0 commit comments