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);
        }
        public void PrintReport(AmortizationReport report)
        {
            LoanEntity loan = report.GetLoan();

            Console.WriteLine("LOAN AT TIME OF REPORT");
            Console.WriteLine("".PadRight(20) +
                              "PAYMENT AMOUNT".PadRight(20) +
                              "INTEREST".PadRight(20) +
                              "PRINCIPAL".PadRight(20) +
                              "BALANCE".PadRight(20));

            Console.WriteLine("Initial".PadRight(20) + "".PadRight(20) + "".PadRight(20) + "".PadRight(20) + loan.GetCurrentBalance().ToString().PadRight(20));

            foreach (AmortizationRow row in report.GetReportRows())
            {
                Console.WriteLine(row.GetPaymentNumber().ToString().PadRight(20) +
                                  row.GetPaymentAmount().ToString().PadRight(20) +
                                  row.GetInterest().ToString().PadRight(20) +
                                  row.GetPrincipal().ToString().PadRight(20) +
                                  row.GetBalance().ToString().PadRight(20));
            }
        }
Exemplo n.º 3
0
 public LoanTerm GetMonthsUntilPaid(LoanEntity loan)
 {
     return(new LoanTerm(-Math.Log(1 - (loan.GetCurrentBalance() * loan.GetMonthlyInterestRate() / loan.GetMinimumMonthlyPayment()))
                         / Math.Log(1 + loan.GetMonthlyInterestRate())));
 }