Math You Don't Need

If you really like math, check out Math You Don't Need.

Tuesday, November 8, 2011

Loan Amortization

Question
How does Loan Amortization work?! Am I getting screwed?! In short, it depends. It's actually quite reasonable (though the math is a little tricky) if you are planning on paying the loan off over the lifetime of the loan. If instead you are planning on paying it off for a little while, and then cashing out (selling the house) ... well, that's not so nice since you will have paid mostly interest and your equity will still be rather small.

First some definitions:

  • Loan Amortization: When you take out a mortgage, you sign a contract agreeing to pay back the amount over some number of years (usually 15 or 30) with interest. Amortization is the act of divvying up those payments so that at the end of your payback period (those 15 or 30 years), you have fully paid back the amount you were loaned (with interest, of course).
  • Monthly payment: Each month, you pay the interest that has accrued over the last month plus a little principal. As you will see in the math below, the amount of principal you pay back changes each month (it becomes more and more of your monthly payment). The monthly payment is a set dollar amount (this is to help people budget), but as you pay off more and more of the principal, there is less and less interest that accrues each month, so the part of the monthly payment that goes towards principal grows over time.
  • Equity: The amount you have paid that didn't go toward interest. When you sell the house, you get this plus (or minus) any appreciation that has occurred.
  • Amortization Schedule: A tabular breakdown of how much interest and principal you pay for each month of the mortgage.

Math Time
Let's start by defining some variables:
  • M = monthly payment
  • A = loan amount
  • r = 1 + (yearly interest rate / 12) ... this is 1 + the monthly interest rate
  • a_0, a_1, a_i, and a_n all refer to how much principal is left to pay after some number of months
  • n = number of months to pay back the loan
  1. How much principal is left at the very beginning after no time has passed? All of it! In other words, a_0 = A.
  2. After one month has passed (a_1), how much principal is left? After one month, you have made one of your monthly payments. It includes some interest, and some principal. A*r is the total amount plus the first month's worth of interest on the total amount. So A*r - M is the total amount plus the first months worth of interest, minus the first months worth of interest and the first months worth of principal. Obviously the interest cancels out, and you have A*r - M is the amount of principal left after the first months principal is subtracted off. Now notice how I haven't really said what M is. That's because our goal is to figure out M given A, r, and n. What we're going to do is use the knowledge that a_n should be 0, or after n months the loan should be paid off. So to recap, a_1 = the amount of principal left after one month = A*r - M. Notice that a_0 = A so we could write a_1 = a_0 * r - M.
  3. Let's consider a_2. Remember that a_2 means the amount of principal left after two months. By the same logic as above, that would be the current amount of principal we have left plus the interest for this month minus the interest for this month and the principal for this month. a_2 = a_1 * r - M. If we expand this we get a_2 = (A*r - M) * r - M = A*r^2 - M*r - M.
  4. We can see that a_i = a_(i-1) * r - M, so a_i = A*r^i - M*r^(i-1) - ... - M*r - M. Let's factor a -M out of the terms that have it: a_i = A*r^i - M(r^(i-1) + r^(i-2) + ... + r + 1).
  5. Now we know that a_n = 0 since after n months are up, we have paid off the loan so the principal left is Zero (woohoo!). a_n = 0 = A*r^n - M(r^(n-1) + ... + r + 1). With a little algebra we get M = (A*r^n) / (r^(n-1) + ... + 1).
  6. The numerator looks easy enough, but if we're dealing with a 30 year mortgage, that's 360 months, so 360 terms to add up in the denominator! Lame. Luckily there's a clever as heck way to simplify the denominator using a telescoping series trick. That gives us M = (A*r^n) / ((r^n - 1) / (r - 1)). Since we have a fraction in the denominator, we can multiply by the reciprocal (this is basic algebra), and get M = (A*r^n * (r-1)) / (r^n - 1).
  7. The banks will tell you what interest rate you qualify for, so we know r. There aren't that many types of conventional loans you can get, so you can run scenarios for each loan type (15 year, 30 year, ARMs, etc) which gives you n. Finally you probably have some idea of what monthly payment you can afford so you know what M should be. Now from all of that, you can figure out A: what house price you can afford. This is a little contrived, since there are also closing costs, a downpayment, taxes and insurance (which are pretty heavy), initial repairs, inspections, and potentially other costs as well as tax breaks.

Final Answers
Using basic algebra we get:
  • M = (A*r^n * (r-1)) / (r^n - 1)
  • A = M(r^n-1) / ((r-1) * r^n)
  • r and n ... bah! (comment if you can figure them out, I don't feel like it and those probably aren't questions you need answered)
Let's look at an example ... how about my mortgage.
I bought a house for $229,000 and put 20% down so my mortgage was for $183,200. It was for a term of 30 years, or 360 months at an interest rate of 4.5%.
Thus M = (183200 * (1+(.045/12))^360 * (1 + (.045/12) - 1)) / ((1+(.045/12))^360 - 1) = 183200 * 1.00375^360 * .00375 / (1.00375^360 - 1) = $928.25.
Note that if I paid that amount for 360 months, I would be paying $334,170 for a total amount of 82.4% or $150,970 in interest paid. That might seem like a staggering amount, however house values tend to appreciate over time (national averages are usually stated around the inflation rate of 3-5% per year). So if my house appreciates by 3% per year, then based on the math in Savings Account, my house will be worth 229000*(1.03)^30 = $555,843.11, for a total appreciation of 142.7% or $326,843.11. Again this is contrived since it doesn't take into account the multitude of situation that can occur in 30 years, but just looking at interest, things don't look so bad and house purchasing as opposed to renting can become financially sound.

What I haven't mentioned is how boned you are if you turn around and sell your house. For that we will need to determine how much of your monthly payments go towards interest and how much go towards principal. We kind of already know the interest part. The interest after the first month is the monthly rate, we'll use R (which is different than the r we used above), times the amount currently owed, or A*R. Since the monthly payment is just the interest plus the principal paid for any given month, M - A*R is the principal paid for the first month. For the second month we have A - (M - A*R) as the principal left so the interest is (A - (M - A*R)*R = (A + A*R - M)*R = A*R + A*R^2 - M*R, and the principal paid is M minus that, or M - A*R - A*R^2 + M*R = M + M*R - A*R - A*R^2. Let's look at the total interest and principal paid so far. The interest is A*R + A*R + A*R^2 - M*R or 2A*R + A*R^2 - M*R. When I start seeing a pattern like this I get a little worried. My intuition tells me I will have a large number of terms to figure out. So I'll just cheat and write a looping python program.

def amnts(loan_amount, yearly_rate, months_paid, monthly_payment):
    monthly_rate = yearly_rate / (12.0 * 100)
    total_int_paid = 0
    total_pr_paid = 0
    interest_paid = 0
    principal_paid = 0
    for i in range(0,months_paid):
        interest_paid = loan_amount * monthly_rate
        principal_paid = monthly_payment - interest_paid
        loan_amount -= principal_paid
        total_int_paid += interest_paid
        total_pr_paid += principal_paid
        print str(i+1) + ': int: ' + str(interest_paid) + ', pr: ' + str(principal_paid)
    print 'total int: ' + str(total_int_paid) + ', total pr: ' + str(total_pr_paid)

Call the function with amnts(183200, 4.5, 24, 928.25)
Output:
1: int: 687.0, pr: 241.25
2: int: 686.0953125, pr: 242.1546875
3: int: 685.187232422, pr: 243.062767578
4: int: 684.275747043, pr: 243.974252957
5: int: 683.360843595, pr: 244.889156405
6: int: 682.442509258, pr: 245.807490742
7: int: 681.520731168, pr: 246.729268832
8: int: 680.59549641, pr: 247.65450359
9: int: 679.666792021, pr: 248.583207979
10: int: 678.734604992, pr: 249.515395008
11: int: 677.79892226, pr: 250.45107774
12: int: 676.859730719, pr: 251.390269281
13: int: 675.917017209, pr: 252.332982791
14: int: 674.970768523, pr: 253.279231477
15: int: 674.020971405, pr: 254.229028595
16: int: 673.067612548, pr: 255.182387452
17: int: 672.110678595, pr: 256.139321405
18: int: 671.15015614, pr: 257.09984386
19: int: 670.186031726, pr: 258.063968274
20: int: 669.218291845, pr: 259.031708155
21: int: 668.246922939, pr: 260.003077061
22: int: 667.2719114, pr: 260.9780886
23: int: 666.293243568, pr: 261.956756432
24: int: 665.310905731, pr: 262.939094269
total int: 16231.302434, total pr: 6046.69756598

So I will have paid $22,278.00, of which $6,046.70 will be equity. Now lets look at appreciation on top of this: 229000(1.03)^2 = $242,946.10. So I will actually have $6,046.70 + $13,946.10 = $19,992.8 in equity. Hmm ... I don't feel too boned. The moral here? Someone won't let you make use of a large sum of their money for nothing, so they charge interest on the loan. If you do more than just hold onto it, such as invest it in real estate (which is what you are doing when you buy a house), then you can actually turn a mortgage into a win-win scenario. Money has to come from somewhere, so if the lender is making money, and you are making money, then where is that money coming from? The next buyer (the future). The lender is making money on you, and you're making money on the next buyer (unless you buy a house that isn't worth as much as you paid for it or it depreciates, or a slew of other things happen).

This was a large one to tackle. Please comment and ask questions. Other people reading this will probably have the same questions, so you'll be helping them out too!

No comments:

Post a Comment