Last active
April 29, 2017 15:24
-
-
Save zeikeland/e6d647645f3087dc6af730ef488bf363 to your computer and use it in GitHub Desktop.
Calculate mortage payments pr month
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Function for calculating loan ammount. | |
* Sum is without fees and additional costs. | |
*/ | |
function calculate_mortage( totalammount, ownmoney, interest, years ) { | |
/** | |
* Formula M = P * ( J / (1 - (1 + J)^-N)) | |
* M = Payment monthly | |
* P = Loan ammount | |
* J = Effective intrest in decimal (x% / 100) / 12 months | |
* N = Num Payments | |
* | |
* Effective interest formula (1 + J)^12 – 1 | |
*/ | |
var m, p, j, n; | |
p = totalammount - ownmoney; | |
j = (interest / 100) / 12; | |
n = years * 12; | |
m = p * ( j / ( 1 - Math.pow(1+j, -n) ) ); | |
// return with rounded monthly payment | |
return Math.round( m ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment