/// <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"); }
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); } } } }
/// <summary> /// /// </summary> /// <param name="logger"></param> /// <param name="cache"></param> /// <param name="paymentCalendar"> </param> /// <param name="capFloorFpML"></param> /// <param name="basePartyReference"></param> /// <param name="forecastRateInterpolation"></param> /// <param name="nameSpace"></param> /// <param name="fixingCalendar"> </param> public CapFloorPricer(ILogger logger, ICoreCache cache, String nameSpace, IBusinessCalendar fixingCalendar, IBusinessCalendar paymentCalendar, CapFloor capFloorFpML, string basePartyReference, Boolean forecastRateInterpolation) { if (capFloorFpML == null) { return; } //AnalyticsModel = new SimpleIRSwapInstrumentAnalytic(); BusinessCentersResolver.ResolveBusinessCenters(capFloorFpML); ForecastRateInterpolation = forecastRateInterpolation; //We make the assumption that the termination date is the same for all legs.. AdjustableDate adjustableTerminationDate = XsdClassesFieldResolver.CalculationPeriodDatesGetTerminationDate(capFloorFpML.capFloorStream.calculationPeriodDates); if (paymentCalendar == null) { paymentCalendar = BusinessCenterHelper.ToBusinessCalendar(cache, adjustableTerminationDate.dateAdjustments.businessCenters, nameSpace); } RiskMaturityDate = AdjustedDateHelper.ToAdjustedDate(paymentCalendar, adjustableTerminationDate); ProductType = ProductTypeSimpleEnum.CapFloor; PaymentCurrencies = new List <string>(); //Resolve the payer if (capFloorFpML.capFloorStream == null) { return; } var calculation = capFloorFpML.capFloorStream.calculationPeriodAmount.Item as Calculation; var floatingRateCalculation = calculation?.Items[0] as FloatingRateCalculation; if (floatingRateCalculation == null) { return; } if (floatingRateCalculation.capRateSchedule != null) { var schedule = floatingRateCalculation.capRateSchedule[0]; var buyerPartyReference = schedule.buyer.Value; if (buyerPartyReference == PayerReceiverEnum.Receiver) { BuyerPartyReference = capFloorFpML.capFloorStream.receiverPartyReference.href; SellerPartyReference = capFloorFpML.capFloorStream.payerPartyReference.href; } else { BuyerPartyReference = capFloorFpML.capFloorStream.payerPartyReference.href; SellerPartyReference = capFloorFpML.capFloorStream.receiverPartyReference.href; } } if (floatingRateCalculation.capRateSchedule == null && floatingRateCalculation.floorRateSchedule != null) { var schedule = floatingRateCalculation.floorRateSchedule[0]; var buyerPartyReference = schedule.buyer.Value; if (buyerPartyReference == PayerReceiverEnum.Receiver) { BuyerPartyReference = capFloorFpML.capFloorStream.receiverPartyReference.href; SellerPartyReference = capFloorFpML.capFloorStream.payerPartyReference.href; } else { BuyerPartyReference = capFloorFpML.capFloorStream.payerPartyReference.href; SellerPartyReference = capFloorFpML.capFloorStream.receiverPartyReference.href; } } BasePartyBuyer = basePartyReference == BuyerPartyReference;//TODO add in the calendar functionality. //Set the id of the first stream. THe generator requires the flag: BasePartyPayer. var capFloorLeg = new PriceableCapFloorStream(logger, cache, nameSpace, !BasePartyBuyer, capFloorFpML.capFloorStream, ForecastRateInterpolation, fixingCalendar, paymentCalendar); Legs.Add(capFloorLeg); //Add the currencies for the trade pricer. if (!PaymentCurrencies.Contains(capFloorLeg.Currency.Value)) { PaymentCurrencies.Add(capFloorLeg.Currency.Value); } if (capFloorFpML.additionalPayment != null) { AdditionalPayments = PriceableInstrumentsFactory.CreatePriceablePayments(basePartyReference, capFloorFpML.additionalPayment, null); foreach (var payment in capFloorFpML.additionalPayment) { if (!PaymentCurrencies.Contains(payment.paymentAmount.currency.Value)) { PaymentCurrencies.Add(payment.paymentAmount.currency.Value); } } } }