Recipe 5.18 Calculating the Loan (Mortgage) You Can Afford

5.18.1 Problem

You want to calculate how large a loan you can get assuming you make a given monthly payment.

5.18.2 Solution

Calculate the present value of a series of equal future periodic payments using the custom Math.PV( ) function.

5.18.3 Discussion

Suppose you are a bank with a big pile of money and you want to lend it to someone to earn some interest. The borrower might come to you and say, "I can pay you back $1,000 per month for 30 years. How much money will you loan me?" The answer requires you to calculate how much the money that you will receive at various times in the future (as a series of periodic payments) is worth today.

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

Math.PV = function (i, n, PMT) {
  // i   = periodic interest rate
  // n   = number of payment periods
  // PMT = periodic payment
  // Present value compounded over n periods: 
  // PV = PMT * ( (multiplier-1)/(i*multiplier))
  // where multiplier = Math.pow ((1 + i), n)
  multiplier = Math.pow ((1 + i), n);
  PV = PMT * (multiplier-1) / (i*multiplier); 
  return PV;

You can use the custom Math.PV( ) method as follows:

// How much will the bank loan me if I can pay $1000/month for 30 years (6% rate)?
trace (Math.PV(.06/12, 30*12, 1000));

5.18.4 See Also

Recipe 5.6, Recipe 5.16, Recipe 5.17, and Recipe 5.19. You can consult a financial textbook for the derivation of the preceding formula. It is essentially based on the reverse of the process used in Recipe 5.16 to calculate the future value. .

    Part I: Local Recipes
    Part II: Remote Recipes