Home | Mathematics |     Share This Page
Finance Calculator

Version 4.5 2015.11.23

Copyright © 2015, P. LutusMessage Page

Calculator | Tutorial | Customization
Programming Notes

(double-click any word to see its definition)

Includes programming notes, math tutorial, and equations

Present Value
Future Value
Number of Periods
Payment Amount
Interest Rate per period, %
Payment At: Beginning End

Instructions: Type in four known values, then press one of the buttons at the right to compute the unknown value.

(to solve an example problem, press the "$fv$" button above)

Remember to use negative values for owed balances and money paid into the account, positive values for balances in your favor and money withdrawn from the account. Also enter the interest rate per period, not per year. If you are making monthly payments and have an annual interest rate, divide the annual rate by 12 (and see "Interest rate per period" for an explanation). Thus, one period of an 8% annual rate is 8/12 and is entered as .666666.

Interest computation is not a simple matter of applying an equation, and many problems have more than one solution, only one of which is likely to be meaningful. If you get an interest rate that doesn't seem right, try entering an approximation of the expected rate, then press "$ir$" again.
These equations solve problems that involve compound interest. With one exception, each kind of problem can be solved immediately, using a well-defined equation. The exception, as Isaac Newton discovered, is that interest computation requires iteration and may result in several solutions.

The variables used are:
  • $pv$ (present value) = The starting balance in an account. This number can be zero, positive (when you take out a loan), or negative (when you make a deposit).
  • $fv$ (future value) = The ending balance after the specified number of payment periods ($np$).
  • $np$ (number of periods) = The number of payment periods, usually expressed in months.
  • $pmt$ (payment) = The amount of each periodic payment, usually a negative amount.
  • $ir$ (interest rate) = The per-period interest rate on the account.

These equations are similar to those used to calculate Population Increase , but they allow you to specify interest and payments as separate variables.

An Example

Let's say you want to know how much money you will have in an investment that has an annual interest rate of 12%. The account has a starting balance of \$0.00 and you are planning to deposit \$100 per month. For the interest rate per period (per month in this case), divide the annual interest rate of 12% by 12 = 1% per month (is this correct?). Result: in 10 years (120 months) you will have a balance of \$23,003.87 (click here to test this result with the calculator above).

Equation List

Here are the equations for all the directly computable forms this problem can take, including the variations created by choosing payment-at-beginning and payment-at-end.

Payment at End:

\begin{equation} pv = \frac{1}{ir\,} \left(ir\, + 1\right)^{- np\,} \left(- fv\, ir\, - pmt\, \left(ir\, + 1\right)^{np\,} + pmt\,\right) \end{equation} \begin{equation} fv = \frac{1}{ir\,} \left(- ir\, pv\, \left(ir\, + 1\right)^{np\,} - pmt\, \left(ir\, + 1\right)^{np\,} + pmt\,\right) \end{equation} \begin{equation} np = \frac{\log{\left (\frac{- fv\, ir\, + pmt\,}{ir\, pv\, + pmt\,} \right )}}{\log{\left (ir\, + 1 \right )}} \end{equation} \begin{equation} pmt = - \frac{ir\, \left(fv\, + pv\, \left(ir\, + 1\right)^{np\,}\right)}{\left(ir\, + 1\right)^{np\,} - 1} \end{equation}

Payment at Beginning:

\begin{equation} pv = - fv\, \left(ir\, + 1\right)^{- np\,} - pmt\, + pmt\, \left(ir\, + 1\right)^{- np\,} - \frac{pmt\,}{ir\,} + \frac{pmt\,}{ir\,} \left(ir\, + 1\right)^{- np\,} \end{equation} \begin{equation} fv = \frac{1}{ir\,} \left(- ir\, \left(pmt\, \left(ir\, + 1\right)^{np\,} - pmt\, + pv\, \left(ir\, + 1\right)^{np\,}\right) - pmt\, \left(ir\, + 1\right)^{np\,} + pmt\,\right) \end{equation} \begin{equation} np = \frac{1}{\log{\left (ir\, + 1 \right )}} \log{\left (\frac{- fv\, ir\, + ir\, pmt\, + pmt\,}{ir\, pmt\, + ir\, pv\, + pmt\,} \right )} \end{equation} \begin{equation} pmt = - \frac{ir\, \left(fv\, + pv\, \left(ir\, + 1\right)^{np\,}\right)}{ir\, \left(ir\, + 1\right)^{np\,} - ir\, + \left(ir\, + 1\right)^{np\,} - 1} \end{equation}

When using these equations, be sure to use negative values for owed balances and money paid into the account, positive values for balances in your favor and money withdrawn from the account. For these equations, enter percentages as ratios, thus 8% = 0.08 — yes, the financial calculator at the top of the page accepts percentages as integers, but these equations are more portable and universal in part because they avoid certain kinds of hand-holdy conversions.

There are several boundary conditions implicit in these equations (conditions for which no meaningful result can be obtained). Example: if a payment is chosen that exactly offsets the accrued interest per period and you try to solve for $np$, the computation will fail because there are an infinite number of periods in that case.

Math Notes

Status indicator: There is a status indicator at the bottom of the calculator display to alert you that the computation is not complete. This indicator is meant to remind you that new numbers have been entered but a value button has not yet been pressed, which means the displayed values may not represent a consistent result.

Interest rate per period: This business of dividing an interest rate by 12 is not mathematically correct, but since banks use the procedure* it's wise to go along, otherwise your numbers will not agree with those of the bank.

Interest rate ($ir$) computation: The case of $ir$ cannot be solved without iteration (using a method for which we are indebted to Isaac Newton). This calculator solves for $ir$ using an efficient iteration method that will work for most problems, but a multiple-root possibility exists (more than one correct, if meaningless, result). If a particular problem will not yield an interest rate or produces a meaningless rate, you may want to try typing an estimate of the correct rate in the interest rate display window and pressing the "$ir$" button again.


While reviewing the access logs for arachnoid.com, I noticed some visitors had been trying to specify values for Financial Calculator to save time when computing common problems. This is a useful feature, so I have added it to the current version of Financial Calculator.

Here is an example of an URL that specifies values for Financial Calculator in order to compute a payment amount:


If you click the link above, it will reload this page and insert the values listed at the right. This feature allows you to predefine a problem in a link to this page.

In this example problem, the defined values are $pv$, $fv$, $np$, and $ir$. Because four of the five financial variables have been defined, the fifth variable ($pmt$) will be calculated as the page loads.

Here is an example URL that a Web page designer might create to call this page with predefinend values:

<a href="http://www.arachnoid.com/finance/index.html?pv=0&fv=100000&np=200&ir=1&pb=false">compute PMT</a>

The basic URL syntax for using this feature looks like this:

http://example.com/page_name.html?name1=value1&name2=value2&name3=value3 (etc.)

Normally the calling parameters are added to the URL that identifies this page.

The idea of this feature is that if a caller provides any four of the five required financial variables, the fifth value will be computed. If fewer or greater than four values are provided, they are accepted into the calculator, but no computation is performed (and the status indicator alerts you that the computation is not complete).

There is one special variable supported by this feature that is not named in the formal description provided earlier (and that is not counted in the total of four financial values) — the value $pb$, which means "payment at beginning." If you set this value to "true" or "false" in a calling URL, the calculator will accept your choice and compute accordingly. Defining this value is optional*, but if you want consistent results, it's a good idea to specify it.

Programming Notes

In a recent revision, to improve this page's appearance and avoid the possibility of typographical errors I decided to automatically generate all the financial equation's computable forms by deriving them from a canonical equation I wrote many years ago:

\begin{equation} fv\, = \frac{1}{ir\,} \left(pmt\, \left(ir\, pb\, + 1\right) - \left(ir\, + 1\right)^{np\,} \left(ir\, pb\, pmt\, + ir\, pv\, + pmt\,\right)\right) \end{equation}

Using the Python symbolic math library sympy, which over a period of years has become quite powerful, I set up a code block in which the above equation is solved for each of its computable variables (interest rate can't be computed directly):

from sympy import *

var('pv fv np pmt ir pb')

# the base equation from which all others are derived

bfe = fv - ((pb*ir+1)*pmt-(ir+1)**np*((pb*ir*pmt)+pmt+ir*pv))/ir

results = []
# for payment at end|beginning
for p in (0,1):
  # solve for each variable
  for v in (pv,fv,np,pmt):
    q = solve(bfe,v)[0].subs({pb:p}).simplify()
    # create insertable LaTeX block for Web page
    pprint(str(v) + ' = ' + padspace(latex(q)))

The idea of the LaTeX generator is that it exploits the existence of MathJax rendering support in this page to display the equations with little struggle or chance for errors.

This arrangement has a number of advantages, among which are a great reduction in effort, and a way to avoid the kinds of transcription errors that make online code listings so unreliable.

I also created numerical functions for each of the equation forms and tested them for consistency:

fpv = lambdify((fv,np,pmt,ir),results[0])
ffv = lambdify((pv,np,pmt,ir),results[1])
fnp = lambdify((pv,fv,pmt,ir),results[2])
fpmt = lambdify((pv,fv,np,ir),results[3])

ppmt = fpmt(0,100000,200,0.01)

y = ffv(0,200,ppmt,0.01)
x = fpv(y,200,ppmt,0.01)
In the above test, I compute a payment amount for an ending balance of 100,000 after 200 payment periods. I then apply that payment amount to a round-robin in which a future value is computed, then that future value is applied to tbe problem of computing a present value for the same parameters. The results were:

The second value, which in principle should be zero, shows the effect of limited precision in computer numerical mathematics.

This programming effort honors the mathematical principle that applications of an established, reliable result should be derived carefully, with as little room for error as possible.

The full Python listing to generate the above results is located here.

Home | Mathematics |     Share This Page