public static PaymentPlanOutputEntry ApplyMonthlyPayment(DateTime currentDate, DebtEntry debtEntry, PaymentManager paymentManager, double additionalPrinciple = 0) { double startingBalance = debtEntry.CurrentBalance; double interestPortion = debtEntry.MonthlyInterest * debtEntry.CurrentBalance; double minimumPrinciple = debtEntry.MinimumMonthlyPayment - interestPortion; double principalPortion = minimumPrinciple + additionalPrinciple; double possibleBalance = debtEntry.CurrentBalance -= principalPortion; if (possibleBalance < 0) { debtEntry.CurrentBalance = 0; paymentManager.AddWindfallEntry(Math.Abs(possibleBalance), currentDate.AddMonths(1)); } else { debtEntry.CurrentBalance = possibleBalance; } PaymentPlanOutputEntry output = PaymentPlanOutputEntry.Create( debtEntry.Name, currentDate, startingBalance, interestPortion, minimumPrinciple, additionalPrinciple, debtEntry.CurrentBalance); //PaymentPlanOutputEntry.WriteToConsole(output); return output; }
public static DebtEntry CreateDebtEntry(string name, double startBalance, double currentBalance, double yearlyInterest, int loanTerm) { DebtEntry debtEntry = new DebtEntry() { Name = name, StartingBalance = startBalance, CurrentBalance = currentBalance, YearlyInterestRate = yearlyInterest, LoanTerm = loanTerm }; InitializeMonthlyPayment(debtEntry); return debtEntry; }
public bool AddDebtEntry(DebtEntry debtEntry) { _debtEntries.Add(debtEntry); return true; }
protected static void InitializeMonthlyPayment(DebtEntry debtEntry) { debtEntry.MonthlyInterest = debtEntry.YearlyInterestRate * _yearly_to_monthly_interest_term_inverse; double monthlyInterest_Loan_Term = Math.Pow ((1 + debtEntry.MonthlyInterest), debtEntry.LoanTerm); debtEntry.MinimumMonthlyPayment = debtEntry.MonthlyInterest * debtEntry.StartingBalance * monthlyInterest_Loan_Term / (monthlyInterest_Loan_Term - 1); }