# 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.
###### Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Commented:
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
0
Author Commented:

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

0
Commented:
Hi,

The formula will give the same answer as it is just a rearrangement of the Excel PV formula

See this example, www.vbaexpress.com/brettdj/PV.xls. The input cells are named ranges to make it easier to read

Cheers

Dave
0

Experts Exchange Solution brought to you by

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Author Commented:

you are exactly right

thank you very much for your help
0
Commented: