mortgageData = {
const numberPayments = duration * 12;
const mortgage = purchasePrice - downPayment;
const monthlyInterestRate = (interestRate / 100) / 12;
let mortgageRemaining = mortgage;
let totalInterestPaid = 0;
let totalPrincipalPaid = 0;
const monthlyMortgagePayment = financial.pmt(monthlyInterestRate, numberPayments, mortgage) * -1;
const mortgageArray = d3.range(numberPayments).map((d,i) => {
const monthlyInterestPayment = financial.ipmt(monthlyInterestRate, i + 1, numberPayments, mortgage) * -1;
const monthlyPrincipalPayment = monthlyMortgagePayment - monthlyInterestPayment;
mortgageRemaining = mortgageRemaining - monthlyPrincipalPayment;
totalInterestPaid += monthlyInterestPayment;
totalPrincipalPaid += monthlyPrincipalPayment;
return { 'Payment #': (i + 1),
'Monthly Payment': monthlyMortgagePayment,
'Interest Payment': monthlyInterestPayment,
'Percent Interest': monthlyInterestPayment / monthlyMortgagePayment,
'Principal Payment': monthlyPrincipalPayment,
'Percent Principal': monthlyPrincipalPayment / monthlyMortgagePayment,
'Total Interest Paid': totalInterestPaid,
'Total Principal Paid': totalPrincipalPaid,
'Total Amount Paid': totalPrincipalPaid + totalInterestPaid,
'Total Mortgage Remaining': mortgageRemaining
}
});
return mortgageArray
}