diff options
author | Charles Harris <charlesr.harris@gmail.com> | 2009-08-26 03:43:46 +0000 |
---|---|---|
committer | Charles Harris <charlesr.harris@gmail.com> | 2009-08-26 03:43:46 +0000 |
commit | 4176f33526beb6f1efd0efd1cbdd89ab103c72b6 (patch) | |
tree | dcdccfcbba4f00827ac073ac2093ab929cc5ca0f /numpy/lib | |
parent | 183609e2de003e953b0c7f01fa35eeb46fc61ea0 (diff) | |
download | numpy-4176f33526beb6f1efd0efd1cbdd89ab103c72b6.tar.gz |
Make some fixes in mirr implementation to avoid overflow in
summing booleans. Do some whitespace cleanup.
Diffstat (limited to 'numpy/lib')
-rw-r--r-- | numpy/lib/financial.py | 10 | ||||
-rw-r--r-- | numpy/lib/tests/test_financial.py | 2 |
2 files changed, 6 insertions, 6 deletions
diff --git a/numpy/lib/financial.py b/numpy/lib/financial.py index 496e960fc..5d1e65f5c 100644 --- a/numpy/lib/financial.py +++ b/numpy/lib/financial.py @@ -625,17 +625,17 @@ def mirr(values, finance_rate, reinvest_rate): """ - values = np.asarray(values) + values = np.asarray(values, dtype=np.double) initial = values[0] values = values[1:] n = values.size pos = values > 0 neg = values < 0 - if not (pos.sum() > 0 and neg.sum() > 0): + if not (pos.any() and neg.any()): return np.nan numer = np.abs(npv(reinvest_rate, values*pos)) denom = np.abs(npv(finance_rate, values*neg)) - if initial > 0: - return ((initial + numer) / denom)**(1.0/n)*(1+reinvest_rate) - 1 + if initial > 0: + return ((initial + numer) / denom)**(1.0/n)*(1 + reinvest_rate) - 1 else: - return ((numer / (-initial + denom)))**(1.0/n)*(1+reinvest_rate) - 1 + return ((numer / (-initial + denom)))**(1.0/n)*(1 + reinvest_rate) - 1 diff --git a/numpy/lib/tests/test_financial.py b/numpy/lib/tests/test_financial.py index 0ad3766bf..3c9703621 100644 --- a/numpy/lib/tests/test_financial.py +++ b/numpy/lib/tests/test_financial.py @@ -43,7 +43,7 @@ class TestFinancial(TestCase): v2 = [-120000,39000,30000,21000,37000,46000] assert_almost_equal(np.mirr(v2,0.10,0.12), 0.1344, 4) - + v3 = [100,200,-50,300,-200] assert_almost_equal(np.mirr(v3,0.05,0.06), 0.3428, 4) |