From 4176f33526beb6f1efd0efd1cbdd89ab103c72b6 Mon Sep 17 00:00:00 2001 From: Charles Harris Date: Wed, 26 Aug 2009 03:43:46 +0000 Subject: Make some fixes in mirr implementation to avoid overflow in summing booleans. Do some whitespace cleanup. --- numpy/lib/financial.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'numpy/lib/financial.py') 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 -- cgit v1.2.1