Пример #1
0
 public void Issue(IUserModel reader)
 {
     Status     = Status.Taken;
     ReaderID   = reader.ID;
     IssueDate  = DateTime.Now;
     ReturnDate = IssueDate.AddMonths(LendingMonths);
 }
Пример #2
0
        private SortedDictionary <double, double> GetCashflows(DateTime evaluationDate)
        {
            SortedDictionary <double, double> cashflows = new SortedDictionary <double, double>();
            double yearFrac;

            if (IsForward)
            {
                DateTime prevCashflowDate = IssueDate;
                DateTime cashflowDate     = IssueDate.AddMonths(CouponGapMonth());
                while (cashflowDate < MaturityDate)
                {
                    yearFrac = (cashflowDate - evaluationDate).TotalDays / 365;
                    if (yearFrac > 0)
                    {
                        cashflows.Add(yearFrac, CouponRate * (cashflowDate - prevCashflowDate).TotalDays / 365);
                    }
                    prevCashflowDate = cashflowDate;
                    cashflowDate     = cashflowDate.AddMonths(CouponGapMonth());
                }

                yearFrac = (MaturityDate - evaluationDate).TotalDays / 365;
                if (yearFrac > 0)
                {
                    cashflows.Add((MaturityDate - evaluationDate).TotalDays / 365, CouponRate * (MaturityDate - prevCashflowDate).TotalDays / 365);
                }
            }
            else
            {
                DateTime prevCashflowDate = MaturityDate.AddMonths(-CouponGapMonth());
                DateTime cashflowDate     = MaturityDate;
                while (prevCashflowDate > IssueDate)
                {
                    yearFrac = (cashflowDate - evaluationDate).TotalDays / 365;
                    if (yearFrac > 0)
                    {
                        cashflows.Add(yearFrac, CouponRate * (cashflowDate - prevCashflowDate).TotalDays / 365);
                    }
                    cashflowDate     = prevCashflowDate;
                    prevCashflowDate = prevCashflowDate.AddMonths(-CouponGapMonth());
                }

                yearFrac = (IssueDate - evaluationDate).TotalDays / 365;
                if (yearFrac > 0)
                {
                    cashflows.Add((IssueDate - evaluationDate).TotalDays / 365, CouponRate * (IssueDate - cashflowDate).TotalDays / 365);
                }
            }

            // Add principal
            if (cashflows.Count != 0)
            {
                double lastYearFrac = cashflows.Keys.Max();
                cashflows[lastYearFrac] += 1;
            }

            return(cashflows);
        }