예제 #1
0
 /// <summary>Adds a warning message if the specific <see cref="System.DateTime"/> is not a business day.
 /// </summary>
 /// <param name="date">The date.</param>
 protected void AddNotABusinessDayLogFileMsg(DateTime date)
 {
     if (HolidayCalendar.IsBusinessDay(date) == false)
     {
         // m_Logger.Add_Warning_NoBusinessDay(date.ToShortDateString() + " [holiday calendar ' " + HolidayCalendar.LongName + "']");
     }
 }
        /// <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;

            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(EndDate, holidayCalendar);

            if ((logger != null) && (endDate != EndDate))
            {
                logger.LogInformation("End date {0} has been adjusted to {1}.", EndDate.ToShortDateString(), endDate.ToShortDateString());
            }
        }
        /// <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 (StartDateTenor.TenorType)
            {
            case TenorType.Overnight:
                startDate = StartDateAdjustment.GetAdjustedDate(spotDate.AddDays(1), holidayCalendar);
                break;

            case TenorType.TomorrowNext:
                if ((SpotDateAdjustment.AdjustmentType != BusinessDayAdjustmentType.AdjustmentToBusinessDay) && (holidayCalendar.IsBusinessDay(spotDate) == false))
                {
                    spotDate = holidayCalendar.GetForwardAdjustedBusinessDay(spotDate);
                }
                spotDate  = holidayCalendar.AddBusinessDays(spotDate, 1);
                startDate = StartDateAdjustment.GetAdjustedDate(spotDate.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)
                {
                    spotDate = holidayCalendar.AddBusinessDays(spotDate, BusinessDaysToSettle);
                }
                startDate = StartDateAdjustment.GetAdjustedDate(spotDate.AddTenorTimeSpan(StartDateTenor), holidayCalendar);
                break;

            default:
                throw new NotImplementedException();
            }
            endDate = EndDateAdjustment.GetAdjustedDate(startDate.AddTenorTimeSpan(Tenor), holidayCalendar);
        }