我需要一个函数的帮助,它可以计算抵押年金摊销表,其输出以列和付款金额、本金支付、利息支付等行为单位,按每月排序,如下面的链接所示: 输出示例
输出文件格式应为 .cvs。目前我被这个女巫困住了,离结果还很远:
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;
}
非常感谢您对此的任何帮助。