|
13 | 13 |
|
14 | 14 |
|
15 | 15 | class TestFinancial(object): |
16 | | - def test_rate(self): |
17 | | - assert_almost_equal(npf.rate(10, 0, -3500, 10000), 0.1107, 4) |
18 | | - |
19 | | - @pytest.mark.parametrize('number_type', [Decimal, float]) |
20 | | - @pytest.mark.parametrize('when', [0, 1, 'end', 'begin']) |
21 | | - def test_rate_with_infeasible_solution(self, number_type, when): |
22 | | - """ |
23 | | - Test when no feasible rate can be found. |
24 | | -
|
25 | | - Rate will return NaN, if the Newton Raphson method cannot find a |
26 | | - feasible rate within the required tolerance or number of iterations. |
27 | | - This can occur if both `pmt` and `pv` have the same sign, as it is |
28 | | - impossible to repay a loan by making further withdrawls. |
29 | | - """ |
30 | | - result = npf.rate(number_type(12.0), |
31 | | - number_type(400.0), |
32 | | - number_type(10000.0), |
33 | | - number_type(5000.0), |
34 | | - when=when) |
35 | | - is_nan = Decimal.is_nan if number_type == Decimal else numpy.isnan |
36 | | - assert is_nan(result) |
37 | | - |
38 | | - def test_rate_decimal(self): |
39 | | - rate = npf.rate(Decimal('10'), Decimal('0'), Decimal('-3500'), |
40 | | - Decimal('10000')) |
41 | | - assert_equal(Decimal('0.1106908537142689284704528100'), rate) |
42 | | - |
43 | 16 | def test_pv(self): |
44 | 17 | assert_almost_equal(npf.pv(0.07, 20, 12000, 0), -127128.17, 2) |
45 | 18 |
|
@@ -120,6 +93,35 @@ def test_decimal_with_when(self): |
120 | 93 | Decimal('0'), 'end')) |
121 | 94 |
|
122 | 95 |
|
| 96 | +class TestRate: |
| 97 | + def test_rate(self): |
| 98 | + assert_almost_equal(npf.rate(10, 0, -3500, 10000), 0.1107, 4) |
| 99 | + |
| 100 | + @pytest.mark.parametrize('number_type', [Decimal, float]) |
| 101 | + @pytest.mark.parametrize('when', [0, 1, 'end', 'begin']) |
| 102 | + def test_rate_with_infeasible_solution(self, number_type, when): |
| 103 | + """ |
| 104 | + Test when no feasible rate can be found. |
| 105 | +
|
| 106 | + Rate will return NaN, if the Newton Raphson method cannot find a |
| 107 | + feasible rate within the required tolerance or number of iterations. |
| 108 | + This can occur if both `pmt` and `pv` have the same sign, as it is |
| 109 | + impossible to repay a loan by making further withdrawls. |
| 110 | + """ |
| 111 | + result = npf.rate(number_type(12.0), |
| 112 | + number_type(400.0), |
| 113 | + number_type(10000.0), |
| 114 | + number_type(5000.0), |
| 115 | + when=when) |
| 116 | + is_nan = Decimal.is_nan if number_type == Decimal else numpy.isnan |
| 117 | + assert is_nan(result) |
| 118 | + |
| 119 | + def test_rate_decimal(self): |
| 120 | + rate = npf.rate(Decimal('10'), Decimal('0'), Decimal('-3500'), |
| 121 | + Decimal('10000')) |
| 122 | + assert_equal(Decimal('0.1106908537142689284704528100'), rate) |
| 123 | + |
| 124 | + |
123 | 125 | class TestNpv: |
124 | 126 | def test_npv(self): |
125 | 127 | assert_almost_equal( |
|
0 commit comments