Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save danyelhenrique/5289b57de7142497cef312f7cd2f6501 to your computer and use it in GitHub Desktop.

Select an option

Save danyelhenrique/5289b57de7142497cef312f7cd2f6501 to your computer and use it in GitHub Desktop.
Formula PGTO
function pgto(tax, period, currentValue, valueFuture, type) {
let pmt, currentValueIf;
valueFuture || (valueFuture = 0);
type || (type = 0);
if (tax === 0)
return -(currentValue + valueFuture) / period;
currentValueIf = Math.pow(1 + tax, period);
pmt =
(-tax * (currentValue * currentValueIf + valueFuture)) / (currentValueIf - 1);
if (type === 1)
pmt /= (1 + tax);
return pmt;
}
let tax = 2.04/100;
let period = 5;
let currentValue = 500;
let pmt = pgto(tax, period, currentValue).toFixed(2) * -1;
console.log(pmt); // <- Log result
@danyelhenrique
Copy link
Author

Formula PGTO in Javascript

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment