summaryrefslogtreecommitdiff
path: root/numpy/lib/financial.py
diff options
context:
space:
mode:
authorCharles Harris <charlesr.harris@gmail.com>2009-08-26 03:43:46 +0000
committerCharles Harris <charlesr.harris@gmail.com>2009-08-26 03:43:46 +0000
commit4176f33526beb6f1efd0efd1cbdd89ab103c72b6 (patch)
treedcdccfcbba4f00827ac073ac2093ab929cc5ca0f /numpy/lib/financial.py
parent183609e2de003e953b0c7f01fa35eeb46fc61ea0 (diff)
downloadnumpy-4176f33526beb6f1efd0efd1cbdd89ab103c72b6.tar.gz
Make some fixes in mirr implementation to avoid overflow in
summing booleans. Do some whitespace cleanup.
Diffstat (limited to 'numpy/lib/financial.py')
-rw-r--r--numpy/lib/financial.py10
1 files changed, 5 insertions, 5 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