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);
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            LoanEntity loan = LoanEntity.NewBuilder()
                              .SetLoanName("Test Loan")
                              .SetPrinciple(20000)
                              .SetCurrentBalance(20000)
                              .SetApr(.006155 * 12)
                              .SetMinuminMonthlyPayment(415.76)
                              .Build();
            LoanEntity secondLoan = LoanEntity.NewBuilder()
                                    .SetLoanName("Test Loan")
                                    .SetPrinciple(5000)
                                    .SetCurrentBalance(5000)
                                    .SetApr(.006155 * 12)
                                    .SetMinuminMonthlyPayment(200)
                                    .Build();

            Console.WriteLine("Expected length of loan paying minimum : " + new LoanTermCalculator()
                              .GetMonthsUntilPaid(loan)
                              .getMonthsUntilPaidOff());

            Dictionary <DateTime, double> payementChanges = new Dictionary <DateTime, double>
            {
                //{ DateTime.Now.AddMonths(5), 550.0 }
            };

            AmortizationReportGenerator amortizationReportGenerator = new AmortizationReportGenerator(new LoanTermCalculator(),
                                                                                                      new DateUtil());

            AmortizationReport report = amortizationReportGenerator.GenerateReport(loan,
                                                                                   payementChanges);

            AmortizationReport secondReport = amortizationReportGenerator.GenerateReport(secondLoan,
                                                                                         payementChanges);
            AmortizationReportConsolePrinter printer = new AmortizationReportConsolePrinter();

            printer.PrintReport(report);
            printer.PrintReport(secondReport);

            SnowBallReportGenerator snowBallReportGenerator = new SnowBallReportGenerator(amortizationReportGenerator,
                                                                                          new AmortizationReportEvaluator());
            List <LoanEntity> loans = new List <LoanEntity> {
                loan, secondLoan
            };
            List <AmortizationReport> snowBallReports = snowBallReportGenerator.GenerateReport(loans);

            foreach (AmortizationReport snowReport in snowBallReports)
            {
                printer.PrintReport(snowReport);
            }
        }
        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.º 4
0
 public AmortizationReport(LoanEntity loan)
 {
     Loan = loan;
 }
Exemplo n.º 5
0
 public LoanTerm GetMonthsUntilPaid(LoanEntity loan)
 {
     return(new LoanTerm(-Math.Log(1 - (loan.GetCurrentBalance() * loan.GetMonthlyInterestRate() / loan.GetMinimumMonthlyPayment()))
                         / Math.Log(1 + loan.GetMonthlyInterestRate())));
 }