razorpay / go-financial

A go port of numpy-financial functions and more.
MIT License
310 stars 22 forks source link

Pmt returns NaN when rate is zero #13

Closed bstpierre closed 3 years ago

bstpierre commented 3 years ago

The Pmt function returns NaN when rate is zero, but it should return a value.

package main

import (
    "fmt"
    gof "github.com/razorpay/go-financial"
)

func main() {
    pmt := gof.Pmt(0, 120, 0, 120, 1)
    fmt.Printf("pmt is %f\n", pmt)
    // Should return -10
    // e.g. from numpy:
    // >>> numpy.pmt(0, 120, 0, 1200, 1)
        // -10.0
}

Note that numpy_financial handles the zero-rate case explicitly: https://github.com/numpy/numpy-financial/blob/master/numpy_financial/_financial.py#L239

gyanesh-m commented 3 years ago

Hey @bstpierre, Thanks for bringing this up. Sorry, I somehow missed it. I have raised a PR to fix this now.