Пример #1
0
        private decimal ApplyPayments(int startYear, int startMonth, int startDay, decimal presentValue, decimal interestRate, LoanPayments payments,
                                      ref LoanStatistics stats)
        {
            var currentDate = new DateTime(startYear, startMonth, startDay);
            var orderedList = payments.Values.OrderBy(x => x.Year).ThenBy(x => x.Month).ThenBy(x => x.Day);

            foreach (var loanPayment in orderedList)
            {
                // Assuming allLoans payment date is after current date.
                if (presentValue == 0)
                {
                    stats[loanPayment.Date] = new LoanPeriodsStatistics(loanPayment.Date, 0, 0, 0);
                }
                else
                {
                    var daysOfInterest = (loanPayment.Date - currentDate).Days;
                    var fv             = Financial.FGivenP(presentValue, daysOfInterest, interestRate);
                    var poi            = fv - presentValue;
                    if ((fv < loanPayment.Payment && fv > 0) ||
                        (fv > loanPayment.Payment && fv < 0))
                    {
                        presentValue            = 0;
                        stats[loanPayment.Date] = new LoanPeriodsStatistics(loanPayment.Date, fv, 0, poi);
                    }
                    else
                    {
                        presentValue            = fv - loanPayment.Payment;
                        stats[loanPayment.Date] = new LoanPeriodsStatistics(loanPayment, presentValue, poi);
                    }
                }
                currentDate = loanPayment.Date;
            }
            return(presentValue);
        }
Пример #2
0
        public Loan ApplyPayments(Loan loan, DateTime startTime, LoanPayments payments, out LoanStatistics loanStats)
        {
            loanStats = new LoanStatistics();
            var fv = ApplyPayments(startTime.Year, startTime.Month, startTime.Day, loan.PresentValue, loan.DailyInterestRate,
                                   payments, ref loanStats);

            return(new Loan(loan.Name, loan.AnnualPercentageRate, fv, loan.AnnualWorth));
        }
Пример #3
0
        public Loan ApplyPayments(Loan loan, out LoanStatistics loanStats)
        {
//j                       Financial.FGivenP((decimal) 6653.54, n, allLoans.MonthlyInterestRate) -
//                       Financial.FGivenA(annualWorth, n, allLoans.MonthlyInterestRate), 0, annualWorth, out finalPayment);


            decimal garbage;
            var     periods = Financial.FindN(n => Financial.FGivenP(loan.PresentValue, n, loan.MonthlyInterestRate) - Financial.FGivenA(loan.AnnualWorth, n, loan.MonthlyInterestRate), 0,
                                              loan.AnnualWorth, out garbage);

            loanStats = new LoanStatistics();
            var now      = DateTime.Now;
            var year     = now.Year;
            var month    = now.Month;
            var day      = now.Day;
            var payments = new LoanPayments();

            if (day > 1)
            {
                month = NextMonth(month, ref year);
            }
            for (int i = 0; i < periods; i++)
            {
                var period = new DateTime(year, month, 1);
                payments[period] = new LoanPayment {
                    Year = year, Month = month, Day = day, Payment = loan.AnnualWorth
                };
                month = NextMonth(month, ref year);
            }
            if (payments.Count != periods)
            {
                throw new Exception();
            }

            var fv = ApplyPayments(now.Year, now.Month, now.Day, loan.PresentValue, loan.DailyInterestRate, payments, ref loanStats);

            return(new Loan(loan.Name, loan.AnnualPercentageRate, fv, loan.AnnualWorth));
        }