8000 BUG: financial.pmt warns of zero divide when rate == 0. by charris · Pull Request #5577 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

BUG: financial.pmt warns of zero divide when rate == 0. #5577

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 18, 2015
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
MAINT: Simplify fix for rate == 0 in financial.pmt.
  • Loading branch information
charris committed Feb 17, 2015
commit a9a80fc4a5ed8fb2faba1e1102121468a905c908
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