Exemple #1
0
            /// <summary>Gets the start and end date of the timeframe.
            /// </summary>
            /// <param name="referenceDate">A reference date (can be a business day or a holiday).</param>
            /// <param name="holidayCalendar">The (settlement) holiday calendar.</param>
            /// <param name="startDate">The start date of the time span with respect to <paramref name="referenceDate"/> (output).</param>
            /// <param name="endDate">The end date of the time span with respect to <paramref name="referenceDate"/> (output).</param>
            /// <param name="logger">An optional logger.</param>
            public void GetStartAndEndDate(DateTime referenceDate, IHolidayCalendar holidayCalendar, out DateTime startDate, out DateTime endDate, ILogger logger = null)
            {
                var IMMDate = Next(referenceDate);

                startDate = StartDateAdjustment.GetAdjustedDate(IMMDate, holidayCalendar);
                endDate   = EndDateAdjustment.GetAdjustedDate(startDate.AddTenorTimeSpan(Tenor), holidayCalendar);
            }
Exemple #2
0
            /// <summary>Gets the start and end date of the timeframe.
            /// </summary>
            /// <param name="referenceDate">A reference date (can be a business day or a holiday).</param>
            /// <param name="holidayCalendar">The (settlement) holiday calendar.</param>
            /// <param name="fixingLag">The fixing lag, i.e. a method used to calculate the fixing date with respect to the period. Will be applied to the IMM Date (even if the IMM date is not a business day).</param>
            /// <param name="startDate">The start date of the time span with respect to <paramref name="referenceDate"/> (output).</param>
            /// <param name="endDate">The end date of the time span with respect to <paramref name="referenceDate"/> (output).</param>
            /// <param name="logger">An optional logger.</param>
            /// <returns>The fixing date of with respect to the (interest) period.</returns>
            public DateTime GetStartAndEndDate(DateTime referenceDate, IHolidayCalendar holidayCalendar, IFixingLag fixingLag, out DateTime startDate, out DateTime endDate, ILogger logger = null)
            {
                var IMMDate = Next(referenceDate);

                startDate = StartDateAdjustment.GetAdjustedDate(IMMDate, holidayCalendar);
                endDate   = EndDateAdjustment.GetAdjustedDate(startDate.AddTenorTimeSpan(Tenor), holidayCalendar);
                return(fixingLag.GetFixingDate(IMMDate, holidayCalendar));
            }
        /// <summary>Gets the start and end date of the timeframe.
        /// </summary>
        /// <param name="referenceDate">A reference date (can be a business day or a holiday).</param>
        /// <param name="holidayCalendar">The (settlement) holiday calendar.</param>
        /// <param name="startDate">The start date of the time span with respect to <paramref name="referenceDate" /> (output).</param>
        /// <param name="endDate">The end date of the time span with respect to <paramref name="referenceDate" /> (output).</param>
        /// <param name="logger">An optional logger.</param>
        public void GetStartAndEndDate(DateTime referenceDate, IHolidayCalendar holidayCalendar, out DateTime startDate, out DateTime endDate, ILogger logger = null)
        {
            DateTime adjReferenceDate = SpotDateAdjustment.GetAdjustedDate(referenceDate, holidayCalendar);

            if ((logger != null) && (adjReferenceDate != referenceDate))
            {
                logger.LogInformation("Reference date {0} has been adjusted to {1}.", referenceDate.ToShortDateString(), adjReferenceDate.ToShortDateString());
            }

            DateTime spotDate = adjReferenceDate;

            switch (Tenor.TenorType)
            {
            case TenorType.Overnight:
                startDate = StartDateAdjustment.GetAdjustedDate(spotDate, holidayCalendar);
                endDate   = EndDateAdjustment.GetAdjustedDate(startDate.AddDays(1), holidayCalendar);
                break;

            case TenorType.TomorrowNext:
                if ((SpotDateAdjustment.AdjustmentType != BusinessDayAdjustmentType.AdjustmentToBusinessDay) && (holidayCalendar.IsBusinessDay(spotDate) == false))
                {
                    spotDate = holidayCalendar.GetForwardAdjustedBusinessDay(spotDate);
                }
                startDate = StartDateAdjustment.GetAdjustedDate(holidayCalendar.AddBusinessDays(spotDate, 1), holidayCalendar);
                endDate   = EndDateAdjustment.GetAdjustedDate(startDate.AddDays(1), holidayCalendar);
                break;

            case TenorType.RegularTenor:
                if ((SpotDateAdjustment.AdjustmentType != BusinessDayAdjustmentType.AdjustmentToBusinessDay) && (holidayCalendar.IsBusinessDay(spotDate) == false))
                {
                    if (BusinessDaysToSettle > 0)
                    {
                        spotDate = holidayCalendar.GetForwardAdjustedBusinessDay(spotDate);
                    }
                    else if (BusinessDaysToSettle < 0)
                    {
                        spotDate = holidayCalendar.GetPreviousAdjustedBusinessDay(spotDate);
                    }
                }
                if (BusinessDaysToSettle != 0)
                {
                    startDate = StartDateAdjustment.GetAdjustedDate(holidayCalendar.AddBusinessDays(spotDate, BusinessDaysToSettle), holidayCalendar);
                }
                else
                {
                    startDate = StartDateAdjustment.GetAdjustedDate(spotDate, holidayCalendar);
                }
                endDate = EndDateAdjustment.GetAdjustedDate(startDate.AddTenorTimeSpan(Tenor), holidayCalendar);
                break;

            default:
                throw new NotImplementedException();
            }
        }
Exemple #4
0
        /// <summary>Adds some <see cref="System.DateTime"/> objects into a specific date schedule.
        /// </summary>
        /// <param name="dateSchedule">The date schedule.</param>
        /// <exception cref="NotOperableException">Thrown, if the current instance it not operable.</exception>
        public void AddDatesToDateSchedule(DateSchedule dateSchedule)
        {
            if (IsOperable == false)
            {
                throw new NotOperableException("BackwardDateScheduleRule");
            }
            DateTime firstDate, terminationDate;

            m_TimeSpanDescription.GetStartAndEndDate(m_ReferenceDate, dateSchedule.HolidayCalendar, out firstDate, out terminationDate, dateSchedule.Logging);

            if (terminationDate < firstDate)
            {
                throw new ArgumentException(String.Format(ExceptionMessages.ArgumentOutOfRangeGreaterEqual, "End date [" + terminationDate.ToShortDateString() + "]", "first date [" + firstDate.ToShortDateString() + "]"));
            }
            dateSchedule.Add(terminationDate);  // add the end date

            // gets the date which is used as 'base date' for the date generation loop:
            DateTime seed = terminationDate;

            if ((m_LastRegularDate != null) && (m_LastRegularDate.HasValue))  // 'last regular date' is given
            {
                seed = m_LastRegularDate.Value;
                if (seed > terminationDate)
                {
                    throw new ArgumentException(String.Format(ExceptionMessages.ArgumentOutOfRangeLessEqual, "Last regular date [" + seed.ToShortDateString() + "]", "end date [" + terminationDate.ToShortDateString() + "]"));
                }
            }
            if (m_SeedBusinessDayConvention != null)  // perhaps adjust the 'base date' which is used for the date generation loop
            {
                seed = m_SeedBusinessDayConvention.GetAdjustedDate(seed, dateSchedule.HolidayCalendar);
            }
            else
            {
                seed = m_BusinessDayConvention.GetAdjustedDate(seed, dateSchedule.HolidayCalendar);
            }
            dateSchedule.Add(seed);

            // gets the exit condition for the loop:
            DateTime exitDate = firstDate;  // perhaps not a business day

            if ((m_FirstRegularDate != null) && (m_FirstRegularDate.HasValue))
            {
                exitDate = m_FirstRegularDate.Value;
                if (exitDate > seed)
                {
                    throw new ArgumentException(String.Format(ExceptionMessages.ArgumentOutOfRangeLessEqual, "First regular date [" + exitDate.ToShortDateString() + "]", "last [regular] date [" + seed.ToShortDateString() + "]"));
                }
            }

            if (m_Frequency.IsOnceFrequency())  // end date and seed date are already added
            {
                if (exitDate != firstDate)      // perhaps add the first regular date
                {
                    dateSchedule.Add(exitDate); // one may apply the business day convention to the first regular date
                }
            }
            else  // do the loop with respect to the frequency
            {
                TenorTimeSpan frequencyTenor = m_Frequency.GetFrequencyTenor();
                DateTime      runningDate    = m_BusinessDayConvention.GetAdjustedDate(seed.AddTenorTimeSpan(frequencyTenor), dateSchedule.HolidayCalendar);
                int           periodIndex    = -1;

                while (runningDate >= exitDate)
                {
                    dateSchedule.Add(runningDate);
                    periodIndex--;

                    runningDate = seed.AddTenorTimeSpan(frequencyTenor, periodIndex);
                    runningDate = m_BusinessDayConvention.GetAdjustedDate(runningDate, dateSchedule.HolidayCalendar);
                }
            }
            dateSchedule.Add(firstDate);
        }