public AmortizationReport GenerateReport(LoanEntity loan,
                                                 Dictionary <DateTime, double> paymentChangesByDate)
        {
            int       loanLength   = LoanTermCalculator.GetMonthsUntilPaid(loan).getMonthsUntilPaidOff();
            ArrayList paymentDates = DateUtil.GetListOfDatesMonthApart(DateUtil.GetNow(), loanLength);

            AmortizationReport report  = new AmortizationReport(loan);
            double             balance = loan.GetCurrentBalance();

            foreach (DateTime date in paymentDates)
            {
                DateTime balanceEffectiveDate = DateUtil.FindDateBeforeFromList(date, new List <DateTime>(paymentChangesByDate.Keys));

                double paymentForDate = date == balanceEffectiveDate?loan.GetMinimumMonthlyPayment() : paymentChangesByDate[balanceEffectiveDate];

                AmortizationRow row = new AmortizationRowGenerator()
                                      .GenerateRow(report.GetReportRows().Count + 1,
                                                   balance,
                                                   loan.GetMonthlyInterestRate(),
                                                   paymentForDate,
                                                   date);
                report.AddRow(row);
                balance = row.GetBalance();
                if (balance < 0)
                {
                    break;
                }
            }
            return(report);
        }
Пример #2
0
 public LoanTerm GetMonthsUntilPaid(LoanEntity loan)
 {
     return(new LoanTerm(-Math.Log(1 - (loan.GetCurrentBalance() * loan.GetMonthlyInterestRate() / loan.GetMinimumMonthlyPayment()))
                         / Math.Log(1 + loan.GetMonthlyInterestRate())));
 }