/// <summary> /// Gets the adjusted calculation period start dates. /// </summary> /// <param name="effectiveDate">The effective date.</param> /// <param name="terminationDate">The termination date.</param> /// <param name="periodInterval">The period interval.</param> /// <param name="rollConvention">The roll convention.</param> /// <param name="firstRegularPeriodDate">The first regular period date.</param> /// <param name="stubPeriodType">Type of the stub period.</param> /// <param name="businessCalendar">The businessCalendar.</param> /// <param name="businessDayConvention">The business day convention.</param> /// <returns>A vertical range of dates.</returns> public static DateTime[] GetAdjustedCalculationPeriodDates(DateTime effectiveDate, DateTime terminationDate, string periodInterval, string rollConvention, DateTime firstRegularPeriodDate, string stubPeriodType, IBusinessCalendar businessCalendar, string businessDayConvention) { const string dateToReturn = "unadjustedStartDate"; StubPeriodTypeEnum?stubType = null; if (!string.IsNullOrEmpty(stubPeriodType)) { stubType = (StubPeriodTypeEnum)Enum.Parse(typeof(StubPeriodTypeEnum), stubPeriodType, true); } var periods = CalculationPeriodHelper.GenerateUnadjustedCalculationDates(effectiveDate, terminationDate, firstRegularPeriodDate, PeriodHelper.Parse(periodInterval), RollConventionEnumHelper.Parse(rollConvention), stubType); var dates = CalculationPeriodHelper.GetCalculationPeriodsProperty <DateTime>(periods, dateToReturn); var newDates = new DateTime[dates.Count]; var index = 0; foreach (var date in dates) { var newDate = BusinessCalendarHelper.Advance(businessCalendar, date, "Calendar", "0D", businessDayConvention); newDates[index] = newDate; index++; } var result = newDates; return(result); }
/// <summary> /// Returns the unadjusted the calculation dates /// </summary> /// <param name="effectiveDate">The effective date.</param> /// <param name="terminationDate">The termination date.</param> /// <param name="intervalToFirstRegularPeriodStart">The interval to first regular period start.</param> /// <param name="periodInterval">The period interval.</param> /// <param name="rollConvention">The roll convention.</param> /// <param name="stubPeriodType">Type of the stub period.</param> /// <returns></returns> public static DateTime[] UnadjustedCalculationDatesFromFirstRegularInterval(DateTime effectiveDate, DateTime terminationDate, string intervalToFirstRegularPeriodStart, string periodInterval, string rollConvention, string stubPeriodType) { const string dateToReturn = "unadjustedStartDate"; StubPeriodTypeEnum?stubType = null; if (!string.IsNullOrEmpty(stubPeriodType)) { stubType = (StubPeriodTypeEnum)Enum.Parse(typeof(StubPeriodTypeEnum), stubPeriodType, true); } var periods = CalculationPeriodHelper.GenerateUnadjustedCalculationDates(effectiveDate, terminationDate, PeriodHelper.Parse(periodInterval), PeriodHelper.Parse(intervalToFirstRegularPeriodStart), RollConventionEnumHelper.Parse(rollConvention), stubType); var dates = CalculationPeriodHelper.GetCalculationPeriodsProperty <DateTime>(periods, dateToReturn); var result = dates.ToArray(); return(result); }
public void RegularPeriodIntervalUnadjustedDates() { Boolean bFailureSet = false; List <CalculationPeriod> unadjustedCalcPeriods; try { // 5 year 3 month cash flow DateTime startDate = new DateTime(2007, 01, 5); Period intervalToMaturity = PeriodHelper.Parse("5Y"); Period periodInterval = PeriodHelper.Parse("3M"); CalculationPeriodSchedule cps = new CalculationPeriodSchedule(); unadjustedCalcPeriods = cps.GetUnadjustedCalculationDateSchedule(startDate, intervalToMaturity, periodInterval); List <DateTime> dates = CalculationPeriodHelper.GetCalculationPeriodsProperty <DateTime>(unadjustedCalcPeriods, "unadjustedStartDate"); Assert.AreEqual(unadjustedCalcPeriods.Count, 20); Assert.IsFalse(cps.HasInitialStub); Assert.IsFalse(cps.HasFinalStub); // 3 year 6 month cash flow startDate = new DateTime(2010, 12, 3); intervalToMaturity = PeriodHelper.Parse("3Y"); periodInterval = PeriodHelper.Parse("6M"); cps = new CalculationPeriodSchedule(); unadjustedCalcPeriods = cps.GetUnadjustedCalculationDateSchedule(startDate, intervalToMaturity, periodInterval); dates = CalculationPeriodHelper.GetCalculationPeriodsProperty <DateTime>(unadjustedCalcPeriods, "unadjustedStartDate"); Assert.AreEqual(unadjustedCalcPeriods.Count, 6); Assert.IsFalse(cps.HasInitialStub); Assert.IsFalse(cps.HasFinalStub); // This should generate an excpetion startDate = new DateTime(2010, 12, 3); intervalToMaturity = PeriodHelper.Parse("3Y"); periodInterval = PeriodHelper.Parse("7M"); cps = new CalculationPeriodSchedule(); unadjustedCalcPeriods = cps.GetUnadjustedCalculationDateSchedule(startDate, intervalToMaturity, periodInterval); dates = CalculationPeriodHelper.GetCalculationPeriodsProperty <DateTime>(unadjustedCalcPeriods, "unadjustedStartDate"); Assert.AreEqual(unadjustedCalcPeriods.Count, 6); Assert.IsFalse(cps.HasInitialStub); Assert.IsFalse(cps.HasFinalStub); Assert.IsTrue(!bFailureSet); } catch (Exception ex) { bFailureSet = true; Console.WriteLine("RegularPeriodIntervalUnadjustedDates: " + ex.Message); } }
public void ShortFinalStubSpecified() { DateTime startDate = new DateTime(2007, 01, 5); DateTime endDate = new DateTime(2012, 01, 5); RollConventionEnum rollConvention = RollConventionEnum.Item26; CalculationPeriodFrequency periodFrequency = CalculationPeriodFrequencyHelper.Parse("3M", rollConvention.ToString()); DateTime firstRegularPeriodDate = new DateTime(2007, 1, 26); CalculationPeriodSchedule cps = new CalculationPeriodSchedule(); List <CalculationPeriod> unadjustedCalcPeriods = cps.GetUnadjustedCalculationDateSchedule(startDate, endDate, firstRegularPeriodDate, periodFrequency, StubPeriodTypeEnum.ShortFinal); List <DateTime> dates = CalculationPeriodHelper.GetCalculationPeriodsProperty <DateTime>(unadjustedCalcPeriods, "unadjustedStartDate"); Assert.AreEqual(unadjustedCalcPeriods.Count, 21); Assert.IsTrue(cps.HasFinalStub); Assert.IsTrue(cps.HasInitialStub); Assert.IsTrue(CalculationPeriodHelper.IsShortStub(unadjustedCalcPeriods[unadjustedCalcPeriods.Count - 1], cps.PeriodInterval)); }
public void RegularPeriodFrequencyUnadjustedDates() { // 5 year 3 month cash flow DateTime startDate = new DateTime(2007, 01, 5); RollConventionEnum rollConvention = RollConventionEnum.Item26; CalculationPeriodFrequency frequencyToMaturity = CalculationPeriodFrequencyHelper.Parse("5Y", rollConvention.ToString()); CalculationPeriodFrequency periodFrequency = CalculationPeriodFrequencyHelper.Parse("3M", rollConvention.ToString()); CalculationPeriodSchedule cps = new CalculationPeriodSchedule(); List <CalculationPeriod> unadjustedCalcPeriods = cps.GetUnadjustedCalculationDateSchedule(startDate, frequencyToMaturity, periodFrequency); List <DateTime> dates = CalculationPeriodHelper.GetCalculationPeriodsProperty <DateTime>(unadjustedCalcPeriods, "unadjustedStartDate"); Assert.AreEqual(unadjustedCalcPeriods.Count, 20); Assert.IsFalse(cps.HasInitialStub); Assert.IsFalse(cps.HasFinalStub); }