Calculate Value Present in Javascript

Asked

Viewed 1,164 times

2

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

VP(2,5%;48;-2052,50) which in excel returns me the value of 57,000.00 rounding down.

Can anyone help do this in javascript?

I tried to use this function I found, but it didn’t work.

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

    This is your correct function. Try PV(0.025, 48, -2052.5).

  • Actually this form worked for me, my mistake was to put 2.5 in the rate instead of 0.025. Thank you!!!

3 answers

3


David,

The VPL (Net Present Value) is the value of each instalment/tranche (PMT = Payments) "brought" to zero date at interest rate (Rate) for each of the N periods (Nper = amount of periods).

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

By adding each portion by dividing this portion by one plus the high rate to the number of each period, you get the NPV.

For example: PMT = 1000 , Rate = 0,025 (2.5% over the period) and Nper = 3:

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

Analyze the formula you are using that will discover the reason for the difference.

  • 1

    Thanks for the explanation, now I understand exactly what the formula does. And the function that I posted worked for me the only problem was to be passing the rate (rate) as 2.5 and not 0.025. Thank you!

  • Nice that you understood the "inside" formula.. Nice work!

1

With @Leo’s explanation I found that the error was to insert 2.5 as the rate, for my calculation the correct would be 0.025, so the function is correct:

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

The exit from this operation would be 57004.40

https://jsfiddle.net/a62a1ra0/

1

The function works, I believe it’s just to suit 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));

Browser other questions tagged

You are not signed in. Login or sign up in order to post.