public static LoanSummary GetLoanSummary(decimal loanAmount, decimal apr, int numberOfPayments) { //get periodical payment amount decimal payment = Math.Round(Loans.LoanCalcs.CalculatePayment(loanAmount, apr, numberOfPayments), 2); var loanAdjustments = LoanAdjustment.GetLoanAdjustment(loanAmount, numberOfPayments, payment); var ls = new LoanSummary() { weeklyRepayment = payment, totalRepaid = loanAdjustments.totalToPay, totalInterest = loanAdjustments.totalInterest }; return(ls); }
public static LoanRepaymentSchedule GetRepaymentSchedule(decimal loanAmount, decimal apr, int numberOfPayments) { var lrs = new LoanRepaymentSchedule(); //get periodical payment amount decimal payment = Math.Round(Loans.LoanCalcs.CalculatePayment(loanAmount, apr, numberOfPayments), 2); ///* Do adjustments to cater for rounding 'errors' // Typically the first payment on any loan/DD schedule is slightly different to future payments // */ var loanAdjustments = LoanAdjustment.GetLoanAdjustment(loanAmount, numberOfPayments, payment); decimal principalStillToPay = loanAdjustments.loanInstallment * numberOfPayments; for (int i = 1; i <= numberOfPayments; i++) { if (i == 1) { loanAdjustments.interestInstallment -= loanAdjustments.interestAdjustment; principalStillToPay += loanAdjustments.loanAdjustment; } lrs.installments.Add(new Installment { installmentNumber = i, amountDue = loanAdjustments.totalToPay, principal = principalStillToPay, interest = loanAdjustments.interestInstallment }); loanAdjustments.totalToPay -= payment; principalStillToPay -= loanAdjustments.loanInstallment; } return(lrs); }