# Recipe 5.19 Calculating Loan Amortization or Annuities

#### 5.19.1 Problem

You want to determine the monthly payment it takes to pay off a loan (i.e., amortize the loan). Alternatively, you want to know how much money you can withdraw from a retirement account on a periodic basis.

#### 5.19.2 Solution

Calculate the payments using the custom Math.PMT( ) function.

#### 5.19.3 Discussion

Suppose you want to borrow \$100,000 from a bank, and you need to know the required monthly payment to pay back the loan. The answer requires the bank to calculate how much money is needed to pay off the principal and the interest that accrues before the loan is finally paid off in full. The calculation is equivalent to the one needed to calculate how much money you can take out monthly from a retirement account. However, in the case of a so-called annuity, you start with the lump sum and extract a series of periodic payments. The math still answers the question, "Given an initial pile of money and the prevailing interest rate, how much money can I take out (or must I pay back) each month before the balance is zero?"

The following custom Math.PMT( ) function returns the same value as the one obtained in Microsoft Excel using the Insert Function Financial PMT formula. You can add this to your Math.as file for easy inclusion in other projects.

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

// Calculate the periodic payment needed to amortize (pay back) a loan.
multiplier = Math.pow((1 + i), n);

return (PV * i * multiplier / (multiplier - 1));
};

// Example usage:
// What monthly payment pays back a \$100,000 mortgage (30-year fixed at 6%)?
trace("Your monthly payment is " + Math.PMT (0.06/12, 30*12, 100000));```