Link to home
Start Free TrialLog in
Avatar of leebarnard
leebarnard

asked on

Algorithm to mimic Excel PV (present value) function



I need to programatically calculate present value.  Excel has the function PV(rate,nper,pmt,fv,type) that I need reproduce exactly in javascript (I would think it would basically be the same in any language).  The parameters are :
rate: interest rate per period
nper: total # of payment periods
pmt: the payment made each period
fv: the future value, or a cash balance you want to attain after the last payment is made
type: indicate if payment is made at the beginning or end of the period

Has anyone ever had to produce this mathmatical calculation in a program that they can share the algorithm with me

If I ever needed an expert this is the time.
Avatar of Dave
Dave
Flag of Australia image

the Excel PV equation is

 PV*((1+ rate)^NPER)+ PMT*(1+rate*type)*(((1+ rate)^NPER)-1)/rate+FV = 0

so rearranging to solve PV

 PV = -1*(FV+ PMT*(1+rate*type)*(((1+ rate)^NPER)-1)/rate)/((1+ rate)^NPER)

Cheers

Dave
Avatar of leebarnard
leebarnard

ASKER


I could not seem to get this equation to produce the exact same results as Excel did with the same data.  I did some further searching and found this equation that seems to produce the same results as Excel (within a few pennies)

http://www.investopedia.com/articles/03/101503.asp

thanks anyway

ASKER CERTIFIED SOLUTION
Avatar of Dave
Dave
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial

you are exactly right

thank you very much for your help
Thanks for the grade