Exemplo n.º 1
0
        public void AdditionalPaymentTest()
        {
            Loan l = new Loan(3800000m, 0.12, new DateTime(2015, 1, 1), 120, Calendar.EmptyCalendar);
            Assert.AreEqual(l.NumberOfPayments, 120);
            Assert.IsTrue(Math.Abs(l.TotalPrincipalPayment - 3800000.0m) < Eps);
            Assert.IsTrue(Math.Abs(l.TotalPayment - l.TotalPrincipalPayment - l.TotalInterest) < Eps);

            l.AdditionalPayment(new DateTime(2015, 6, 1), 200000);
            Assert.AreEqual(l.NumberOfPayments, 121);
            Assert.IsTrue(Math.Abs(l.TotalPrincipalPayment - 3800000.0m) < Eps);
            Assert.IsTrue(Math.Abs(l.TotalPayment - l.TotalPrincipalPayment - l.TotalInterest) < Eps);
        }
Exemplo n.º 2
0
        public void LoanTest()
        {
            Loan l = new Loan(3800000m, 0.12, new DateTime(2015, 1, 1), 120, Calendar.EmptyCalendar);
            Assert.AreEqual(l.NumberOfPayments, 120);
            Assert.IsTrue(Math.Abs(l.TotalPrincipalPayment-3800000.0m) < Eps);
            Assert.IsTrue(Math.Abs(l.TotalPayment - l.TotalPrincipalPayment - l.TotalInterest) < Eps);

            Loan l1 = new Loan(521450.0m, 0.28, new DateTime(2015, 1, 25), 26, Calendar.EmptyCalendar); // RUS
            Assert.AreEqual(l1.NumberOfPayments, 26);
            Assert.IsTrue(Math.Abs(l1.TotalPrincipalPayment - 521450.0m) < Eps);
            Assert.IsTrue(Math.Abs(l1.TotalPayment - l1.TotalPrincipalPayment - l1.TotalInterest) < Eps);
        }
Exemplo n.º 3
0
 public void AdditionalPayment(DateTime date, decimal amount)
 {
     // todo: + percents for partial month
     int i = 0;
     for (; i < m_payments.Count; ++i)
         if (m_payments[i].paymentDate > date)
             break;
     Debug.Assert(i > 0 && i < m_payments.Count);
     decimal totalPaid = 0.0m;
     for (int j = 0; j < i; ++j)
         totalPaid += m_payments[j].principalPayment;
     totalPaid += amount;
     decimal newAmount = m_principal - totalPaid;
     bool bHasFuturePayments = (i < m_payments.Count);
     DateTime newStartDate = bHasFuturePayments ? m_payments[i + 1].paymentDate : date;
     int newDuration = m_payments.Count - i;
     m_payments.RemoveRange(i, newDuration);
     m_payments.Add(new Cashflow(date, amount, 0.0m)); // todo: interest payments here
     if (bHasFuturePayments)
     {
         Loan newLoan = new Loan(newAmount, m_rate, newStartDate, newDuration, m_calendar);
         m_payments.AddRange(newLoan.Schedule);
         m_payment = newLoan.Payment;
     }
 }