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.

Revisions

  1. danyelhenrique created this gist Apr 6, 2023.
    25 changes: 25 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,25 @@
    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