Skip to content
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

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

Open
keslavi opened this issue Nov 20, 2018 · 0 comments
Open

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

keslavi opened this issue Nov 20, 2018 · 0 comments

Comments

@keslavi
Copy link

keslavi commented Nov 20, 2018

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) : '');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant