Calculate Present Value in Javascript

2

I need to calculate the present value equivalent to the Excel formula, I have the following data:

VP (2.5%; 48; -2052.50) that excel does not return me the value of 57,000.00 rounding down.

Can anyone help with this in javascript?

I tried to use this function I found, but it did not work.

function PV(rate, nper, pmt)
{
    return pmt / rate * (1 - Math.pow(1 + rate, -nper));
}
    
asked by anonymous 30.06.2016 / 22:30

3 answers

3

David,

The VPL (Net Present Value) is the value of each installment ( PMT = PayMenTs) "brought" to the zero date at the interest rate < for each of the N periods ( Nper = number of periods).

VPL = somatório (n = 1 até Nper) de PMT / (1 + Rate) ^ n 

By adding up each installment by splitting this installment by one more rate at the number of each period, you get the NPV.

For example: PMT = 1,000 , Rate = 0.025 (2,5% per period) and Nper = 3 :

>
VPL = 1.000 / (1 + 0,025) ^ 1 + 1.000 / (1 + 0,025) ^ 2 + 1.000 / (1 + 0,025) ^ 3 

Review the formula you are using that will figure out the reason for the difference.

    
30.06.2016 / 23:43
1

The function works, I believe it's just fitting it to your purpose:

function PV(rate, nper, pmt) {
    rate = parseFloat(rate) / 100.0;
    return pmt / rate * (1 - Math.pow(1 + rate, -nper));
}

var saida =  Math.round(PV(2.5,48,-2052.5));
console.log(saida.toFixed(2));
    
01.07.2016 / 15:27
1

With the explanation of @Leo I checked that the error was to insert 2.5 as a rate, for my calculation the correct one would be 0.025, so the function is correct:

function PV(rate, nper, pmt)
{
    return pmt / rate * (1 - Math.pow(1 + rate, -nper));
}

The output of this operation would be 57004.40

link

    
01.07.2016 / 16:03