Skip to content

PMT not calculated same as Excel (yes I know it's OpenOffice) #66

Description

@keslavi

hey, I know this is an OpenOffice port, but I noticed that the implementation doesn't return the same PMT as Excel.

(Excel Example)
rate | time | principle | pmt |  
0.1 | 12 | 2000 | ($293.53) | =PMT(A2,B2,C2)

exports.PMT = function(rate, periods, present, future, type) {
      //formula:
      //PMT = PV x IR / (1 - (1 + IR) -NP)
      //converted to js:
      //PMT = (PV * IR) / (1 - Math.pow(1 + IR, -NP))
      //(ir,np,pv) =>{//(rate, time, principle)
  let pay = (present * rate) / (1 - Math.pow(1 + rate, -periods));
  return -pay;
  //your implementation goes on for additional  work but this was all I needed for mine

I'm comparing the values to an Excel sheet calculating PMT from $100-$5000 for a time period of 1-18 months and the above PMT lines up with Excel through the whole sheet.

Also, though this isn't technically an Excel function, I also use .toMoney to format like excel:

// eslint-disable-next-line
Number.prototype.toMoney = function(decimals, decimal_sep, thousands_sep)
{
     var n = this,
     c = isNaN(decimals) ? 2 : Math.abs(decimals),
     d = decimal_sep || '.',
     t = (typeof thousands_sep === 'undefined') ? ',' : thousands_sep,
     sign = (n < 0) ? '-' : '',
     // eslint-disable-next-line
     i = parseInt(n = Math.abs(n).toFixed(c)) + '',
     // eslint-disable-next-line
     j = ((j = i.length) > 3) ? j % 3 : 0;
     return sign + (j ? i.substr(0, j) + t : '') + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + t) + (c ? d + Math.abs(n - i).toFixed(c).slice(2) : '');
}

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