public IEnumerable <IPayment> GetRepaymentSchedule(DateTime firstPaymentDate, decimal principal, decimal interestRatePercentage, int term) { var repayments = new List <MonthlyRepayment>(); int numberOfRepayments = (term * MonthsInYear); var monthlyRepayment = GetRepaymentsFor(principal, interestRatePercentage, term); var balance = principal; var monthlyInterestRate = interestRatePercentage / (MonthsInYear * 100); for (int index = 0; index < numberOfRepayments; index++) { var interestAmountPaid = balance * monthlyInterestRate; var principleAmountPaid = monthlyRepayment - interestAmountPaid; balance = balance - principleAmountPaid; var payment = new MonthlyRepayment(firstPaymentDate, principleAmountPaid, interestAmountPaid, balance); repayments.Add(payment); if (balance < 0) { break; } // Advance to the next schedule payment date in the series firstPaymentDate = firstPaymentDate.AddMonths(1); } return(repayments); }
public override int GetHashCode() { unchecked { var hashCode = RequestedAmount; hashCode = (hashCode * 397) ^ InterestRate.GetHashCode(); hashCode = (hashCode * 397) ^ MonthlyRepayment.GetHashCode(); hashCode = (hashCode * 397) ^ TotalRepayment.GetHashCode(); return(hashCode); } }