/// <summary> /// Don't generate stubs? /// </summary> /// <param name="interestRateStream"></param> /// <param name="rollDates">from #1st roll date to last roll date (last roll dates is effectively the end of the swap)</param> /// <param name="paymentCalendar"></param> /// <returns></returns> public static CalculationPeriodsPrincipalExchangesAndStubs GenerateCalculationPeriodsPrincipalExchangesAndStubsFromRollDates(InterestRateStream interestRateStream, List <DateTime> rollDates, IBusinessCalendar paymentCalendar) { CalculationPeriodDates calculationPeriodDates = interestRateStream.calculationPeriodDates; AdjustableDate adjustableEffectiveDate = XsdClassesFieldResolver.CalculationPeriodDatesGetEffectiveDate(calculationPeriodDates); var result = new CalculationPeriodsPrincipalExchangesAndStubs(); for (int rollDateIndex = 0; rollDateIndex < rollDates.Count - 1; ++rollDateIndex) { DateTime startOfThePeriod = rollDates[rollDateIndex]; DateTime endOfThePeriod = rollDates[rollDateIndex + 1]; var calculationPeriod = new CalculationPeriod(); // Set adjusted period dates // CalculationPeriodHelper.SetAdjustedDates(calculationPeriod, startOfThePeriod, endOfThePeriod); result.Add(calculationPeriod); } // Add principle exchanges if this need is defined in parametric representation of the interest rate steam. // if (null != interestRateStream.principalExchanges) { // Initial PE // if (interestRateStream.principalExchanges.initialExchange) { //if (paymentCalendar == null) //{ // paymentCalendar = BusinessCenterHelper.ToBusinessCalendar(cache, adjustableEffectiveDate.dateAdjustments.businessCenters); //} PrincipalExchange initialExchange = PrincipalExchangeHelper.Create(AdjustedDateHelper.ToAdjustedDate(paymentCalendar, adjustableEffectiveDate)); result.InitialPrincipalExchange = initialExchange; } // intermediatory PE // if (interestRateStream.principalExchanges.intermediateExchange) { // Generate a list of intermediatory PE exchanges // Calculation calculation = XsdClassesFieldResolver.CalculationPeriodAmountGetCalculation(interestRateStream.calculationPeriodAmount); Notional notionalSchedule = XsdClassesFieldResolver.CalculationGetNotionalSchedule(calculation); if (null != notionalSchedule.notionalStepSchedule.step)//there should be steps - otherwise NO interm. exchanges. { foreach (DateTime stepDate in ScheduleHelper.GetStepDates(notionalSchedule.notionalStepSchedule)) { PrincipalExchange intermediatoryExchange = PrincipalExchangeHelper.Create(stepDate); result.Add(intermediatoryExchange); } } } //AdjustableDate adjustableTerminationDate = XsdClassesFieldResolver.CalculationPeriodDates_GetTerminationDate(calculationPeriodDates); DateTime lastRollDate = rollDates[rollDates.Count - 1]; // Final PE // if (interestRateStream.principalExchanges.finalExchange) { //PrincipalExchange finalExchange = PrincipalExchangeHelper.Create(DateTypesHelper.ToAdjustedDate(adjustableTerminationDate)); PrincipalExchange finalExchange = PrincipalExchangeHelper.Create(lastRollDate); result.FinalPrincipalExchange = finalExchange; } } return(result); }
public static CalculationPeriodsPrincipalExchangesAndStubs GenerateCalculationPeriodsPrincipalExchangesAndStubs( InterestRateStream interestRateStream, IBusinessCalendar fixingCalendar, IBusinessCalendar paymentCalendar) { CalculationPeriodDates calculationPeriodDates = interestRateStream.calculationPeriodDates; AdjustableDate adjustableEffectiveDate = XsdClassesFieldResolver.CalculationPeriodDatesGetEffectiveDate(calculationPeriodDates); AdjustableDate adjustableTerminationDate = XsdClassesFieldResolver.CalculationPeriodDatesGetTerminationDate(calculationPeriodDates); AdjustableDate adjustableFirstPeriodDate = adjustableEffectiveDate; DateTime?firstRegularPeriodStartDate = XsdClassesFieldResolver.CalculationPeriodDatesGetFirstRegularPeriodStartDate(calculationPeriodDates); var tempDate = XsdClassesFieldResolver.CalculationPeriodDatesGetFirstPeriodStartDate(calculationPeriodDates); if (tempDate != null && firstRegularPeriodStartDate != null) { adjustableFirstPeriodDate = tempDate; Frequency frequency = calculationPeriodDates.calculationPeriodFrequency; var startDate = CalculationPeriodGenerator.AddPeriod((DateTime)firstRegularPeriodStartDate, IntervalHelper.FromFrequency(frequency), -1); adjustableFirstPeriodDate.unadjustedDate = IdentifiedDateHelper.Create(startDate); } DateTime?lastRegularPeriodEndDate = XsdClassesFieldResolver.CalculationPeriodDatesGetLastRegularPeriodEndDate(calculationPeriodDates); // This assumes automatic adjustment of calculationperiods. CalculationPeriodsPrincipalExchangesAndStubs result = CalculationPeriodGenerator.GenerateAdjustedCalculationPeriods( adjustableFirstPeriodDate.unadjustedDate.Value, adjustableTerminationDate.unadjustedDate.Value, firstRegularPeriodStartDate, lastRegularPeriodEndDate, calculationPeriodDates.calculationPeriodFrequency, calculationPeriodDates.calculationPeriodDatesAdjustments, paymentCalendar); //Determine whether the reset dates must be calcuated. Calculation calculation = XsdClassesFieldResolver.CalculationPeriodAmountGetCalculation(interestRateStream.calculationPeriodAmount); // Add principle exchanges if this need is defined in parametric representation of the interest rate steam. // if (null != interestRateStream.principalExchanges) { //if (paymentCalendar == null) //{ // paymentCalendar = BusinessCenterHelper.ToBusinessCalendar(cache, adjustableEffectiveDate.dateAdjustments.businessCenters); //} // Initial PE // if (interestRateStream.principalExchanges.initialExchange) { PrincipalExchange initialExchange = PrincipalExchangeHelper.Create(AdjustedDateHelper.ToAdjustedDate(paymentCalendar, adjustableEffectiveDate)); result.InitialPrincipalExchange = initialExchange; } // intermediatory PE // if (interestRateStream.principalExchanges.intermediateExchange) { // Generate a list of intermediatory PE exchanges // Notional notionalSchedule = XsdClassesFieldResolver.CalculationGetNotionalSchedule(calculation); if (null != notionalSchedule.notionalStepSchedule.step)//there should be steps - otherwise NO interm. exchanges. { foreach (DateTime stepDate in ScheduleHelper.GetStepDates(notionalSchedule.notionalStepSchedule)) { PrincipalExchange intermediatoryExchange = PrincipalExchangeHelper.Create(stepDate); result.Add(intermediatoryExchange); } } } // Final PE // Assume the same calendar is used for the termination date as well! if (interestRateStream.principalExchanges.finalExchange) { PrincipalExchange finalExchange = PrincipalExchangeHelper.Create(AdjustedDateHelper.ToAdjustedDate(paymentCalendar, adjustableTerminationDate)); result.FinalPrincipalExchange = finalExchange; } } //Only does upfront resetRelativeTo start date. if (interestRateStream.resetDates != null && calculation.Items[0].GetType() == typeof(FloatingRateCalculation)) { //Get the fixing date convention. var fixingDateConvention = interestRateStream.resetDates.resetDatesAdjustments; //if (fixingCalendar == null) //{ // fixingCalendar = BusinessCenterHelper.ToBusinessCalendar(cache, fixingDateConvention.businessCenters); //} foreach (var calculationPeriod in result.CalculationPeriods) { if (calculationPeriod.adjustedStartDateSpecified) { //Set the adjusted fixing date. var adjustedFixingDate = AdjustedDateHelper.ToAdjustedDate(fixingCalendar, calculationPeriod.adjustedStartDate, fixingDateConvention); var floatingRateDefinition = new FloatingRateDefinition(); var rateObservation = new RateObservation { observedRateSpecified = false, adjustedFixingDateSpecified = true, adjustedFixingDate = adjustedFixingDate }; floatingRateDefinition.rateObservation = new[] { rateObservation }; calculationPeriod.Item1 = floatingRateDefinition; } } //The initial stub period. if (result.InitialStubCalculationPeriod != null) { if (result.InitialStubCalculationPeriod.adjustedStartDateSpecified) { //Set the adjusted fixing date. var adjustedFixingDate = AdjustedDateHelper.ToAdjustedDate(fixingCalendar, result.InitialStubCalculationPeriod.adjustedStartDate, fixingDateConvention); var floatingRateDefinition = new FloatingRateDefinition(); var rateObservation = new RateObservation { observedRateSpecified = false, adjustedFixingDateSpecified = true, adjustedFixingDate = adjustedFixingDate }; floatingRateDefinition.rateObservation = new[] { rateObservation }; result.InitialStubCalculationPeriod.Item1 = floatingRateDefinition; } } //The final stub period if (result.FinalStubCalculationPeriod != null) { if (result.FinalStubCalculationPeriod.adjustedStartDateSpecified) { //Set the adjusted fixing date. var adjustedFixingDate = AdjustedDateHelper.ToAdjustedDate(fixingCalendar, result.FinalStubCalculationPeriod.adjustedStartDate, fixingDateConvention); var floatingRateDefinition = new FloatingRateDefinition(); var rateObservation = new RateObservation { observedRateSpecified = false, adjustedFixingDateSpecified = true, adjustedFixingDate = adjustedFixingDate }; floatingRateDefinition.rateObservation = new[] { rateObservation }; result.FinalStubCalculationPeriod.Item1 = floatingRateDefinition; } } } return(result); }