Time Estimate: 1 hour
Important MATLAB commands that will be used:
A True Story, by Prof. Mark Lyon
Buying a car can be tricky and some salesmen are just plain dishonest. My brother went to go buy a car some time ago in a diﬀerent state while he was still a student at a university. The salesman was someone he knew and trusted. They looked at several cars and each time the salesman would quote a cost for the car and a price per month on a 5 year loan.
It just so happens that my brother was married at the time and his wife has some unique ﬁnancial training. When she started college, she got a job at the local university credit union. This credit union only had two employees, the president of credit union and one assistant (my brother’s wife). After she had worked there for about two years, the president of the credit union resigned and she was made the president. She had been in that position for a little over a year, handling every major transaction of the credit union, when they went to look at buying a new car. She had a ﬁnancial calculator with her and would calculate what the monthly payments should be on the car based on the price and interest rate. They quickly realized that the salesman was quoting them monthly payments considerably higher than they should have been. They confronted the salesman, whom they had previously trusted, and asked him what was up.
At this point the salesman told them that it was a game that they played. They would tell the customers a monthly payment that was too high so that when they sat down with the manager who asked them to buy an extended warranty they could say that it would only be a little bit more per month. Basically they were lying about the original cost per month to trick customers into believing that the extended warranties were cheaper than they actually were.
In this lab we are going to write a MATLAB function to calculate monthly loan payments. I highly suggest that whenever you go to make a purchase with a loan or take out any loan that you make sure you know exactly what is going on. Run this program that you have written or go to the website of almost any bank and they should have a loan calculator. The above story is true, and it is not my only story of people being deceived on major loan purchases. My brother was lucky because his wife knew some math.
We ﬁrst need to identify what the inputs to our function will be. We
will need to have the total number of payments in months or
the loan. We will need the interest rate,
rate, as well as the loan
loan. We will assume the interest is compounded monthly
(standard for loans today, savings account interest is typically
compounded daily). Rather than have any outputs, we will just print
our results to the screen. Save the function as
by beginning the function with the command function
LoanCalc(loan,term,rate) Hit enter until you come to the line number
15 and put
We are actually going to start with a simpler problem and let MATLAB
solve for the harder one for us. We are going to write a sub-function,
or a function within a function. Some where around line 8, start
another function (call it
LoanPay, with input of just
a single output,
balance.) This function is going to compute, given
a loan with a certain rate, what the balance due on the loan is going
to be after all the payments of amount
payment have been made. This
function will need an
end before line 15. In the function, ﬁrst let
balance=loan; Then put a
for loop over the
term months. With each
month (or with each iteration of the loop) the balance should be
increased by the interest rate times the balance and reduced by the
amount of the payment. Test this sub-function by running it (on line
5) by the command
bal=LoanPay(300) which should then give
if you have set
format bank when you enter
in the MATLAB command window. Verify you have completed this step with
The returned balance in the previous step was negative because the
payment of 300 per month was too high. Changing the payment to 200 per
month would show a positive balance. How about 250? What would you
try next? We could keep trying diﬀerent values until we zeroed in on
the correct value, or we could use a built-in MATLAB function that
does the same thing. It is called
fzero and it ﬁnds a value that
will result in the function returning a zero. On line 2 of your code
put the line
payment=fzero(@LoanPay,[0,loan]) and then change line 5
bal=LoanPay(payment) and run this with the command
LoanCalc(15000,60,0.05) to get the results:
Verify you have completed this step with the TA.
Add some additional code to your
LoanCalc function to calculate the total amount of
interest paid during the life of the loan. Use this code to answer the following questions:
1. If you borrow $15,000 for 5 years at a 5% interest rate, how much interest would you end up paying?
2. If you borrow $15,000 for 5 years at a 10% interest rate will you end up paying exactly double in total interest compared to a 5% interest rate?
3. A typical home in the area around Durham, NH costs around $300,000. If you pay $50,000 on the down payment and you borrow the remaining $250,000 for 30 years at a 4% interest rate, how much interest would you end up paying? How does that amount compare to the original loan?
4. How much would your payments increase by (in amount and percent) if you decided to pay off the mortgage in just 15 years instead of 30? How much would you save interest?
5. How much would you pay in interest if you borrowed $250,000 at a rate of 4% for 30 years compared with how much you would pay interest if you borrowed $250,000 at a rate of 8% for 30 years. How do your payments compare for these two different scenarios?