Ejemplo n.º 1
0
        private static Loan CreateLoan(Loantypes loanType, int tenure, double interestRate, int principal, DateTime payoutDate, IDayCounter dayCalculator)
        {
            Loan loan;

            switch (loanType)
            {
            case Loantypes.FixedEmiLoan:
                loan = new FixedEmiLoan(dayCalculator);
                break;

            case Loantypes.FixedAmortizationLoan:
                loan = new FixedAmortizationLoan(dayCalculator);
                break;

            case Loantypes.FixedInterestLoan:
                loan = new FixedInterestLoan(dayCalculator);
                break;

            default: throw new ArgumentException("Loan type not implemented");
            }
            ;
            loan.TenureYears      = tenure;
            loan.InterestRate     = interestRate;
            loan.StartAmount      = principal;
            loan.CurrentPrincipal = principal;
            loan.PayoutDate       = payoutDate;

            return(loan);
        }
Ejemplo n.º 2
0
        static void TestCreatingInvoices2(IDayCounter dayCalculator, string filename)
        {
            var loan = new FixedAmortizationLoan(dayCalculator)
            {
                InterestRate     = 10,
                CurrentPrincipal = 10000,
                StartAmount      = 10000,
                PayoutDate       = new DateTime(2017, 10, 01),
                TenureYears      = 10,
            };

            var invoices = new List <Invoice>();
            var baseDate = loan.PayoutDate;

            while (loan.CurrentPrincipal > 0.001)
            {
                baseDate = baseDate.AddMonths(1);
                var date    = baseDate.AddDays(-1);
                var invoice = loan.AddInvoice(date, new DateTime(date.Year, date.Month, 1), baseDate, 0.0);
                loan.CurrentPrincipal -= invoice.Principal;
                invoices.Add(invoice);

                //Console.WriteLine(invoice.ToString());
                //Console.WriteLine($"{invoice.InvoiceDate.ToString("MMM-yyyy")} | {Math.Round(invoice.FullInvoiceAmount, 0, MidpointRounding.AwayFromZero)} | {Math.Round(invoice.Interest, 0, MidpointRounding.AwayFromZero)} | {Math.Round(invoice.Principal, 0, MidpointRounding.AwayFromZero)} | {Math.Round(loan.CurrentPrincipal, 0, MidpointRounding.AwayFromZero)}");
            }
            Console.WriteLine($"SUM: Principal {invoices.Sum(s => s.Principal)}, Interest: {invoices.Sum(s => s.Interest)}, InvoiceFee: {invoices.Sum(s => s.InvoiceFee)}, LateFee: {invoices.Sum(s => s.LateFee)}");
            TestOutput.CreateCSV(invoices, filename);
        }