diff options
author | Charles Harris <charlesr.harris@gmail.com> | 2015-02-17 15:01:29 -0700 |
---|---|---|
committer | Charles Harris <charlesr.harris@gmail.com> | 2015-02-17 15:01:29 -0700 |
commit | a9a80fc4a5ed8fb2faba1e1102121468a905c908 (patch) | |
tree | 7c28ffe9ca55e3d14748aeb67e9759041c8816f6 /numpy/lib/financial.py | |
parent | 97917ac8d45c54aa99453b350cd1834a121d1d29 (diff) | |
download | numpy-a9a80fc4a5ed8fb2faba1e1102121468a905c908.tar.gz |
MAINT: Simplify fix for rate == 0 in financial.pmt.
Diffstat (limited to 'numpy/lib/financial.py')
-rw-r--r-- | numpy/lib/financial.py | 13 |
1 files changed, 5 insertions, 8 deletions
diff --git a/numpy/lib/financial.py b/numpy/lib/financial.py index 9ec6fc06b..a7e4e60b6 100644 --- a/numpy/lib/financial.py +++ b/numpy/lib/financial.py @@ -208,14 +208,11 @@ def pmt(rate, nper, pv, fv=0, when='end'): """ when = _convert_when(when) (rate, nper, pv, fv, when) = map(np.asarray, [rate, nper, pv, fv, when]) - temp = (1+rate)**nper - miter = np.broadcast(rate, nper, pv, fv, when) - zer = np.zeros(miter.shape) - fact = np.zeros(miter.shape) - numerator = (1 + rate * when) * ( temp - 1) - np.divide(numerator, rate, where = ( rate!= 0), out= fact) - factforZeroRate = nper + zer - np.copyto(fact, factforZeroRate, where = (rate==0)) + temp = (1 + rate)**nper + mask = (rate == 0.0) + np.copyto(rate, 1.0, where=mask) + z = np.zeros(np.broadcast(rate, nper, pv, fv, when).shape) + fact = np.where(mask != z, nper + z, (1 + rate*when)*(temp - 1)/rate + z) return -(fv + pv*temp) / fact def nper(rate, pmt, pv, fv=0, when='end'): |