Пример #1
0
        public FinancialPeriod GetCouponPeriod(FinancialDay settlementDay, FinancialDay maturityDay, int frequency)
        {
            var periods        = new List <FinancialPeriod>();
            var settlementDate = settlementDay.ToDateTime();
            var tmpDay         = maturityDay;
            var lastDay        = tmpDay;

            while (tmpDay.ToDateTime() > settlementDate)
            {
                switch (frequency)
                {
                case 1:
                    tmpDay = tmpDay.SubtractYears(1);
                    break;

                case 2:
                    tmpDay = tmpDay.SubtractMonths(6, maturityDay.Day);
                    break;

                case 4:
                    tmpDay = tmpDay.SubtractMonths(3, maturityDay.Day);
                    break;

                default:
                    throw new ArgumentException("frequency");
                }
                if (tmpDay > settlementDay)
                {
                    lastDay = tmpDay;
                }
            }
            return(new FinancialPeriod(tmpDay, lastDay));
        }
Пример #2
0
        public int GetNumberOfCouponPeriods(FinancialDay settlementDay, FinancialDay maturityDay, int frequency)
        {
            var settlementDate = settlementDay.ToDateTime();
            var tmpDay         = maturityDay;
            var lastDay        = tmpDay;
            var nPeriods       = 0;

            while (tmpDay.ToDateTime() > settlementDate)
            {
                switch (frequency)
                {
                case 1:
                    tmpDay = tmpDay.SubtractYears(1);
                    break;

                case 2:
                    tmpDay = tmpDay.SubtractMonths(6, maturityDay.Day);
                    break;

                case 4:
                    tmpDay = tmpDay.SubtractMonths(3, maturityDay.Day);
                    break;

                default:
                    throw new ArgumentException("frequency");
                }
                nPeriods++;
            }
            return(nPeriods);
        }
Пример #3
0
 public int CompareTo(FinancialDay other)
 {
     if (other is null)
     {
         return(1);
     }
     if (Year == other.Year && Month == other.Month && Day == other.Day)
     {
         return(0);
     }
     return(ToDateTime().CompareTo(other.ToDateTime()));
 }
Пример #4
0
 public double GetDaysBetweenDates(FinancialDay startDate, FinancialDay endDate)
 {
     if (startDate.Day == 31)
     {
         startDate.Day = 30;
     }
     if (endDate.Day == 31)
     {
         endDate.Day = 30;
     }
     return(GetDaysBetweenDates(startDate, endDate, 360));
 }
Пример #5
0
        protected double ActualDaysInLeapYear(FinancialDay start, FinancialDay end)
        {
            var daysInLeapYear = 0d;

            for (var year = start.Year; year <= end.Year; year++)
            {
                if (System.DateTime.IsLeapYear(year))
                {
                    if (year == start.Year)
                    {
                        daysInLeapYear += new System.DateTime(year + 1, 1, 1).Subtract(start.ToDateTime()).TotalDays;
                    }
                    else if (year == end.Year)
                    {
                        daysInLeapYear += end.ToDateTime().Subtract(new System.DateTime(year, 1, 1)).TotalDays;
                    }
                    else
                    {
                        daysInLeapYear += 366d;
                    }
                }
            }
            return(daysInLeapYear);
        }
Пример #6
0
 public double GetDaysBetweenDates(FinancialDay startDate, FinancialDay endDate)
 {
     if (endDate.IsLastDayOfFebruary)
     {
         if (startDate.IsLastDayOfFebruary)
         {
             endDate.Day   = 30;
             startDate.Day = 30;
         }
         else
         {
             endDate.Day = 30;
         }
     }
     if (endDate.Day == 31 && (startDate.Day == 30 || startDate.Day == 31))
     {
         endDate.Day = 30;
     }
     if (startDate.Day == 31)
     {
         startDate.Day = 30;
     }
     return(GetDaysBetweenDates(startDate, endDate, 360));
 }
Пример #7
0
 protected virtual double GetDaysBetweenDates(FinancialDay start, FinancialDay end, int basis)
 {
     return(basis * (end.Year - start.Year) + 30 * (end.Month - start.Month) + ((end.Day > 30 ? 30 : end.Day) - (start.Day > 30 ? 30 : start.Day)));
 }
Пример #8
0
 public FinancialPeriod(FinancialDay start, FinancialDay end)
 {
     Start = start;
     End   = end;
 }
Пример #9
0
        /// <summary>
        /// Number of days between two <see cref="FinancialDay"/>s
        /// </summary>
        /// <param name="day">The other day</param>
        /// <returns>Number of days according to the <see cref="DayCountBasis"/> of this day</returns>
        public double SubtractDays(FinancialDay day)
        {
            var financialDays = FinancialDaysFactory.Create(Basis);

            return(financialDays.GetDaysBetweenDates(this.ToDateTime(), day.ToDateTime()));
        }
Пример #10
0
 public double GetCoupdays(FinancialDay start, FinancialDay end, int frequency)
 {
     return(360d / frequency);
 }
Пример #11
0
 protected override double GetDaysBetweenDates(FinancialDay start, FinancialDay end, int basis)
 {
     return(end.ToDateTime().Subtract(start.ToDateTime()).TotalDays);
 }
Пример #12
0
 public double GetDaysBetweenDates(FinancialDay startDate, FinancialDay endDate)
 {
     return(GetDaysBetweenDates(startDate, endDate, 360));
 }
Пример #13
0
 public double GetCoupdays(FinancialDay start, FinancialDay end, int frequency)
 {
     return(GetDaysBetweenDates(start, end));
 }