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.
leebarnardAsked:
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.

DaveCommented:
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
leebarnardAuthor 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
DaveCommented:
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

Your issues matter to us.

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

Start your 7-day free trial
leebarnardAuthor Commented:

you are exactly right

thank you very much for your help
0
DaveCommented:
Thanks for the grade
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.