/// <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); }
/// <summary>Adds the specified holiday calendar. /// </summary> /// <param name="value">The holiday calendar.</param> /// <returns>A value indicating whether <paramref name="value"/> has been inserted.</returns> public static ItemAddedState Add(IHolidayCalendar value) { ItemAddedState state = sm_Pool.Add(value); // sm_Logger.Add_PoolItemState(state, (value != null) ? value.Name : null); return(state); }
/// <summary>Gets an adjusted date with respect to a specific <see cref="System.DateTime"/> object. /// </summary> /// <param name="date">The date.</param> /// <param name="holidayCalendar">The holiday calendar.</param> /// <returns>The <see cref="System.DateTime"/> object that is given by <paramref name="date"/> taken into account the business day /// convention represented by the current instance. /// </returns> /// <remarks>Perhaps the return value is not a business day, for example in the case of some end-of-month adjustment or 'no adjustment'.</remarks> public DateTime GetAdjustedDate(DateTime date, IHolidayCalendar holidayCalendar) { switch (date.Month) { case 1: case 2: case 3: var endOfQ1Date = new DateTime(date.Year, 3, 31); return(holidayCalendar.GetPreviousAdjustedBusinessDay(endOfQ1Date)); case 4: case 5: case 6: var endOfQ2Date = new DateTime(date.Year, 6, 30); return(holidayCalendar.GetPreviousAdjustedBusinessDay(endOfQ2Date)); case 7: case 8: case 9: var endOfQ3Date = new DateTime(date.Year, 9, 30); return(holidayCalendar.GetPreviousAdjustedBusinessDay(endOfQ3Date)); default: var endOfQ4Date = new DateTime(date.Year, 12, 31); return(holidayCalendar.GetPreviousAdjustedBusinessDay(endOfQ4Date)); } }
/// <summary>Gets an adjusted date with respect to a specific <see cref="System.DateTime"/> object. /// </summary> /// <param name="date">The date.</param> /// <param name="holidayCalendar">The holiday calendar.</param> /// <returns>The <see cref="System.DateTime"/> object that is given by <paramref name="date"/> taken into account the business day /// convention represented by the current instance. /// </returns> /// <remarks>Perhaps the return value is not a business day, for example in the case of some end-of-month adjustment or 'no adjustment'.</remarks> public DateTime GetAdjustedDate(DateTime date, IHolidayCalendar holidayCalendar) { DateTime FirstDayOfMonth = new DateTime(date.Year, date.Month, 1); int wednesdayIndex = ((10 - ((int)FirstDayOfMonth.DayOfWeek)) % 7 + 1) + 14; return(new DateTime(date.Year, date.Month, wednesdayIndex)); }
/// <summary>Gets an adjusted date with respect to a specific <see cref="System.DateTime"/> object. /// </summary> /// <param name="date">The date.</param> /// <param name="holidayCalendar">The holiday calendar.</param> /// <returns>The <see cref="System.DateTime"/> object that is given by <paramref name="date"/> taken into account the business day /// convention represented by the current instance. /// </returns> /// <remarks>Perhaps the return value is not a business day, for example in the case of some end-of-month adjustment or 'no adjustment'.</remarks> public DateTime GetAdjustedDate(DateTime date, IHolidayCalendar holidayCalendar) { if (date.Month == 2) { return(new DateTime(date.Year, date.Month, 28)); } return(new DateTime(date.Year, date.Month, DateTime.DaysInMonth(date.Year, date.Month))); }
/// <summary>Gets the weekend representation with respect to two <see cref="IHolidayCalendar"/> objects. /// </summary> /// <param name="holidayCalendar1">The first holiday calendar.</param> /// <param name="holidayCalendar2">The second holiday calendar.</param> /// <returns>A <see cref="IWeekendRepresentation"/> object which is the intersection of the <see cref="IWeekendRepresentation"/> /// objects of <paramref name="holidayCalendar1"/> and <paramref name="holidayCalendar2"/>.</returns> private static IWeekendRepresentation GetWeekendRepresentation(IHolidayCalendar holidayCalendar1, IHolidayCalendar holidayCalendar2) { ISet <DayOfWeek> weekendDays = new HashSet <DayOfWeek>(); holidayCalendar1.WeekendRepresentation.AddWeekendDaysTo(weekendDays); holidayCalendar2.WeekendRepresentation.IntersectWeekendDaysWith(weekendDays); return(WeekendFactory.GetWeekend(weekendDays)); }
/// <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>Initializes a new instance of the <see cref="CurrencyMarketConventions"/> class. /// </summary> /// <param name="bondMarketConventions">The bond market conventions.</param> /// <param name="creditMarketConventions">The credit market conventions.</param> /// <param name="inflationMarketConventions">The inflation market conventions.</param> /// <param name="moneyMarketConventions">The money market conventions.</param> /// <param name="swapMarketConventions">The swap market conventions.</param> /// <param name="holidayCalendar">The standard (settlement) holiday calendar.</param> /// <exception cref="ArgumentNullException">Thrown, if one of the arguments is <c>null</c>.</exception> public CurrencyMarketConventions(ReadOnlyBondMarketConventions bondMarketConventions, ReadOnlyCreditMarketConventions creditMarketConventions, ReadOnlyInflationMarketConventions inflationMarketConventions, ReadOnlyMoneyMarketConventions moneyMarketConventions, ReadOnlySwapMarketConventions swapMarketConventions, IHolidayCalendar holidayCalendar) : base(bondMarketConventions, creditMarketConventions, inflationMarketConventions, moneyMarketConventions, swapMarketConventions) { if (holidayCalendar == null) { throw new ArgumentNullException("holidayCalendar"); } m_HolidayCalendar = holidayCalendar; }
/// <summary>Gets an adjusted date with respect to a specific <see cref="System.DateTime"/> object. /// </summary> /// <param name="date">The date.</param> /// <param name="holidayCalendar">The holiday calendar.</param> /// <returns>The <see cref="System.DateTime"/> object that is given by <paramref name="date"/> taken into account the business day /// convention represented by the current instance. /// </returns> /// <remarks>Perhaps the return value is not a business day, for example in the case of some end-of-month adjustment or 'no adjustment'.</remarks> public DateTime GetAdjustedDate(DateTime date, IHolidayCalendar holidayCalendar) { DateTime nextBusinessDay = holidayCalendar.GetForwardAdjustedBusinessDay(date); if (nextBusinessDay.Month == date.Month) { return(nextBusinessDay); } return(holidayCalendar.GetPreviousAdjustedBusinessDay(date)); }
/// <summary>Initializes a new instance of the <see cref="DateSchedule"/> class. /// </summary> /// <param name="holidayCalendar">The holiday calendar.</param> /// <param name="name">The name of the date schedule.</param> /// <param name="longName">The (perhaps language dependent) long name of the date schedule.</param> /// <param name="logger">A logger; if <c>null</c> a new <see cref="ILogger"/> object will be created.</param> /// <exception cref="ArgumentNullException">Thrown, if <paramref name="holidayCalendar"/> is <c>null</c>.</exception> public DateSchedule(IHolidayCalendar holidayCalendar, IdentifierString name = null, IdentifierString longName = null, ILogger logger = null) { if (holidayCalendar == null) { throw new ArgumentNullException("holidayCalendar"); } HolidayCalendar = holidayCalendar; Initialize(name, longName, logger); m_DateScheduleSet = new SortedSet <DateTime>(); }
/// <summary>Creates a specified 'BU/252' day count convention used for Brazilian trades. /// </summary> /// <param name="holidayCalendar">The holiday calendar.</param> /// <param name="addToPool">The return value will be stored into the <see cref="DayCountConvention"/> pool for later use.</param> /// <returns>The specified 'BU/252' day count convention used for Brazilian trades. This day count fraction is defined as the numbers /// of business days in the period over 252the specified holiday calendar.</returns> public IDayCountConvention Create(IHolidayCalendar holidayCalendar, bool addToPool = false) { IDayCountConvention dayCountConvention = new DayCountConventionImplementation(holidayCalendar); if (addToPool == true) { DayCountConvention.Add(dayCountConvention); } return(dayCountConvention); }
private double CalculateEndDate(double rateStartDate, double rateTenor, IHolidayCalendar rateCalendar) { if (rateTenor == 0.0) { return(rateStartDate); } var term = Period.ValueToTerm(rateTenor); return(DateAdjuster.Add(DateTime.FromOADate(rateStartDate), term, 1, rateCalendar, true, RateAdjustmentMethod, RateStickyMonthEnd == YesNo.Yes).ToOADate()); }
/// <summary>Initializes a new instance of the <see cref="DayCountConventionImplementation"/> class. /// </summary> /// <param name="holidayCalendar">The holiday calendar.</param> /// <exception cref="ArgumentNullException">Thrown, if <paramref name="holidayCalendar"/> is <c>null</c>.</exception> internal DayCountConventionImplementation(IHolidayCalendar holidayCalendar) { if (holidayCalendar == null) { throw new ArgumentNullException("holidayCalendar"); } m_HolidayCalendar = holidayCalendar; m_Name = new IdentifierString("Bu/252 [" + holidayCalendar.Name.String + "]"); m_LongName = new IdentifierString(String.Format(DayCountConventionResources.Bu252LongName, (string)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; 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(); } }
/// <summary>Gets the region with respect to two holiday calendars, i.e. the region represents the union of each single region. /// </summary> /// <param name="holidayCalendar1">The first holiday calendar.</param> /// <param name="holidayCalendar2">The second holiday calendar.</param> /// <returns>The region with respect to the given holiday calendar, i.e. the <see cref="HolidayCalendarRegion"/> /// which is given by the bitwise operation of each region.</returns> private static HolidayCalendarRegion GetRegion(IHolidayCalendar holidayCalendar1, IHolidayCalendar holidayCalendar2) { HolidayCalendarRegion region = HolidayCalendarRegion.Unspecified; if (holidayCalendar1 != null) { region |= holidayCalendar1.Region; } if (holidayCalendar2 != null) { region |= holidayCalendar2.Region; } return(region); }
/// <summary>Gets the earliest date for which holiday informations are available with respect to two given <see cref="IHolidayCalendar"/> instances. /// </summary> /// <param name="holidayCalendar1">The first holiday calendar.</param> /// <param name="holidayCalendar2">The second holiday calendar.</param> /// <returns>The maximum of the <see cref="IHolidayCalendar.FirstDate"/> instances with respect to the given holiday calendars.</returns> private static DateTime GetFirstDate(IHolidayCalendar holidayCalendar1, IHolidayCalendar holidayCalendar2) { DateTime firstDate = DateTime.MinValue; if ((holidayCalendar1 != null) && (holidayCalendar1.FirstDate > firstDate)) { firstDate = holidayCalendar1.FirstDate; } if ((holidayCalendar2 != null) && (holidayCalendar2.FirstDate > firstDate)) { firstDate = holidayCalendar2.FirstDate; } return(firstDate); }
/// <summary>Gets the latest date for which holiday informations are available with respect to two <see cref="IHolidayCalendar"/> instances. /// </summary> /// <param name="holidayCalendar1">The first holiday calendar.</param> /// <param name="holidayCalendar2">The second holiday calendar.</param> /// <returns>The minimum of the <see cref="IHolidayCalendar.LastDate"/> instances with respect to the given holiday calendars.</returns> private static DateTime GetLastDate(IHolidayCalendar holidayCalendar1, IHolidayCalendar holidayCalendar2) { DateTime lastDate = DateTime.MaxValue; if ((holidayCalendar1 != null) && (holidayCalendar1.LastDate < lastDate)) { lastDate = holidayCalendar1.LastDate; } if ((holidayCalendar2 != null) && (holidayCalendar2.LastDate < lastDate)) { lastDate = holidayCalendar2.LastDate; } return(lastDate); }
/// <summary>Gets an adjusted date with respect to a specific <see cref="System.DateTime"/> object. /// </summary> /// <param name="date">The date.</param> /// <param name="holidayCalendar">The holiday calendar.</param> /// <returns>The <see cref="System.DateTime"/> object that is given by <paramref name="date"/> taken into account the business day /// convention represented by the current instance. /// </returns> /// <remarks>Perhaps the return value is not a business day, for example in the case of some end-of-month adjustment or 'no adjustment'.</remarks> public DateTime GetAdjustedDate(DateTime date, IHolidayCalendar holidayCalendar) { DateTime FirstDayOfMonth = new DateTime(date.Year, date.Month, 1); int wednesdayIndex = ((10 - ((int)FirstDayOfMonth.DayOfWeek)) % 7 + 1) + 14; /* if the wednesday is a business day, we go two business days back, otherwise one * business day. In general in both cases the 'monday' will be returned: */ DateTime previousBusinessDay = holidayCalendar.GetPreviousAdjustedBusinessDay(new DateTime(date.Year, date.Month, wednesdayIndex)); if (previousBusinessDay.DayOfWeek == DayOfWeek.Wednesday) // wednesday is some business day { return(holidayCalendar.AddBusinessDays(previousBusinessDay, -2)); } return(holidayCalendar.AddBusinessDays(previousBusinessDay, -1)); }
/// <summary>Initializes a new instance of the <see cref="JointHolidayCalendar"/> class. /// </summary> /// <param name="calendarName">The name of the calendar.</param> /// <param name="holidayCalendar1">The first holiday calendar.</param> /// <param name="holidayCalendar2">The second holiday calendar.</param> /// <param name="weekendRepresentation">The representation of the weekend.</param> /// <exception cref="ArgumentNullException">Thrown, if one of the arguments is <c>null</c>.</exception> protected JointHolidayCalendar(IdentifierString calendarName, IHolidayCalendar holidayCalendar1, IHolidayCalendar holidayCalendar2, IWeekendRepresentation weekendRepresentation) : base(calendarName, GetRegion(holidayCalendar1, holidayCalendar2), GetFirstDate(holidayCalendar1, holidayCalendar2), GetLastDate(holidayCalendar1, holidayCalendar2), weekendRepresentation) { if (holidayCalendar1 == null) { throw new ArgumentNullException("holidayCalendar1"); } if (holidayCalendar2 == null) { throw new ArgumentNullException("holidayCalendar2"); } m_HolidayCalendars = new List <IHolidayCalendar>() { holidayCalendar1, holidayCalendar2 }; m_Annotation = GetAnnotation(); }
/// <summary>Gets an adjusted date with respect to a specific <see cref="System.DateTime"/> object. /// </summary> /// <param name="date">The date.</param> /// <param name="holidayCalendar">The holiday calendar.</param> /// <returns>The <see cref="System.DateTime"/> object that is given by <paramref name="date"/> taken into account the business day /// convention represented by the current instance. /// </returns> /// <remarks>Perhaps the return value is not a business day, for example in the case of some end-of-month adjustment or 'no adjustment'.</remarks> public DateTime GetAdjustedDate(DateTime date, IHolidayCalendar holidayCalendar) { switch (date.Month) { case 1: case 2: case 3: return(new DateTime(date.Year, 3, 31)); case 4: case 5: case 6: return(new DateTime(date.Year, 6, 30)); case 7: case 8: case 9: return(new DateTime(date.Year, 9, 30)); default: return(new DateTime(date.Year, 12, 31)); } }
/// <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()); } }
static void InitializeHoliday(HolidayCalendar holidayCalendar, IHolidayCalendar calendar) { holidayCalendar.TimeZone = TimeZoneInfo.FindSystemTimeZoneById(RegistryTimeZoneProvider.GetRegistryKeyNameByTimeZoneId(calendar.TimeZone)); calendar.DatesExcluded.ForEach(holidayCalendar.AddExcludedDate); }
/// <summary>Gets an adjusted date with respect to a specific <see cref="System.DateTime"/> object. /// </summary> /// <param name="date">The date.</param> /// <param name="holidayCalendar">The holiday calendar.</param> /// <returns>The <see cref="System.DateTime"/> object that is given by <paramref name="date"/> taken into account the business day /// convention represented by the current instance. /// </returns> /// <remarks>Perhaps the return value is not a business day, for example in the case of some end-of-month adjustment or 'no adjustment'.</remarks> public DateTime GetAdjustedDate(DateTime date, IHolidayCalendar holidayCalendar) { return(date); }
/// <summary>Gets a specific fixing date. /// </summary> /// <param name="periodStartDate">The start date of the (interest) period.</param> /// <param name="holidayCalendar">The (settlement) calendar.</param> /// <returns>The specific fixing date.</returns> public DateTime GetFixingDate(DateTime periodStartDate, IHolidayCalendar holidayCalendar) { return(holidayCalendar.AddBusinessDays(periodStartDate, m_BusinessDays)); }
static void InitializeHoliday(HolidayCalendar holidayCalendar, IHolidayCalendar calendar) { holidayCalendar.TimeZone = TimeZoneInfo.FindSystemTimeZoneById(Persistent.Base.General.RegistryTimeZoneProvider.GetRegistryKeyNameByTimeZoneId(calendar.TimeZone)); calendar.DatesExcluded.ForEach(holidayCalendar.AddExcludedDate); }
/// <summary>Gets an adjusted date with respect to a specific <see cref="System.DateTime"/> object. /// </summary> /// <param name="date">The date.</param> /// <param name="holidayCalendar">The holiday calendar.</param> /// <returns>The <see cref="System.DateTime"/> object that is given by <paramref name="date"/> taken into account the business day /// convention represented by the current instance. /// </returns> /// <remarks>Perhaps the return value is not a business day, for example in the case of some end-of-month adjustment or 'no adjustment'.</remarks> public DateTime GetAdjustedDate(DateTime date, IHolidayCalendar holidayCalendar) { return(holidayCalendar.GetPreviousAdjustedBusinessDay(date)); }
/// <summary> /// Generate CTD dates and set CTD coupon rate and conversion factor. /// </summary> protected void GenerateCTD(double baseDate, double issueDate, double maturityDate, double couponInterval, double firstCouponDate, double penultimateCouponDate, DayCount dayCount, IHolidayCalendar calendar, double couponRate, double conversionFactor) { if (conversionFactor <= 0.0) { return; // No CTD details or details invalid } BondFutureOption deal = (BondFutureOption)fDeal; // Validation of settlement date not done for CTD details on price factor if (deal.Settlement_Date >= maturityDate) { throw new AnalyticsException("Settlement date must be before cheapest-to-deliver maturity date."); } DateGenerationResults dateGenerationResults = deal.GetDateGenerationResults(issueDate, maturityDate, couponInterval, firstCouponDate, penultimateCouponDate, dayCount, calendar); fPayDates = dateGenerationResults.PayDates; fAccruals = dateGenerationResults.AccrualYearFractions; fIssueDate = issueDate; fMaturityDate = maturityDate; fCouponInterval = couponInterval; fCouponRate = couponRate; fConversionFactor = conversionFactor; fAccrual = PricingFunctions.AccruedInterest(deal.Settlement_Date, fIssueDate, fPayDates, fAccruals, fCouponRate, 1.0, null); double strike = PriceTransform(deal.Strike); double tSettle = CalcUtils.DaysToYears(deal.Settlement_Date - baseDate); double tMaturity = CalcUtils.DaysToYears(fMaturityDate - baseDate); fStrikeYield = PricingFunctions.BondYieldFromPrice(tSettle, tMaturity, couponRate, couponInterval, strike); }
/// <summary> /// Returns a <see cref="DateGenerationResults"/> which contains bond futures option's dates and accrual information. /// </summary> /// <returns></returns> public DateGenerationResults GetDateGenerationResults(double issueDate, double maturityDate, double couponInterval, double firstCouponDate, double penultimateCouponDate, DayCount dayCount, IHolidayCalendar calendar) { var dateGenerationRequest = new DateGenerationRequest { RequiresPayDates = true, RequiresYearFractions = true, }; var dateGenerationParams = new DateGenerationParams { EffectiveDate = issueDate, MaturityDate = maturityDate, CouponPeriod = couponInterval, FirstCouponDate = firstCouponDate, PenultimateCouponDate = penultimateCouponDate, AccrualCalendar = calendar, AccrualDayCount = dayCount }; return(CashflowGeneration.GenerateCashflowDateAndValueLists(dateGenerationRequest, dateGenerationParams)); }
/// <summary> /// Generate CTD dates and set CTD coupon rate and conversion factor. /// </summary> protected void GenerateCTD(double issueDate, double maturityDate, double couponInterval, double firstCouponDate, double penultimateCouponDate, DayCount dayCount, IHolidayCalendar calendar, double couponRate, double conversionFactor) { if (conversionFactor <= 0.0) { return; // No CTD details or details invalid } BondFuture deal = (BondFuture)fDeal; if (deal.Settlement_Date >= maturityDate) { throw new AnalyticsException("Settlement date must be before cheapest-to-deliver maturity date."); } DateGenerationRequest dateGenerationRequest = new DateGenerationRequest { RequiresPayDates = true, RequiresYearFractions = true, }; DateGenerationParams dateGenerationParams = new DateGenerationParams { EffectiveDate = issueDate, MaturityDate = maturityDate, CouponPeriod = couponInterval, FirstCouponDate = firstCouponDate, PenultimateCouponDate = penultimateCouponDate, AccrualCalendar = calendar, AccrualDayCount = dayCount }; DateGenerationResults dateGenerationResults = CashflowGeneration.GenerateCashflowDateAndValueLists(dateGenerationRequest, dateGenerationParams); fPayDates = dateGenerationResults.PayDates; fAccruals = dateGenerationResults.AccrualYearFractions; fIssueDate = issueDate; fMaturityDate = maturityDate; fCouponRate = couponRate; fConversionFactor = conversionFactor; }
/// <summary>Creates a date schedule that contains the start and end dates of the interest periods of each caplets, i.e. T_0, T_1, T_2, ..., where [T_k; T_{k+1}] is the /// interest period of caplet k, k=0,...,n-1; The first caplet is already expired but it is part of the date schedule. /// </summary> /// <param name="referenceDate">The reference date, i.e. the trading date.</param> /// <param name="startDateAndEndDateDescription">A description of the start date of the first caplet as well as the end date of the last caplet, i.e. the start date and the maturity of the cap.</param> /// <param name="marketConventions">The market conventions.</param> /// <param name="holidayCalendar">The holiday calendar.</param> /// <param name="underlyingLiborTenor">A mapping of the null-based index of the start date of each caplet interest period to the tenor of the underlying Libor rate (output).</param> /// <param name="logger">An optional logger.</param> /// <returns>The date schedule of the interest periods, i.e. the start and end dates of each caplet; thus T_0, T_1, T_2, ..., where [T_k; T_{k+1}] is the /// interest period of caplet k, k=0,...,n-1; The first caplet is already expired but it is part of the date schedule. /// </returns> public ReadOnlyDateSchedule CreateInterestPeriodDateSchedule(DateTime referenceDate, ITimeframeDescription startDateAndEndDateDescription, ReadOnlyMoneyMarketConventions marketConventions, IHolidayCalendar holidayCalendar, out Func <int, TenorTimeSpan> underlyingLiborTenor, ILogger logger = null) { if (marketConventions == null) { throw new ArgumentNullException("marketConventions"); } if (holidayCalendar == null) { throw new ArgumentNullException("holidayCalendar"); } DateSchedule dateSchedule = new DateSchedule(holidayCalendar, logger: logger); dateSchedule.Add(new ForwardDateScheduleRule(referenceDate, startDateAndEndDateDescription, m_LiborRateTenor, marketConventions.BusinessDayConvention)); underlyingLiborTenor = (i => m_LiborRateTenor.GetFrequencyTenor()); return(dateSchedule.AsReadOnly()); }
/// <summary>Registers a specific <see cref="IHolidayCalendar"/> object. /// </summary> /// <param name="value">The <see cref="IHolidayCalendar"/> object to register.</param> /// <returns>A value indicating whether <paramref name="value"/> has been inserted.</returns> public ItemAddedState Add(IHolidayCalendar value) { return(HolidayCalendar.Add(value)); }
public bool IsBusinessDay(DateTime date, IHolidayCalendar holidayCalendar) { bool retValue = !holidayCalendar.IsHoliday(date); return retValue; }