Skip to content

Commit

Permalink
MAINT: Simplify fix for rate == 0 in financial.pmt.
Browse files Browse the repository at this point in the history
  • Loading branch information
charris committed Feb 17, 2015
1 parent 97917ac commit a9a80fc
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions numpy/lib/financial.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'):
Expand Down

0 comments on commit a9a80fc

Please sign in to comment.