I need help with a function which can calculate mortgage annuity amortization table with output in cols and rows of payment amount, principal payment, Interest payment, etc. sorted by each month like in link below: Output example
The output file format should be .cvs. At the moment I am stuck with this witch is still far away from result:
var i = 5/100;
var loanAmount = 15000;
var m = 12;
var monthlyPayment = loanAmount*(i/12)*Math.pow((1+i/12), m) / (Math.pow((1+i/12), m)-1)
var currentBalance = loanAmount;
var paymentCounter = 1;
var totalInterest = 0;
monthlyPayment = monthlyPayment;
while(currentBalance > 0) {
//this calculates the portion of your monthly payment that goes towards interest
towardsInterest = (i/12)*currentBalance;
if (monthlyPayment > currentBalance){
monthlyPayment = currentBalance + towardsInterest;
}
towardsBalance = monthlyPayment - towardsInterest;
totalInterest = totalInterest + towardsInterest;
currentBalance = currentBalance - towardsBalance;
}
Would really appreciate any help on this.
Try something like this:
Output: