## With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

No credit card required

# 5.17. Calculating Retirement Savings

## Problem

You want to calculate how much money you’ll have at retirement, assuming you’ll receive a series of equal periodic payments.

## Solution

Calculate the future value of a series of periodic payments using the custom `Math.FV( )` function.

## Discussion

Suppose you are implementing a retirement calculator. People commonly deposit a certain amount of money each month into their retirement account. Typically, they want to know how much money they’ll accumulate in the account at some time in the future. There are two components to the accumulation of funds: the interest earned each period, plus the periodic payment that is added. The total value also includes a third component: the principal in the account at the beginning of the calculation.

Here is an enhanced version of the ```futureValue( )``` function presented in Recipe 5.16. It calculates the future value based on an initial payment plus periodic payments. We calculate the final amount by adding together the appreciation of the principal and the appreciation of the periodic payments. If the periodic payment is 0, the calculation reduces to the equation from Recipe 5.16 (in which there is principal and interest only). If there is no initial deposit, you can use 0 for the `PV` parameter. You can add this to your `Math.as` file to use it in other projects.

```Math.FV = function (interest, n, PMT, PV) {
// `PV`       = initial deposit (present value)
// `interest` = periodic interest rate
// `n` = number of payment periods ...```

## With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

No credit card required