Although there are many available mortgage calculators out there, the principle of a simple mortgage calculator is really simple, which is based on the following math formula.
where, the c is the monthly repayment, r is the monthly interests (which is the one-twelveth of the yearly interests). P is the total money borrowed. N is the total number of re-payments (e.g. the number of months).
Simple Mortgage Calculator Implemented in MySQL
For example, I borrowed 170K from the HSBC Bank, the interests rate (yearly) is 2.49%, and I need to repay the principle+interests in 25 years. The amount of repayment each month (suppose it is fixed-rate) can be computed via the following command in MySQL console:
1 2 3 4 5 6 7 | mysql> select 0.0249/12*170000*power(1+0.0249/12,25*12)/(power(1+0.0249/12,25*12)-1); +------------------------------------------------------------------------+ | 0.0249/12*170000*power(1+0.0249/12,25*12)/(power(1+0.0249/12,25*12)-1) | +------------------------------------------------------------------------+ | 761.792586559163 | +------------------------------------------------------------------------+ 1 row in set (0.00 sec) |
mysql> select 0.0249/12*170000*power(1+0.0249/12,25*12)/(power(1+0.0249/12,25*12)-1); +------------------------------------------------------------------------+ | 0.0249/12*170000*power(1+0.0249/12,25*12)/(power(1+0.0249/12,25*12)-1) | +------------------------------------------------------------------------+ | 761.792586559163 | +------------------------------------------------------------------------+ 1 row in set (0.00 sec)
Simple Mortgage Calculator Implemented in C/C++
With the pow function from math.h, the payment function is defined as follows:
1 2 3 4 5 6 7 8 9 | #include <math.h> // r - monthly interest rate // p - principle // n - number of repayments double payment(r, p, n) { var x = pow(1 + r, n); return r * p * x / (x - 1); } |
#include <math.h> // r - monthly interest rate // p - principle // n - number of repayments double payment(r, p, n) { var x = pow(1 + r, n); return r * p * x / (x - 1); }
Online Simple Mortgage Calculator Implemented in Javascript
Similarly, the function defined in Javascript is defined as:
1 2 3 4 5 6 7 | // r - monthly interest rate // p - principle // n - number of repayments function payment(r, p, n) { var x = Math.pow(1 + r, n); return r * p * x / (x - 1); } |
// r - monthly interest rate // p - principle // n - number of repayments function payment(r, p, n) { var x = Math.pow(1 + r, n); return r * p * x / (x - 1); }
Fill in the values of r, P and N and the the following online mortgage calculator (open in new window) will compute the monthly repayment and interests (not available if you are viewing in Accelerated Mobile Page version):
The alternative version of this mortgage calculator can be found here.
–EOF (The Ultimate Computing & Technology Blog) —
loading...
Last Post: The RDTSC Performance Timer written in C++
Next Post: How to Protect Your WordPress Login from Brute-Force Attacks - Simple Approach?