felixfan / FinCal

Package for time value of money calculation, time series analysis and computational finance
http://felixfan.github.io/FinCal/
22 stars 13 forks source link

fv.annunity fails for zero discount rate #2

Open jsjuni opened 1 year ago

jsjuni commented 1 year ago

Although an edge case, the value of an annuity with a zero discount rate is mathematically well-defined. The formula in fv.annuity(), however, divides by r and returns NaN for a zero discount rate.

I've made a fix and will submit a pull request. The value for the zero discount rate case is the limit (using L'Hôpital's rule) as r goes to zero.

jsjuni commented 1 year ago

I've made similar updates to pv.annuity(), n.period(), and pmt().