# Mortgage Amortization Table

### Calculate a loan repayment schedule with Matlab

 This program calculates and displays a loan repayment schedule in a manner of Mortgage Amortization Table. This Matlab code for financial applications provides the following output: - Payment number. - Amount of each payment paid as interest. - Amount of the loan amortized with each payment. - Balance remaining on the principal at the time of each payment.

- Accumulated interest paid at the time of each payment.

To use this script you must supply the amount of the regular payment, the term of payment, the number of payments per year, the amount of the principal and the annual interest rate.

The schedule is calculated using very simple formulas:

- Payment number = number of monthly payment

- Amount of each payment paid as interest = remaining balance x i/N
where
i = annual interest rate (nominal)
N = number of payments per year

- Amount ammortized with each payment = R – I
where
R = amount of regular payments
I = amount of each payment paid as interest

- Balance remaining = P – sum(A)
where
P = principal
sum(A) = sum of amounts amortized with each payment to date

Accumulated interest = sum(I)
where
sum(I) = sum of amounts of each payment paid as interest to date

One way to code the above ideas is creating a function:

function table = mortg_amort_tab(r, y, p, i, n)

% Let's define some starting values
i = i/100;
balance(1) = p;
acc_interest(1) = 0;

% Calculate every monthly payment (except the last one)
for pnr = 2 : y*n
interest(pnr) = (balance(pnr-1) * i/n);
amortized(pnr) = (r - interest(pnr));
balance(pnr) = (balance(pnr-1) - amortized(pnr));

end

% Calculate the final payment differently, to terminate the debt
interest(pnr+1) = (balance(pnr) * i/n);
amortized(pnr+1) = balance(pnr);
balance(pnr+1) = balance(pnr) - amortized(pnr+1);

% Deliver results in table form
table = [(0 : pnr)' interest' amortized' balance' cumsum(interest')];

Example 1:

Daniel needs \$2100 to pay off some urgent debts. His sister Charlotte offers him the money at only 6% interest. With payments of \$75 monthly for 2.5 years, what is Daniel’s repayment schedule?

We can create a script named test_ mortgage_amort_tabl in the editor window, and run it easily, changing the input parameters as necessary:

clear, clc, format compact, format bank

r = 75;
y = 2.5;
p = 2100;
i = 6;
n = 12;

table = mortg_amort_tab(r, y, p, i, n);
disp(
'Mortgage Amortization Table')
s = sprintf(
'\t\t%s\t\t%s\t\t%s\t\t%s\t%s', ...
' Month', 'Interest', 'Amortz', ' Balance', ' Acc. Int');
disp(s)
disp(table)

The Matlab result is:

Mortgage Amortization Table
Month Interest Amortz Balance Acc. Int
0 0 0 2100.00 0
1.00 10.50 64.50 2035.50 10.50
2.00 10.18 64.82 1970.68 20.68
3.00 9.85 65.15 1905.53 30.53
4.00 9.53 65.47 1840.06 40.06
5.00 9.20 65.80 1774.26 49.26
6.00 8.87 66.13 1708.13 58.13
7.00 8.54 66.46 1641.67 66.67
8.00 8.21 66.79 1574.88 74.88
9.00 7.87 67.13 1507.75 82.75
10.00 7.54 67.46 1440.29 90.29
11.00 7.20 67.80 1372.49 97.49
12.00 6.86 68.14 1304.36 104.36
13.00 6.52 68.48 1235.88 110.88
14.00 6.18 68.82 1167.06 117.06
15.00 5.84 69.16 1097.89 122.89
16.00 5.49 69.51 1028.38 128.38
17.00 5.14 69.86 958.52 133.52
18.00 4.79 70.21 888.32 138.32
19.00 4.44 70.56 817.76 142.76
20.00 4.09 70.91 746.85 146.85
21.00 3.73 71.27 675.58 150.58
22.00 3.38 71.62 603.96 153.96
23.00 3.02 71.98 531.98 156.98
24.00 2.66 72.34 459.64 159.64
25.00 2.30 72.70 386.94 161.94
26.00 1.93 73.07 313.87 163.87
27.00 1.57 73.43 240.44 165.44
28.00 1.20 73.80 166.64 166.64
29.00 0.83 74.17 92.48 167.48
30.00 0.46 92.48 0 167.94

Example 2:

If you took out a loan for \$700 from a close friend at 9% interest and were to pay \$100/monthly for 8 months, what would your repayment schedule be?

Since we’re now working with less than a year period, we need to make subtle changes in the way we input data (note y and n values):

clear, clc, format compact, format bank

r = 100;
y = 8/12;
p = 700;
i = 9;
n = 12;
table = mortg_amort_tab(r, y, p, i, n);
disp(
'Mortgage Amortization Table')
s = sprintf(
'\t\t%s\t\t%s\t\t%s\t\t%s\t%s', ...
' Month', 'Interest', 'Amortz', ' Balance', ' Acc. Int');
disp(s)
disp(table)

and the Matlab result is:

Mortgage Amortization Table
Month Interest Amortz Balance Acc. Int
0 0 0 700.00 0
1.00 5.25 94.75 605.25 5.25
2.00 4.54 95.46 509.79 9.79
3.00 3.82 96.18 413.61 13.61
4.00 3.10 96.90 316.71 16.71
5.00 2.38 97.62 219.09 19.09
6.00 1.64 98.36 120.73 20.73
7.00 0.91 99.09 21.64 21.64
8.00 0.16 21.64 0 21.80

You can format your output. Type 'help sprintf' on your command window to read its description. You can use also 'format bank' to have only two decimals displayed.

From 'Mortgage Amortization Table' to home

From 'Mortgage Amortization Table' to 'Financial Formulas'

 Top Simple/Compund interest Commercial Paper Depreciation

## Related pages

polar graph matlabintegrals of gaussian functionsbinary and hexadecimal number systemstring matlabdecimal to gray code conversioncramer rule examplebisect methodmatlab plot animationmatlab box plotmatlab random number generationmatlab not equal operatorcall function in matlabascii for lettersdepreciation formulasascii alphabetplot coordinates matlabfor and while loops matlabinch to sq ft calculatorhow to solve kvl and kcl problemscramer's rule exampleleast squares fitting matlabsolve function matlabconvert binary to decimalformula for infinite gppascal triangle calculatorrgb color matlabexcel to matlabtrapezoidal rule algorithmroots of quadratic equation calculatorsolve equations matlabsum harmonic seriesfuncion heavisidematlab function solverdelta diracaprime factorization tutorialcompound interest continuously calculatormatlab for beginnersbest fit curve matlabhow to learn matlabgauss normal distributionusing matlab to solve simultaneous equationsmatlab function rootssimpsons rule examplemaclaurin series sin x 2create gui in matlabseries of trigonometric functionsohms law calculator appsum to infinity formuladepreciation rate laptopfind the equation of a line with two points calculatorrc circuit chargingsample matlab programsmaclaurin series cosh xprogram in c for pascal trianglecollatz fractalinverse of a matrix by gauss jordan methodconvert binary number to decimal numberhow to solve factorialsdivision of two polynomialsmatlab do while looppythag calculatorgraphing a piecewise defined functioncompound interest calculator spreadsheetonline polynomial regression calculatorascii lookup tableplot regression matlabstr2num matlabconversion binary to octalmatlab curvefitdepreciation salvage value formulagenerate ascii table