public static Collection<PaymentPlanOutputEntry> CalculateDebtSnowball(DebtManager debtManager, PaymentManager paymentManager)
        {
            Collection<PaymentPlanOutputEntry> col = new Collection<PaymentPlanOutputEntry>();

            DateTime startDate = DateTime.Now;
            DateTime currentDate = DateTime.Now;

            foreach (DebtEntry debt in debtManager.DebtEntries)
            {
                while (debt.CurrentBalance > 0)
                {
                    double salarySnowball = paymentManager.GetTotalMonthlySnowball(startDate, currentDate);
                    col.Add(DebtSnowballCalculator.ApplyMonthlyPayment(currentDate, debt, paymentManager, salarySnowball));
                    currentDate = currentDate.AddMonths(1);
                }
            }

            return col;
        }
Пример #2
0
        // display results for each debt in results panels
        private void DisplayResults(DebtManager debtManager)
        {
            List <Control> controls;
            Panel          resultsPanel;
            int            months;
            string         interestStr;
            double         interest;
            Color          monthsColor;
            Color          interestColor;

            // totals
            int    monthsTotal   = 0;
            double interestTotal = 0;

            foreach (Debt debt in debtManager)
            {
                monthsColor   = Color.Black;
                interestColor = Color.Black;
                resultsPanel  = debt.resultsPanel;
                controls      = GetControls(resultsPanel);

                if (controls[0].Text != "" && controls[1].Text != "")
                {
                    // get results panel values from previous calculation
                    months      = Convert.ToInt32(controls[0].Text);
                    interestStr = controls[1].Text.Trim('$');
                    interest    = Convert.ToDouble(interestStr);

                    // set results panel colors to reflect improvement or worsening of previous calculation
                    if (months < debt.months)
                    {
                        monthsColor = Color.Red;
                    }
                    else if (months > debt.months)
                    {
                        monthsColor = Color.Green;
                    }

                    if (interest < Math.Round(debt.interestPaid, 2, MidpointRounding.AwayFromZero))
                    {
                        interestColor = Color.Red;
                    }
                    else if (interest > Math.Round(debt.interestPaid, 2, MidpointRounding.AwayFromZero))
                    {
                        interestColor = Color.Green;
                    }
                }
                // populate results panel for this debt
                controls[0].Text      = debt.months.ToString();
                controls[1].Text      = (debt.interestPaid + debt.feesPaid).ToString("c");
                controls[2].Text      = debt.payment.ToString("c");
                controls[0].ForeColor = monthsColor;
                controls[1].ForeColor = interestColor;

                // add to calculation totals
                if (debt.months > monthsTotal)
                {
                    monthsTotal = debt.months;
                }
                interestTotal += debt.interestPaid + debt.annualFees;
            }

            // populate total results of all debts
            int    monthsDifference;
            double interestDifference;
            Color  monthsDifferenceColor   = Color.Black;
            Color  interestDifferenceColor = Color.Black;

            // set total time to pay off all debts
            lblTimeToPayAll.Text = FormatMonths(monthsTotal);

            // skip difference if first calculation
            // if not, display time difference with appropriate color
            if (lastMonthsTotal != 0)
            {
                monthsDifference = lastMonthsTotal - monthsTotal;
                if (monthsDifference > 0)
                {
                    monthsDifferenceColor = Color.Green;
                }
                if (monthsDifference < 0)
                {
                    monthsDifferenceColor = Color.Red;
                }
                lblTimeDifference.Text      = FormatMonths(monthsDifference);
                lblTimeDifference.ForeColor = monthsDifferenceColor;
            }

            // set total interest paid on all debts
            lblTotalInterest.Text = interestTotal.ToString("c");

            // skip difference if first calculation
            // if not, display interest difference with appropriate color
            if (lastInterestTotal != 0)
            {
                interestDifference = lastInterestTotal - interestTotal;
                interestDifference = Math.Round(interestDifference, 2, MidpointRounding.AwayFromZero);
                if (interestDifference > 0)
                {
                    interestDifferenceColor = Color.Green;
                }
                else if (interestDifference < 0)
                {
                    interestDifferenceColor = Color.Red;
                }
                lblInterestDifference.Text      = interestDifference.ToString("c");
                lblInterestDifference.ForeColor = interestDifferenceColor;
            }

            // store values for comparison on next calculation
            lastMonthsTotal   = monthsTotal;
            lastInterestTotal = interestTotal;
        }
Пример #3
0
        // parse active main panel data to create a list of debt objects
        private DebtManager CreateDebtList(List <Panel> activePanels)
        {
            DebtManager debtManager = new DebtManager();

            foreach (Panel p in activePanels)
            {
                List <Control> controls         = GetControls(p);
                List <Control> matchingControls = GetControls(GetPanel(p, 1));
                ListBox        type             = controls[2] as ListBox;
                ListBox        structure        = controls[3] as ListBox;
                NumericUpDown  order            = controls[10] as NumericUpDown;

                if (type.Text == "Amortized Loan")
                {
                    Amortized debt = new Amortized();
                    // extract info from input boxes
                    debt.payment = Convert.ToDouble(controls[4].Text);
                    if (rollover.Checked)
                    {
                        debt.maxPayment = Convert.ToDouble(controls[5].Text);
                    }

                    debt.order = (int)order.Value;

                    debt.principalLeft = Convert.ToDouble(matchingControls[0].Text);
                    debt.apr           = Convert.ToDouble(matchingControls[1].Text) / 100;
                    debt.annualFees    = Convert.ToDouble(matchingControls[2].Text);
                    NumericUpDown feesMonthUpDown = matchingControls[3] as NumericUpDown;
                    debt.feesMonth = (int)feesMonthUpDown.Value;

                    debt.resultsPanel = GetPanel(p, 2);

                    // set compounding period and interestFactor
                    if (structure.Text == "Daily")
                    {
                        debt.period = 365.25;
                    }
                    else if (structure.Text == "Monthly")
                    {
                        debt.period = 12;
                    }
                    debt.CalculateInterestFactor();

                    // add completed debt object to list
                    debtManager.Add(debt);
                }
                else if (type.Text == "Credit Card/Line")
                {
                    CreditCard debt = new CreditCard();

                    // extract info from text boxes
                    debt.payment = Convert.ToDouble(controls[4].Text);
                    if (rollover.Checked)
                    {
                        debt.maxPayment = Convert.ToDouble(controls[5].Text);
                    }

                    debt.order = (int)order.Value;

                    debt.principalLeft = Convert.ToDouble(matchingControls[0].Text);
                    debt.apr           = Convert.ToDouble(matchingControls[1].Text) / 100;
                    debt.annualFees    = Convert.ToDouble(matchingControls[2].Text);
                    NumericUpDown feesMonthUpDown = matchingControls[3] as NumericUpDown;
                    debt.feesMonth = Convert.ToInt16(feesMonthUpDown.Value);

                    debt.resultsPanel = GetPanel(p, 2);

                    // set compounding period and interestFactor
                    if (structure.Text == "Daily")
                    {
                        debt.period = 365.25;
                    }
                    else if (structure.Text == "Monthly")
                    {
                        debt.period = 12;
                    }
                    debt.CalculateInterestFactor();

                    // add completed debt object to list
                    debtManager.Add(debt);
                }
                else if (type.Text == "Add-on Loan")
                {
                    AddOn debt = new AddOn();

                    // extract info from text boxes
                    debt.payment = Convert.ToDouble(controls[4].Text);
                    if (rollover.Checked)
                    {
                        debt.maxPayment = Convert.ToDouble(controls[5].Text);
                    }

                    debt.order = (int)order.Value;

                    debt.principalLeft = Convert.ToDouble(matchingControls[0].Text);
                    debt.annualFees    = Convert.ToDouble(matchingControls[1].Text);
                    NumericUpDown feesMonthUpDown = matchingControls[2] as NumericUpDown;
                    debt.feesMonth = Convert.ToInt16(feesMonthUpDown.Value);

                    debt.resultsPanel = GetPanel(p, 2);

                    // add completed debt object to list
                    debtManager.Add(debt);
                }
            }
            debtManager.Sort((d1, d2) => d1.order.CompareTo(d2.order));
            return(debtManager);
        }