Exemplo n.º 1
0
        public static LoanSummary GetLoanSummary(decimal loanAmount, decimal apr, int numberOfPayments)
        {
            //get periodical payment amount
            decimal payment = Math.Round(Loans.LoanCalcs.CalculatePayment(loanAmount, apr, numberOfPayments), 2);

            var loanAdjustments = LoanAdjustment.GetLoanAdjustment(loanAmount, numberOfPayments, payment);

            var ls = new LoanSummary()
            {
                weeklyRepayment = payment, totalRepaid = loanAdjustments.totalToPay, totalInterest = loanAdjustments.totalInterest
            };

            return(ls);
        }
Exemplo n.º 2
0
        public static LoanAdjustment GetLoanAdjustment(decimal loanAmount, decimal numberOfPayments, decimal payment)
        {
            var la = new LoanAdjustment();

            la.totalToPay    = Math.Round((payment * numberOfPayments), 2);
            la.totalInterest = Math.Round(la.totalToPay - loanAmount, 2);

            /* Do adjustments to cater for rounding 'errors'
             *  Typically the first payment on any loan/DD schedule is slightly different to future payments
             */
            la.loanInstallment = Math.Round((decimal)loanAmount / (decimal)numberOfPayments, 2);
            la.loanAdjustment  = loanAmount - (la.loanInstallment * numberOfPayments);

            la.interestInstallment = Math.Round(la.totalInterest / numberOfPayments, 2);
            la.interestAdjustment  = (loanAmount + (la.interestInstallment * numberOfPayments)) - la.totalToPay;

            la.adjustedLoanAmount     = la.totalToPay - la.loanAdjustment;
            la.adjustedInterestAmount = la.totalInterest - la.interestAdjustment;

            return(la);
        }
Exemplo n.º 3
0
        public static LoanRepaymentSchedule GetRepaymentSchedule(decimal loanAmount, decimal apr, int numberOfPayments)
        {
            var lrs = new LoanRepaymentSchedule();

            //get periodical payment amount
            decimal payment = Math.Round(Loans.LoanCalcs.CalculatePayment(loanAmount, apr, numberOfPayments), 2);

            ///* Do adjustments to cater for rounding 'errors'
            //    Typically the first payment on any loan/DD schedule is slightly different to future payments
            // */
            var loanAdjustments = LoanAdjustment.GetLoanAdjustment(loanAmount, numberOfPayments, payment);


            decimal principalStillToPay = loanAdjustments.loanInstallment * numberOfPayments;

            for (int i = 1; i <= numberOfPayments; i++)
            {
                if (i == 1)
                {
                    loanAdjustments.interestInstallment -= loanAdjustments.interestAdjustment;
                    principalStillToPay += loanAdjustments.loanAdjustment;
                }
                lrs.installments.Add(new Installment
                {
                    installmentNumber = i,
                    amountDue         = loanAdjustments.totalToPay,
                    principal         = principalStillToPay,
                    interest          = loanAdjustments.interestInstallment
                });

                loanAdjustments.totalToPay -= payment;
                principalStillToPay        -= loanAdjustments.loanInstallment;
            }

            return(lrs);
        }