Beispiel #1
0
 public TenorDateRelative(Frequency relativeTenor) => RelativeTenor = relativeTenor;
Beispiel #2
0
 public static DateTime[] AddPeriod(this DateTime[] dates, RollType rollType, Calendar calendar, Frequency datePeriod) => dates.Select(d => d.AddPeriod(rollType, calendar, datePeriod)).ToArray();
Beispiel #3
0
        /// <summary>
        /// Returns a date equal to the input date minus the specified period, adjusted for holidays
        /// </summary>
        /// <param name="date">Input date</param>
        /// <param name="rollType">RollType enum</param>
        /// <param name="calendar">Calendar</param>
        /// <param name="datePeriod">Period to add in the form of a Frequency object</param>
        /// <returns></returns>
        public static DateTime SubtractPeriod(this DateTime date, RollType rollType, Calendar calendar, Frequency datePeriod)
        {
            date = date.Date;
            if (datePeriod.PeriodCount == 0)
            {
                return(IfHolidayRoll(date, rollType, calendar));
            }

            if (datePeriod.PeriodType == DatePeriodType.B)
            {
                //Business day jumping so we need to do something different
                var d = date;
                for (var i = 0; i < datePeriod.PeriodCount; i++)
                {
                    d = d.AddDays(-1);
                    d = IfHolidayRoll(d, rollType, calendar);
                }

                return(d);
            }
            return(AddPeriod(date, rollType, calendar, new Frequency(0 - datePeriod.PeriodCount, datePeriod.PeriodType)));
        }
Beispiel #4
0
        /// <summary>
        /// Returns a date equal to the input date plus the specified period, adjusted for holidays
        /// </summary>
        /// <param name="date">Input date</param>
        /// <param name="rollType">RollType enum</param>
        /// <param name="calendar">Calendar</param>
        /// <param name="datePeriod">Period to add in the form of a Frequency object</param>
        /// <returns></returns>
        public static DateTime AddPeriod(this DateTime date, RollType rollType, Calendar calendar, Frequency datePeriod)
        {
            if (calendar == null && datePeriod.PeriodType == DatePeriodType.B)
            {
                return(date);
            }

            date = date.Date;
            if (datePeriod.PeriodCount == 0)
            {
                return(IfHolidayRoll(date, rollType, calendar));
            }

            if (datePeriod.PeriodType == DatePeriodType.B)
            {
                if (datePeriod.PeriodCount < 0) //actually a subtract
                {
                    return(date.SubtractPeriod(rollType, calendar, new Frequency(-datePeriod.PeriodCount, datePeriod.PeriodType)));
                }

                //Business day jumping so we need to do something different
                var d = date;
                for (var i = 0; i < datePeriod.PeriodCount; i++)
                {
                    d = d.AddDays(1);
                    d = IfHolidayRoll(d, rollType, calendar);
                }
                return(d);
            }

            DateTime dt;

            switch (datePeriod.PeriodType)
            {
            case DatePeriodType.D:
                dt = date.AddDays(datePeriod.PeriodCount);
                break;

            case DatePeriodType.M:
                dt = date.AddMonths(datePeriod.PeriodCount);
                break;

            case DatePeriodType.W:
                dt = date.AddDays(datePeriod.PeriodCount * 7);
                break;

            default:
                dt = date.AddYears(datePeriod.PeriodCount);
                break;
            }

            if ((rollType == RollType.MF_LIBOR) && (date == date.LastBusinessDayOfMonth(calendar)))
            {
                dt = date.LastBusinessDayOfMonth(calendar);
            }
            if (rollType == RollType.ShortFLongMF)
            {
                if (datePeriod.PeriodType == DatePeriodType.B || datePeriod.PeriodType == DatePeriodType.D || datePeriod.PeriodType == DatePeriodType.W)
                {
                    return(IfHolidayRoll(dt, RollType.F, calendar));
                }
                else
                {
                    return(IfHolidayRoll(dt, RollType.MF, calendar));
                }
            }
            return(IfHolidayRoll(dt, rollType, calendar));
        }