Algorithm to mimic Excel PV (present value) function

Posted on 2004-11-29
Last Modified: 2010-07-27

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.
Question by:leebarnard
    LVL 50

    Expert Comment

    by:Dave Brett
    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)



    Author Comment


    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)

    thanks anyway

    LVL 50

    Accepted Solution


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

    See this example, The input cells are named ranges to make it easier to read



    Author Comment


    you are exactly right

    thank you very much for your help
    LVL 50

    Expert Comment

    by:Dave Brett
    Thanks for the grade

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    Purpose To explain how to place a textual stamp on a PDF document.  This is commonly referred to as an annotation, or possibly a watermark, but a watermark is generally different in that it is somewhat translucent.  Watermark’s may be text or graph…
    Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
    An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
    In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now