Sean's pick this week is All Purpose Mortgage Calculator including mortgage schedule by S B.
I am currently in the fun process of buying a house. My wife and I were going over the mortgage calculations the other day and figuring out our approximate monthly payments and the amount of money we want to put down. We know that the financial company we are using probably knows how to do these calculations. But we wanted to check them! I also noticed that they were using Excel so that made me curious to see how easy this would be in my choice software for everything, MATLAB.
It's generally the case that if functionality for MATLAB seems obvious, it's probably built in to the product or one of the toolboxes. If this is not the case, then someone else has likely already written it and deposited it on the File Exchange. I vaguely remembered this App from a few months ago when my friend Doug and I were talking about the great low interests rates available right now.
NOTE All numbers below have been obfuscated to hide the actual financial details.
In MATLAB R2012b, we introduced MATLAB Apps and the Apps Toolbar:
Using MATLAB Apps you can package your GUIs and their dependencies into single files that can be distributed and installed easily. This will help your users avoid the standard path issues. Apps also enable you to have easy version control and descriptions for your GUIs.
Side Note: I know that during the R2012b release many of you wanted to be able to change the App icon. In R2013a, the ability to select an icon from one of a dozen is available.
So let's take a look at this App:
We'll first try 20% down:
How does that compare to 5% down (not including Private Mortgage Insurance (PMI)):
So the total interest saved by putting down 20% instead of 5% is about $28K, not including PMI.
What if we could shorten it to 15 years?
This just about halves the amount of interest!
Unfortunately, the plot does not work for any number of years less than 30 (enhancement!)
For every scenario, the numbers lined up with those that the financial firm gave us verifying both their calculations and this App.
Though we have a big suite of Financial Products, none of them were used here. The engine behind this appears to be about 20 lines of MATLAB code and everything else is just for the GUI.
One thing I noticed is that S B did a lot of work for selecting the colors for the plot lines. Here's what he did:
color_map = ['rbgrbmbrgr']; z1 = 0; z2 = 0; while (z1 == 0) | (z1 > 9) | (z2 == 0) | (z2 > 9) z1 = fix(rand(1)*10); z2 = fix(rand(1)*10); % What are the chances of get the same random number twice!? if (z1 == z2) z1 = fix(rand(1)*10); z2 = fix(rand(1)*10); end end z1 = color_map(z1); z2 = color_map(z2);
I would recommend just using randperm() to guarantee two unique integers between one and nine.
color_map = 'rgbcmyk'; idx = randperm(numel(color_map),2); color1 = color_map(idx(1)) color2 = color_map(idx(2))
color1 = k color2 = b
There are a few enhancements that would make this App even better!
- The ability for it to plot for a term different than 30 years.
- The ability to account for overpayments (e.g. by just changing the monthly amount).
- The ability to account for PMI.
So the answer to my original question: How easy would it be to do this in MATLAB? Really easy!
Get the MATLAB code
Published with MATLAB® R2013a