Skip to content

Financial functions ipmt and ppmt result in incorrect values for per=1 #17

@pverleg

Description

@pverleg

The numpy.ipmt and numpy.ppmt functions seem to misbehave when per=1. The ipmt+ppmt still equals the result of numpy.pmt, but as you can see below, ipmt results in 0 for per=1, while ppmt equals the full amount of principal+interest.

I noticed that https://github.com/numpy/numpy/blob/master/numpy/lib/financial.py contains an exception for per=1, but I do not think that should be there:
ipmt = np.where(np.logical_and(when == 1, per == 1), 0.0, ipmt)

# Principal calculation (notice second line)
numpy.ppmt(rate=0.001988079518355057, per=0, nper=360, pv=300000, fv=0, when="begin")=-568.922801885
numpy.ppmt(rate=0.001988079518355057, per=1, nper=360, pv=300000, fv=0, when="begin")=-1165.29433577
numpy.ppmt(rate=0.001988079518355057, per=2, nper=360, pv=300000, fv=0, when="begin")=-571.18717807
numpy.ppmt(rate=0.001988079518355057, per=3, nper=360, pv=300000, fv=0, when="begin")=-572.3227436
# ...etc

# Interest calculation (notice second line)
numpy.ipmt(rate=0.001988079518355057, per=0, nper=360, pv=300000, fv=0, when="begin")=-596.37153388933
numpy.ipmt(rate=0.001988079518355057, per=1, nper=360, pv=300000, fv=0, when="begin")=0.0
numpy.ipmt(rate=0.001988079518355057, per=2, nper=360, pv=300000, fv=0, when="begin")=-594.1071577047084
numpy.ipmt(rate=0.001988079518355057, per=3, nper=360, pv=300000, fv=0, when="begin")=-592.9715921748406
# ...etc

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions