Mortgage Payments

We want to understand the relationships between the mortgage payment of a fixed rate mortgage, the principal (the amount borrowed), the annual interest rate, and the period of the loan. We are going to assume that payments are made monthly, even though the interest rate is given as an annual rate. So, one of the things we will need is a way to convert years into months. Let's define

\(months\  = \ 1; 
years\  = \ 12*months; 
peryear\  = \ 1/years; 

    percent\  = \ 1/100.0; \)

For example, we can write

30*years

to determine the number of monthly payments made on a 30 year loan, and we can write

8*percent*peryear

to convert an annual percentage rate of 8% into a monthly rate.

Now let's think about what happens with each monthly payment.  Some of the payment is applied to pay the interest for that month, and the remainder is applied to reduce the principal. Let P denote the principal at the beginning of the month, let R denote the amount of the monthly payment, and let J denote the monthly interest rate.

interestPaid[P_,  J_]  :=  P*J;

reduction[P_,  J_,  R_]  :=  R  -  interestPaid[P,  J];

newPrincipal[P_,  J_,  R_]  :=  P  -  reduction[P,  J,  R];

This allows us to compute a formula for the new principal.

newPrincipal[P,  J,  R]

In order to understand the full relationship between the principal, interest rate, number of payments, and monthly payment, we need to see how the outstanding principal changes over the course of several payments. The simplest way to think about this relationship is to observe that the outstanding principal changes with each payment by the formula we just worked out for computing the new principal after one payment; we simply need to repeat this process. The next series of commands shows how to do this. (The curious double definition of the function outstanding[N] is a standard technique in Mathematica to make the function remember values that it has computed earlier. See Section 2.4.9 of The Mathematica Book by Steven Wolfram.)

\(outstanding[0]\  = \ P; 

    outstanding[N_]\  := \ 
      \(outstanding[N]\  = \ 

        \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ 
        newPrincipal[outstanding[N - 1], \ J, \ R]\)\)

For example, here is the amount of the principal still outstanding after each of the first six payments.

Table[Simplify[outstanding[n]],  {n,  0,  6}]   //  TableForm

Next, we'll try to find a better formula for the outstanding principal. It's clear from our examples that there will always be a term of the form (((1 + J))^n)P. However, we need a better formula for the term involving R. The coefficients of powers of J in this term are reminiscent of the binomial coefficients. For example, we have

Expand[(1 + J)^6]

With a minor adjustment, we can get the exact term.

Expand[((1 + J)^6 - 1)/J]

So, a formula for the outstanding principal is

outstandingPrincipal  = 
      (1  +  J)^N*P  -  (((1  +  J)^N  -  1)/J)*R

Now suppose that after N payments the loan is paid off. Then the outstanding principal is zero. By setting outstandingPrincipal to zero and solving the resulting equation for R, we can compute the monthly payment as a function of the principal, interest rate, and number of payments.

Solve[outstandingPrincipal  ==  0,  R]

payment[P_,  J_,  N_]  :=  
      J*(1  +  J)^N*P/((1  +  J)^N - 1)

For example, the payment on a loan of $150,000 at 8 percent for 30 years is

payment[150000,  8*percent*peryear,  30*years]

We may also want to determine the amount of money that can be borrowed as a function of the amount we are able to pay each month. We simply solve our equation for P in terms of the remaining variables.

Solve[outstandingPrincipal  ==  0,  P]

loanAmount[R_,  J_,  N_]  :=  
      ((1 + J)^N - 1)*R/(J*(1 + J)^N)

For example, suppose we can afford to pay $1500 per month, and that the interest rate on a 30 year loan is 8 percent. Then the amount of money that can be borrowed is

loanAmount[1500,  8*percent*peryear,  30*years]

As a final piece of the analysis, we are going to write a function that will produce a table of values showing how much of each of a series of payments is allocated toward the interest payment, and how much is used to reduce the principal. The function takes as inputs the initial principal, the annual interest rate, the monthly payment, and the number of payments to be made during the period of time covered by the table. We use the Mathematica commands Module and Do to write a function that can repeat a process a fixed number of times, using local variables to store the intermediate results of the computation.

\(\(several[P_, \ J_, \ R_, \ N_]\  := \ 

      Module[{p\  = \ P, \ onerow, \ 
          allrows\  = {{"principal", \ "interest paid", \ 
                "principal paid"}}}, \ 
		
        Do[onerow\  = 
            \ {p, \ interestPaid[p, \ J], \ reduction[p, \ J, \ R]}; 

          			\ \ \ \ allrows\  = \ Join[allrows, \ {onerow}]; 

          		\ \ \ \ \ \ \ p = \ newPrincipal[p, \ J, \ R], 

          		{i, \ 1, \ N}]; 
allrows]
			\)\)

Let's see what happens if we make one year's worth of $1100.65 payments on a $150,000 loan at an annual interest rate of 8 per cent.

several[150000,  8*percent*peryear,  1100.65,  12 months]  // 
      TableForm

Using similar techniques, we can determine the total amount of interest paid over the life of a loan. In order to do this, we need to know the principal, the interest rate, and the number of payments.

\(totalInterest[P_, \ J_, \ N_\ ] := \ 
      Module[{ip\  = \ 0, \ p\  = \ P, \ r\  = \ payment[P, \ J, \ N]}, \ 

        	\ \ \ \ \ 
        Do[ip\  += \ interestPaid[p, J]; 
		\ \ \ \ \ \ \ \ \ 
          p\  -= \ reduction[p, \ J, \ r], \ {i, \ N}]; 
		ip]\)

For example, let's continue to look at the case of a 30 year mortgage at eight percent.  With a principal of

prin  =  150000;

we pay a total interest of

inter  =  totalInterest[prin,  8*percent*peryear,  30 years]

Here is a pie chart showing the relative amounts paid in principal and interest over the life of the loan.

<< Graphics`Graphics`

PieChart[{prin,  inter},  
      PieStyle ->  {GrayLevel[0.4],  GrayLevel[0.8]},  
      PieLabels -> {"Principal",  "Interest"}];