/// <summary> /// Gets the unadjusted calculation date schedule. /// </summary> /// <param name="calculationPeriodDates">The calculation period dates.</param> /// <returns></returns> public List <CalculationPeriod> GetUnadjustedCalculationDateSchedule(CalculationPeriodDates calculationPeriodDates) { CalculationPeriodDates = calculationPeriodDates; PeriodInterval = CalculationPeriodHelper.CalculationPeriodFrequencyToInterval(calculationPeriodDates.calculationPeriodFrequency); _effectiveDate = XsdClassesFieldResolver.CalculationPeriodDatesGetEffectiveDate(calculationPeriodDates).unadjustedDate.Value; _termDate = XsdClassesFieldResolver.CalculationPeriodDatesGetTerminationDate(calculationPeriodDates).unadjustedDate.Value; RollConvention = calculationPeriodDates.calculationPeriodFrequency.rollConvention; _unadjustedDateScheduleList = CalculationPeriodHelper.GenerateUnadjustedCalculationDates(_effectiveDate, _termDate, calculationPeriodDates); return(_unadjustedDateScheduleList); }
///<summary> /// Gets all the Forecast curve name. ///</summary> ///<returns></returns> public static string GetRateVolatilityMatrixName(Swap swap) { AdjustableDate adjustableEffectiveDate = XsdClassesFieldResolver.CalculationPeriodDatesGetEffectiveDate(swap.swapStream[0].calculationPeriodDates); AdjustableDate adjustableTerminationDate = XsdClassesFieldResolver.CalculationPeriodDatesGetTerminationDate(swap.swapStream[0].calculationPeriodDates); var years = adjustableTerminationDate.unadjustedDate.Value.Year - adjustableEffectiveDate.unadjustedDate.Value.Year; var calculation = (Calculation)swap.swapStream[0].calculationPeriodAmount.Item; var notional = XsdClassesFieldResolver.CalculationGetNotionalSchedule(calculation); var currency = notional.notionalStepSchedule.currency.Value; return(PricingStructureTypeEnum.RateVolatilityMatrix + "." + currency + "-IRSwap-" + years + "Y"); }
/// <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; } // intermediary PE // if (interestRateStream.principalExchanges.intermediateExchange) { // Generate a list of intermediary 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 intermediaryExchange = PrincipalExchangeHelper.Create(stepDate); result.Add(intermediaryExchange); } } } //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 calculation periods. CalculationPeriodsPrincipalExchangesAndStubs result = CalculationPeriodGenerator.GenerateAdjustedCalculationPeriods( adjustableFirstPeriodDate.unadjustedDate.Value, adjustableTerminationDate.unadjustedDate.Value, firstRegularPeriodStartDate, lastRegularPeriodEndDate, calculationPeriodDates.calculationPeriodFrequency, calculationPeriodDates.calculationPeriodDatesAdjustments, paymentCalendar); //Determine whether the reset dates must be calculated. 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; } // intermediary PE // if (interestRateStream.principalExchanges.intermediateExchange) { // Generate a list of intermediary 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 intermediaryExchange = PrincipalExchangeHelper.Create(stepDate); result.Add(intermediaryExchange); } } } // 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); }
protected SwapPricer(ILogger logger, ICoreCache cache, String nameSpace, List <Pair <IBusinessCalendar, IBusinessCalendar> > legCalendars, Swap swapFpML, string basePartyReference, ProductTypeSimpleEnum productType, Boolean forecastRateInterpolation) { Multiplier = 1.0m; if (swapFpML == null) { return; } BusinessCentersResolver.ResolveBusinessCenters(swapFpML); ForecastRateInterpolation = forecastRateInterpolation; //Get the effective date AdjustableDate adjustableEffectiveDate = XsdClassesFieldResolver.CalculationPeriodDatesGetEffectiveDate(swapFpML.swapStream[0].calculationPeriodDates); EffectiveDate = adjustableEffectiveDate.unadjustedDate.Value; //We make the assumption that the termination date is the same for all legs. AdjustableDate adjustableTerminationDate = XsdClassesFieldResolver.CalculationPeriodDatesGetTerminationDate(swapFpML.swapStream[0].calculationPeriodDates); var paymentCalendar = BusinessCenterHelper.ToBusinessCalendar(cache, adjustableTerminationDate.dateAdjustments.businessCenters, nameSpace); TerminationDate = AdjustedDateHelper.ToAdjustedDate(paymentCalendar, adjustableTerminationDate); RiskMaturityDate = TerminationDate; //EffectiveDate is not set; ProductType = productType; PaymentCurrencies = new List <string>(); //Resolve the payer var legs = swapFpML.swapStream.Length; if (legs == 0) { return; } var flag = false; var index = 0; if (legCalendars != null && legCalendars.Count == legs) { flag = true; } foreach (var swapStream in swapFpML.swapStream) { bool payerIsBase = basePartyReference == swapStream.payerPartyReference.href;//TODO add in the calendar functionality. //Set the id of the first stream. PriceableInterestRateStream leg = flag ? new PriceableInterestRateStream(logger, cache, nameSpace, payerIsBase, swapStream, ForecastRateInterpolation, legCalendars[index].First, legCalendars[index].Second) : new PriceableInterestRateStream(logger, cache, nameSpace, payerIsBase, swapStream, ForecastRateInterpolation, null, null); Legs.Add(leg); //Add the currencies for the trade pricer. if (!PaymentCurrencies.Contains(leg.Currency.Value)) { PaymentCurrencies.Add(leg.Currency.Value); } index++; } if (swapFpML.additionalPayment != null) { AdditionalPayments = PriceableInstrumentsFactory.CreatePriceablePayments(basePartyReference, swapFpML.additionalPayment, null); foreach (var payment in swapFpML.additionalPayment) { if (!PaymentCurrencies.Contains(payment.paymentAmount.currency.Value)) { PaymentCurrencies.Add(payment.paymentAmount.currency.Value); } } } }