Esempio n. 1
0
        public static List <MonthDetail> CalculateFixedRateCashflow(IEnumerable <Loan> loans)
        {
            List <MonthDetail>         flow        = new List <MonthDetail>();
            List <List <MonthDetail> > workingFlow = new List <List <MonthDetail> >();

            if (loans == null || !loans.Any())
            {
                return(flow);
            }

            foreach (var loan in loans)
            {
                workingFlow.Add(CalculateFixedRateCashflow(loan));
            }

            int maxMonth = workingFlow.Max(f => f.Count);

            for (int i = 0; i < maxMonth; ++i)
            {
                MonthDetail detail = new MonthDetail();
                detail.Month = i + 1;
                foreach (var loanFlow in workingFlow)
                {
                    if (loanFlow.Count > i)
                    {
                        detail.Interest         += loanFlow.ElementAt(i).Interest;
                        detail.Principal        += loanFlow.ElementAt(i).Principal;
                        detail.RemainingBalance += loanFlow.ElementAt(i).RemainingBalance;
                    }
                }
                flow.Add(detail);
            }
            return(flow);
        }
Esempio n. 2
0
        public static List <MonthDetail> CalculateFixedRateCashflow(Loan loan)
        {
            List <MonthDetail> flow = new List <MonthDetail>();
            double             totalMonthlyPayment = GetTotalMonthlyPayment(loan);
            double             remainingBalance    = loan.Balance;

            for (int i = 0; i < loan.Term; ++i)
            {
                MonthDetail detail = new MonthDetail();
                detail.Month            = i + 1;
                detail.Interest         = remainingBalance * loan.Rate / 1200;
                detail.Principal        = totalMonthlyPayment - detail.Interest;
                remainingBalance       -= detail.Principal;
                detail.RemainingBalance = remainingBalance;
                flow.Add(detail);
            }

            return(flow);
        }