Example #1
0
 public Loan(decimal principal, double rate, DateTime startDate, int duration, Calendar calendar)
 {
     m_principal = principal;
     m_rate = rate;
     m_startDate = startDate;
     m_calendar = calendar;
     int nPaymentsPerYear = 12; // Monthly; duration - months
     double flowRate = rate / nPaymentsPerYear;
     m_payment = (decimal) (((double) principal * flowRate) / (1 - 1 / Math.Pow(1 + flowRate, duration)));
     decimal amount = principal;
     DateTime date = startDate; // ! paying immediately, percents for the month forward; in case of full deal the principal payment would be 1 month off
     m_payments = new List<Cashflow>(duration);
     for (long i = 0; i < duration; ++i)
     {
         decimal interestPayment = (decimal) ((double) amount * flowRate);
         decimal principalPayment = m_payment - interestPayment;
         amount -= principalPayment;
         m_payments.Add(new Cashflow(date, principalPayment, interestPayment));
         date = date.AddMonths(1); // don't respect calendar
     }
     Debug.Assert(Math.Abs(amount) < 0.01m);
     Debug.Assert(m_payments.Count == duration);
 }
Example #2
0
 public void Add(Calendar calendar)
 {
     calendars.Add(calendar);
 }