Loans

It is common to take out loans that are repaid on a fixed-rate, fixed-term
repayment schedule. For example, home mortgages are often paid off with thirty
years of monthly payments, while car loans are paid off over three or four
years. A feature of such repayment schedules is that the same amount is paid
each month. At the beginning, most of the payment goes for interest; by the
end, most of the payment is going toward principal.

Suppose that you borrow $100,000 at an annual interest rate of 7%, and you
are wondering what your monthly payment should be. All you know is that your
monthly payment should be the same throughout the life of the loan, and that
your loan should be paid back at the end of 30 years. Let's see how you can
use what you've just learned to analyze this problem.

Since we are trying to figure out what your monthly payment should be, let's
use the variable p to stand for it for the time being. At the end of each
month you must pay 7/12% of the current loan balance in interest. Clearly,
you and the bank want your monthly payment to be sufficient to at least cover
the interest each month. Can you calculate a lower bound on the monthly
payment?

Click here for the answer

We can approach this problem by setting up a recurrence relation. Let's let
B(i) be the loan balance at the end of the ith month of the loan. For
example, B(0) will be the beginning loan balance and B(12) will be the loan
balance after one year. The base case of the recurrence is easy, since we know
that the initial loan balance is $100,000:

B(0) = 100000

The other half of the recurrence relation requires more thought. When you make
a monthly payment, part of it will go to pay for interest and the remainder
will go to bring down the loan balance. Thus, the balance at the end of each
month will be the difference between

(1) the previous month's balance and

(2) the amount of principal that is included in this month's payment.

The amount of principal that is included in this month's payment will be equal
to the difference between the monthly payment and the amount of interest due on
last month's interest. This is all easier to understand in symbols:

B(i) = B(i-1) - ( p - (.07/12)*B(i-1) )

Be sure that you understand where this equation comes from before continuing.


The formula given above is a difference equation. It gives a
relationship for the balance at two different times and the
payment. Rather than using specific numbers, let's try to solve the problem entirely in symbols. What we would like to know is what the payment has to
be to retire the loan of initial balance B taken out at annual rate r in a period of
T years.

There are several different approaches whch can be taken to this problem,
but perhaps the simples way to is to solve the difference equation backwards.
At time T, the loan is paid off so the balance is 0. This
means that the balance at time T-1 must satisfy

0 = B(T-1)*(1+r) - p

so

B(T-1) = p/(1+r)

Similarly, B(T-2) must satisfy

B(T-1)= p/(1+r)
=B(T-2)*(1+r) - p

which means

B(T-2) = p/(1+r)*[ 1 + 1/(1+r) ] = p*[ 1/(1+r) +1/(1+r)^2 ] .

Continuing in this way,it is pretty easy to see the pattern
emering:

B(T-k) = p*Sum[ (1+r)^(-t), {t, 1, k} ]

Applying this formula to period 0 we have

B(0) = p* Sum[ (1+r)^(-t), {t, 1, T} ]

From this it follows immediately that the payment is

p = B(0) / Sum[ (1+r)^(-t), {t, 1, T} ]

The sum in the denominator of this expression can be simplified. It is an
example of a ``geometric series'' and quite possibly you already know, say
from your calculus or precalculus classes, how it comes out. But let's use
another symbolic computation package from Mathematica's library to do the
sum.

Needs["Algebra`SymbolicSum`"]


loads the needed package, and the command

SymbolicSum[(1+r)^(-t),{t,1,T}]

gives us the answer. Thus, we are left with

p = B(0)*r/ ( 1 - (1+r)^(-T) )

That looks better. Now what we really want is a function called
payment that takes B, r, and T, as input and determines the payment for
us. From the above this function is given by

payment[B_, r_, T_]:= B*r/  ( 1 - (1+r)^(-T) )


Let's check this function using an example (taken from a ``real life'' experience
of one of the authors). You want to buy a house for $85,000 dollars, and will be putting
$9000 down. You have negotiated with the bank for thirty year fixed rate mortgage
at an 8% annual rate. What will your monthly payment be? Click here for answer.


Now that we have a function that determines the proper payment to retire a given
loan in a fixed period of time, we also want a function called balance
that takes r and p as arguments and computes monthly loan balances. In the
example above we found that

B(i) = B(i-1) - ( p - (.07/12)*B(i-1) )

and we can see how to generalize this pretty easily. Each month the balance on the
loan is equal to the old balance, plus the interest on the old balance, minus the payment
which has been made.

Using our rules of making Mathematica functions and the equation above we can
write a general balance function for the ith loan period

balance[i_,p_,r_]:=(1+r)*balance[i-1,p,r] -  p 


This function is somewhat unusual, in that it is defined in terms of itself, i.e., balance occurs on both sides of the definition. This is called a recursive function, and Mathematica will evaluate this function repeatedly (recursively) until it has a reason to stop. The only
logical reason to stop is when you get to the initial balance, and so you must specify that
as well. For example, we could say

balance[0,p_,r_]:=1000

which says that the initial balance is $1000 regardless of what the interest rate or payment
is. Let's return to our example above of a $100,000 loan at 7% annual interest. That means
we set

balance[0 ,p_, r_]:= 100000

Now that we have our function we can do some interesting things with it. But
first let's do some sanity checks to make sure that we haven't made a mistake
somewhere along the way.

For example, let's see what happens after one year if we make the
``break-even'' payment of $583.33 each month:

balance[12,583.33, .07/12]

The balance stays the same as we would expect.

Here are some other checks that you should try. What happens if we don't pay anything every month? What about if we pay $2000 every month, how long does it take to pay the loan at $2000 per month?

Click here for answer.