5.18. Calculating the Loan (Mortgage) You Can Afford
Problem
You want to calculate how large a loan you can get assuming you make a given monthly payment.
Solution
Calculate the present value of a series of equal future periodic
payments using the custom Math.PV( )
function.
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
Math.as
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 overn
periods: //PV
=PMT
* ( (multiplier
-1)/(i
*multiplier
)) // wheremultiplier
=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));
See Also
Recipe 5.6, Recipe 5.16, Recipe 5.17, and Recipe 5.19. You can consult ...
Get Actionscript Cookbook now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.