public static double GetPremiumImpl( ILogger logger, ICoreCache cache, String nameSpace, SwapLegParametersRange payLegParametersRange, SwapLegParametersRange receiveLegParametersRange, SwaptionParametersRange swaptionTermsRange, ValuationRange valuationRange) { InterestRateStream payStream = null; InterestRateStream receiveStream = null; UpdateCashflowsWithAmounts(logger, cache, nameSpace, payStream, payLegParametersRange, valuationRange); UpdateCashflowsWithAmounts(logger, cache, nameSpace, receiveStream, receiveLegParametersRange, valuationRange); Money fv = CashflowsHelper.GetForecastValue(payStream.cashflows); Money pv = CashflowsHelper.GetPresentValue(payStream.cashflows); double tillExpiry = (swaptionTermsRange.ExpirationDate - valuationRange.ValuationDate).TotalDays / 365.0; //Debug.Print("Future value :{0}", fv.amount); //Debug.Print("Present value :{0}", pv.amount); // get swaption price // double pricePerDollar = BlackModel.GetSwaptionValue((double)payLegParametersRange.CouponOrLastResetRate, (double)swaptionTermsRange.StrikeRate, (double)swaptionTermsRange.Volatility, tillExpiry); double premium = System.Math.Abs((double)payLegParametersRange.NotionalAmount * pricePerDollar); return(premium); }
private static List <IRateCurve> GetUniqueCurves( ILogger logger, ICoreCache cache, String nameSpace, SwapLegParametersRange payLegParametersRange, SwapLegParametersRange receiveLegParametersRange) { var uniqueCurves = new List <IRateCurve>(); var curveNames = new[] { payLegParametersRange.ForecastCurve, payLegParametersRange.DiscountCurve, receiveLegParametersRange.ForecastCurve, receiveLegParametersRange.DiscountCurve }; foreach (string curveName in curveNames) { if (!String.IsNullOrEmpty(curveName) && curveName.ToLower() != "none") { var curve = CurveLoader.LoadInterestRateCurve(logger, cache, nameSpace, curveName); if (!uniqueCurves.Contains(curve)) { uniqueCurves.Add(curve); } } } return(uniqueCurves); }
public static InterestRateStream GenerateStreamDefinition(SwapLegParametersRange legParametersRange) { InterestRateStream result; if (legParametersRange.LegType == LegType.Fixed) { result = GenerateFixedStreamDefinition(legParametersRange); } else if (legParametersRange.LegType == LegType.Floating) { result = GenerateFloatingStreamDefinition(legParametersRange); } else { throw new NotImplementedException(String.Format("'{0}' leg type is not suported!", legParametersRange.LegType)); } // Payer/Receiver references // result.payerPartyReference = PartyReferenceFactory.Create(legParametersRange.Payer); result.receiverPartyReference = PartyReferenceFactory.Create(legParametersRange.Receiver); // Principal exchanges // result.principalExchanges = new PrincipalExchanges(); result.principalExchanges.initialExchange = result.principalExchanges.finalExchange = result.principalExchanges.intermediateExchange = legParametersRange.GeneratePrincipalExchanges; return(result); }
public static InterestRateStream GetCashflowsSchedule(SwapLegParametersRange legParametersRange) { InterestRateStream stream = InterestRateStreamParametricDefinitionGenerator.GenerateStreamDefinition(legParametersRange); Cashflows cashflows = FixedAndFloatingRateStreamCashflowGenerator.GetCashflows(stream); stream.cashflows = cashflows; return(stream); }
private static InterestRateStream GetCashflowsSchedule( IBusinessCalendar fixingCalendar, IBusinessCalendar paymentCalendar, SwapLegParametersRange legParametersRange) { InterestRateStream stream = InterestRateStreamParametricDefinitionGenerator.GenerateStreamDefinition(legParametersRange); Cashflows cashflows = FixedAndFloatingRateStreamCashflowGenerator.GetCashflows(stream, fixingCalendar, paymentCalendar); stream.cashflows = cashflows; return(stream); }
/// <summary> /// /// </summary> /// <param name="leg1Parameters"></param> /// <param name="leg2Parameters"></param> /// <returns></returns> public static Swap GenerateDefiniton( SwapLegParametersRange leg1Parameters, SwapLegParametersRange leg2Parameters) { InterestRateStream stream1 = InterestRateStreamParametricDefinitionGenerator.GenerateStreamDefinition(leg1Parameters); InterestRateStreamHelper.SetPayerAndReceiver(stream1, leg1Parameters.Payer, leg1Parameters.Receiver); InterestRateStream stream2 = InterestRateStreamParametricDefinitionGenerator.GenerateStreamDefinition(leg2Parameters); InterestRateStreamHelper.SetPayerAndReceiver(stream2, leg2Parameters.Payer, leg2Parameters.Receiver); return(SwapFactory.Create(stream1, stream2)); }
/// <summary> /// /// </summary> /// <param name="logger"></param> /// <param name="cache"></param> /// <param name="nameSpace"></param> /// <param name="leg1Parameters"></param> /// <param name="leg1Calendars"></param> /// <param name="leg2Parameters"></param> /// <param name="leg2Calendars"></param> /// <param name="fixedRateSchedule"></param> /// <param name="spreadSchedule"></param> /// <param name="notionalSchedule"></param> /// <returns></returns> public static Swap GenerateDefinitionCashflowsAmounts(ILogger logger, ICoreCache cache, string nameSpace, SwapLegParametersRange leg1Parameters, Pair <IBusinessCalendar, IBusinessCalendar> leg1Calendars, SwapLegParametersRange leg2Parameters, Pair <IBusinessCalendar, IBusinessCalendar> leg2Calendars, Schedule fixedRateSchedule, Schedule spreadSchedule, NonNegativeAmountSchedule notionalSchedule) { var swap = GenerateDefinitionCashflows(logger, cache, nameSpace, leg1Parameters, leg1Calendars, leg2Parameters, leg2Calendars, fixedRateSchedule, spreadSchedule, notionalSchedule); return(swap); }
public static void UpdateStreamCashflowsAmounts(SwapLegParametersRange legParameters, InterestRateStream stream, ISwapLegEnvironment marketEnvironment, DateTime valuationDate) { IRateCurve forecastCurve = null; if (!String.IsNullOrEmpty(legParameters.ForecastCurve)) { forecastCurve = marketEnvironment.GetForecastRateCurve(); } IRateCurve discountingCurve = marketEnvironment.GetDiscountRateCurve(); FixedAndFloatingRateStreamCashflowGenerator.UpdateCashflowsAmounts(stream, forecastCurve, discountingCurve, valuationDate); }
public static void UpdatePaymentsAmounts(ILogger logger, ICoreCache cache, String nameSpace, Swap swap, SwapLegParametersRange leg1Parameters, SwapLegParametersRange leg2Parameters, IRateCurve leg1DiscountCurve, IRateCurve leg2DiscountCurve, DateTime valuationDate, IBusinessCalendar paymentCalendar) { foreach (Payment payment in swap.additionalPayment) { // choose correct discount curve // IRateCurve discountCurve; if (payment.payerPartyReference.href == leg1Parameters.Payer) { discountCurve = leg1DiscountCurve; } else if (payment.payerPartyReference.href == leg2Parameters.Payer) { discountCurve = leg2DiscountCurve; } else { throw new NotImplementedException(); } if (paymentCalendar == null) { var containsPaymentDateAdjustments = AdjustableOrAdjustedDateHelper.Contains(payment.paymentDate, ItemsChoiceType.dateAdjustments, out var dateAdjustments); if (containsPaymentDateAdjustments && dateAdjustments != null) { paymentCalendar = BusinessCenterHelper.ToBusinessCalendar(cache, ((BusinessDayAdjustments)dateAdjustments). businessCenters, nameSpace); } } var date = AdjustedDateHelper.GetAdjustedDate(paymentCalendar, payment.paymentDate); if (date == null) { continue; } payment.discountFactor = (decimal)discountCurve.GetDiscountFactor(valuationDate, (DateTime)date); payment.discountFactorSpecified = true; payment.presentValueAmount = MoneyHelper.Mul(payment.paymentAmount, payment.discountFactor); } }
/// <summary> /// /// </summary> /// <param name="logger"></param> /// <param name="cache"></param> /// <param name="nameSpace"></param> /// <param name="leg1Parameters"></param> /// <param name="leg1Calendars"></param> /// <param name="leg2Parameters"></param> /// <param name="leg2Calendars"></param> /// <param name="fixedRateSchedule"></param> /// <param name="spreadSchedule"></param> /// <param name="notionalSchedule"></param> /// <param name="leg1MarketEnvironment"></param> /// <param name="leg2MarketEnvironment"></param> /// <param name="valuationDate"></param> /// <returns></returns> public static Swap GenerateDefinitionCashflowsAmounts(ILogger logger, ICoreCache cache, string nameSpace, SwapLegParametersRange leg1Parameters, Pair <IBusinessCalendar, IBusinessCalendar> leg1Calendars, SwapLegParametersRange leg2Parameters, Pair <IBusinessCalendar, IBusinessCalendar> leg2Calendars, Schedule fixedRateSchedule, Schedule spreadSchedule, NonNegativeAmountSchedule notionalSchedule, ISwapLegEnvironment leg1MarketEnvironment, ISwapLegEnvironment leg2MarketEnvironment, DateTime valuationDate) { var swap = GenerateDefinitionCashflows(logger, cache, nameSpace, leg1Parameters, leg1Calendars, leg2Parameters, leg2Calendars, fixedRateSchedule, spreadSchedule, notionalSchedule); InterestRateStream stream1 = swap.swapStream[0]; InterestRateStream stream2 = swap.swapStream[1]; UpdateStreamCashflowsAmounts(leg1Parameters, stream1, leg1MarketEnvironment, valuationDate); UpdateStreamCashflowsAmounts(leg2Parameters, stream2, leg2MarketEnvironment, valuationDate); return(swap); }
private static void UpdateCashflowsWithAmounts( ILogger logger, ICoreCache cache, String nameSpace, InterestRateStream stream, SwapLegParametersRange legParametersRange, ValuationRange valuationRange) { // Get a forecast curve // IRateCurve forecastCurve = null; if (!String.IsNullOrEmpty(legParametersRange.ForecastCurve)) { forecastCurve = CurveLoader.LoadInterestRateCurve(logger, cache, nameSpace, legParametersRange.ForecastCurve); } // Get a discount curve // var discountCurve = CurveLoader.LoadInterestRateCurve(logger, cache, nameSpace, legParametersRange.DiscountCurve); FixedAndFloatingRateStreamCashflowGenerator.UpdateCashflowsAmounts(stream, forecastCurve, discountCurve, valuationRange.ValuationDate); }
public string CreateValuation( ILogger logger, ICoreCache cache, String nameSpace, IBusinessCalendar fixingCalendar, IBusinessCalendar paymentCalendar, SwaptionParametersRange swaptionParametersRange, List <StringObjectRangeItem> valuationSet, ValuationRange valuationRange, TradeRange tradeRange, SwapLegParametersRange leg1ParametersRange, SwapLegParametersRange leg2ParametersRange, List <InputCashflowRangeItem> leg1DetailedCashflowsListArray, List <InputCashflowRangeItem> leg2DetailedCashflowsListArray, List <InputPrincipalExchangeCashflowRangeItem> leg1PrincipalExchangeCashflowListArray, List <InputPrincipalExchangeCashflowRangeItem> leg2PrincipalExchangeCashflowListArray, List <AdditionalPaymentRangeItem> leg1AdditionalPaymentListArray, List <AdditionalPaymentRangeItem> leg2AdditionalPaymentListArray, List <PartyIdRangeItem> partyIdList, //optional List <OtherPartyPaymentRangeItem> otherPartyPaymentList, //opt List <FeePaymentRangeItem> feePaymentList //opt ) { var swap = GetPriceAndGeneratedFpMLSwap(logger, cache, nameSpace, fixingCalendar, paymentCalendar, valuationRange, tradeRange, leg1ParametersRange, leg2ParametersRange, leg1DetailedCashflowsListArray, leg2DetailedCashflowsListArray, leg1PrincipalExchangeCashflowListArray, leg2PrincipalExchangeCashflowListArray, leg1AdditionalPaymentListArray, leg2AdditionalPaymentListArray).Second; string baseParty = valuationRange.BaseParty; List <IRateCurve> uniqueCurves = GetUniqueCurves(logger, cache, nameSpace, leg1ParametersRange, leg2ParametersRange); Market fpMLMarket = InterestRateProduct.CreateFpMLMarketFromCurves(uniqueCurves); // TODO: add Trade Id & Trade data into valuation. (Trade.Id & Trade.TradeHeader.TradeDate) // // create ValuationReport and add it to in-memory collection. // Add methods! AssetValuation assetValuation = InterestRateProduct.CreateAssetValuationFromValuationSet(valuationSet); NonNegativeMoney premium = MoneyHelper.GetNonNegativeAmount(swaptionParametersRange.Premium, swaptionParametersRange.PremiumCurrency); AdjustableDate expirationDate = DateTypesHelper.ToAdjustableDate(swaptionParametersRange.ExpirationDate, swaptionParametersRange.ExpirationDateBusinessDayAdjustments, swaptionParametersRange.ExpirationDateCalendar); AdjustableOrAdjustedDate paymentDate = DateTypesHelper.ToAdjustableOrAdjustedDate(swaptionParametersRange.PaymentDate, swaptionParametersRange.PaymentDateBusinessDayAdjustments, swaptionParametersRange.PaymentDateCalendar); TimeSpan earliestExerciseTimeAsTimeSpan = TimeSpan.FromDays(swaptionParametersRange.EarliestExerciseTime); DateTime earliestExerciseTime = DateTime.MinValue.Add(earliestExerciseTimeAsTimeSpan); TimeSpan expirationTimeAsTimeSpan = TimeSpan.FromDays(swaptionParametersRange.ExpirationTime); DateTime expirationTime = DateTime.MinValue.Add(expirationTimeAsTimeSpan); var swaption = SwaptionFactory.Create(swap, premium, swaptionParametersRange.PremiumPayer, swaptionParametersRange.PremiumReceiver, paymentDate, expirationDate, earliestExerciseTime, expirationTime, swaptionParametersRange.AutomaticExcercise); // overrides the premium created by SwaptionFactort.Create // var feeList = new List <Payment>(); if (null != feePaymentList) { feeList.AddRange(feePaymentList.Select(feePaymentRangeItem => new Payment { paymentDate = DateTypesHelper.ToAdjustableOrAdjustedDate(feePaymentRangeItem.PaymentDate), paymentAmount = MoneyHelper.GetNonNegativeAmount(feePaymentRangeItem.Amount), payerPartyReference = PartyReferenceFactory.Create(feePaymentRangeItem.Payer), receiverPartyReference = PartyReferenceFactory.Create(feePaymentRangeItem.Receiver) })); } swaption.premium = feeList.ToArray(); string valuationReportAndProductId = tradeRange.Id ?? Guid.NewGuid().ToString(); swaption.id = valuationReportAndProductId; ValuationReport valuationReport = ValuationReportGenerator.Generate(valuationReportAndProductId, baseParty, valuationReportAndProductId, tradeRange.TradeDate, swaption, fpMLMarket, assetValuation); cache.SaveObject(valuationReport, valuationReportAndProductId, null); InterestRateProduct.ReplacePartiesInValuationReport(valuationReport, partyIdList); InterestRateProduct.AddOtherPartyPayments(valuationReport, otherPartyPaymentList); return(valuationReportAndProductId); }
private static InterestRateStream GenerateFixedStreamDefinition(SwapLegParametersRange legParametersRange) { var discountingType = legParametersRange.DiscountingType; InterestRateStream stream; Discounting discounting = null; if (discountingType != null && discountingType.ToUpper() != "NONE") { discounting = new Discounting { discountingType = EnumHelper.Parse <DiscountingTypeEnum>(legParametersRange.DiscountingType), discountingTypeSpecified = true }; stream = InterestRateStreamFactory.CreateFixedRateStream(DiscountingTypeToPayRelativeTo(discounting.discountingType)); } else { stream = InterestRateStreamFactory.CreateFixedRateStream(DiscountingTypeToPayRelativeTo(null)); } // Set effective and termination dates of the stream. // SetEffectiveAndTerminationDates(stream, legParametersRange.EffectiveDate, legParametersRange.MaturityDate, legParametersRange.PaymentBusinessDayAdjustments, legParametersRange.PaymentCalendar); //Set the FirstRegularPeriodStartDate SetFirstRegularPeriodStartDate(stream, legParametersRange.FirstRegularPeriodStartDate); //Set the LastRegularPeriodEndDate SetLastRegularPeriodEndDate(stream, legParametersRange.LastRegularPeriodEndDate); // Adjusted or unadjusted swap // var dateAdjustments = AdjustedType.Adjusted != legParametersRange.AdjustedType ? BusinessDayAdjustmentsHelper.Create(BusinessDayConventionEnum.NONE, legParametersRange.PaymentCalendar) : BusinessDayAdjustmentsHelper.Create(legParametersRange.PaymentBusinessDayAdjustments, legParametersRange.PaymentCalendar); stream.calculationPeriodDates.calculationPeriodDatesAdjustments = dateAdjustments; stream.calculationPeriodDates.calculationPeriodFrequency = CalculationPeriodFrequencyHelper.Parse(legParametersRange.PaymentFrequency, legParametersRange.RollConvention); //Set FirstPeriodStartDate i.e. Full or Partial period. if (legParametersRange.FirstCouponType == FirstCouponType.Full) { var firstCouponStartDate = new AdjustableDate { dateAdjustments = dateAdjustments, id = "FullFirstCoupon" }; SetFirstPeriodStartDate(stream, firstCouponStartDate); } // Set payment dates frequency and adjustments // stream.paymentDates.paymentFrequency = PeriodHelper.Parse(legParametersRange.PaymentFrequency).ToFrequency(); stream.paymentDates.paymentDatesAdjustments = BusinessDayAdjustmentsHelper.Create(legParametersRange.PaymentBusinessDayAdjustments, legParametersRange.PaymentCalendar); Calculation calculation = XsdClassesFieldResolver.CalculationPeriodAmountGetCalculation(stream.calculationPeriodAmount); // Set discounting type // calculation.discounting = discounting; // Set notional amount (as the initial value in notional schedule) // SetNotional(calculation, legParametersRange.NotionalAmount, legParametersRange.Currency); // Set fixed rate (as the initial value in fixed-rate schedule) // Schedule fixedRateSchedule = ScheduleHelper.Create(legParametersRange.CouponOrLastResetRate); XsdClassesFieldResolver.CalculationSetFixedRateSchedule(calculation, fixedRateSchedule); // Set the 'day count convention' // calculation.dayCountFraction = DayCountFractionHelper.Parse(legParametersRange.DayCount); // Initial stub // //if (paymentCalendar==null) //{ // paymentCalendar = BusinessCenterHelper.ToBusinessCalendar(cache, stream.paymentDates.paymentDatesAdjustments.businessCenters); //} //ProcessStubs(stream, legParametersRange, paymentCalendar); return(stream); }
private static InterestRateStream GenerateFloatingStreamDefinition(SwapLegParametersRange legParametersRange) { Discounting discounting = null; InterestRateStream stream; if (legParametersRange.DiscountingType != null && legParametersRange.DiscountingType.ToUpper() != "NONE") { discounting = new Discounting { discountingType = EnumHelper.Parse <DiscountingTypeEnum>(legParametersRange.DiscountingType) }; // Create the stream object stream = InterestRateStreamFactory.CreateFloatingRateStream(DiscountingTypeToPayRelativeTo(discounting.discountingType)); } else { // Create the stream object // stream = InterestRateStreamFactory.CreateFloatingRateStream(DiscountingTypeToPayRelativeTo(null)); } // Set effective and termination dates of the stream. // SetEffectiveAndTerminationDates(stream, legParametersRange.EffectiveDate, legParametersRange.MaturityDate, legParametersRange.PaymentBusinessDayAdjustments, legParametersRange.PaymentCalendar); //Set the FirstRegularPeriodStartDate SetFirstRegularPeriodStartDate(stream, legParametersRange.FirstRegularPeriodStartDate); //Set the LastRegularPeriodEndDate SetLastRegularPeriodEndDate(stream, legParametersRange.LastRegularPeriodEndDate); // Adjusted or unadjusted swap //Set the stub period type var dateAdjustments = AdjustedType.Adjusted != legParametersRange.AdjustedType ? BusinessDayAdjustmentsHelper.Create(BusinessDayConventionEnum.NONE, legParametersRange.PaymentCalendar) : BusinessDayAdjustmentsHelper.Create(legParametersRange.PaymentBusinessDayAdjustments, legParametersRange.PaymentCalendar); stream.calculationPeriodDates.calculationPeriodDatesAdjustments = dateAdjustments; stream.calculationPeriodDates.calculationPeriodFrequency = CalculationPeriodFrequencyHelper.Parse(legParametersRange.PaymentFrequency, legParametersRange.RollConvention); if (legParametersRange.FirstCouponType == FirstCouponType.Full) { var firstCouponStartDate = new AdjustableDate { dateAdjustments = dateAdjustments, id = "FullFirstCoupon" }; SetFirstPeriodStartDate(stream, firstCouponStartDate); } //Set the payment dates stream.paymentDates.paymentFrequency = PeriodHelper.Parse(legParametersRange.PaymentFrequency).ToFrequency(); stream.paymentDates.paymentDatesAdjustments = BusinessDayAdjustmentsHelper.Create(legParametersRange.PaymentBusinessDayAdjustments, legParametersRange.PaymentCalendar); stream.resetDates.fixingDates = RelativeDateOffsetHelper.Create(legParametersRange.PaymentFrequency, DayTypeEnum.Business, BusinessDayConventionEnum.NONE.ToString(), legParametersRange.FixingCalendar, "resetDates");//"NONE" & "resedDates" - hardcoded stream.resetDates.resetFrequency = ResetFrequencyHelper.Parse(legParametersRange.PaymentFrequency); stream.resetDates.resetDatesAdjustments = BusinessDayAdjustmentsHelper.Create(legParametersRange.FixingBusinessDayAdjustments, legParametersRange.FixingCalendar); Calculation calculation = XsdClassesFieldResolver.CalculationPeriodAmountGetCalculation(stream.calculationPeriodAmount); // Set discounting type // calculation.discounting = discounting; // Set notional amount (as the initial value in notional schedule) // SetNotional(calculation, legParametersRange.NotionalAmount, legParametersRange.Currency); // Set floating rate index name // string indexTenor = legParametersRange.PaymentFrequency; //string indexName = legParametersRange.ForecastCurve; string indexName = legParametersRange.ForecastIndexName; FloatingRateCalculation floatingRateCalculation = FloatingRateCalculationFactory.Create(indexName, indexTenor, legParametersRange.FloatingRateSpread); XsdClassesFieldResolver.CalculationSetFloatingRateCalculation(calculation, floatingRateCalculation); // Set day count convention // calculation.dayCountFraction = DayCountFractionHelper.Parse(legParametersRange.DayCount); return(stream); }
internal static Pair <ValuationResultRange, Swap> GetPriceAndGeneratedFpMLSwap( ILogger logger, ICoreCache cache, String nameSpace, IBusinessCalendar fixingCalendar, IBusinessCalendar paymentCalendar, ValuationRange valuationRange, TradeRange tradeRange, SwapLegParametersRange leg1ParametersRange, SwapLegParametersRange leg2ParametersRange, List <InputCashflowRangeItem> leg1DetailedCashflowsList, List <InputCashflowRangeItem> leg2DetailedCashflowsList, List <InputPrincipalExchangeCashflowRangeItem> leg1PrincipalExchangeCashflowList, List <InputPrincipalExchangeCashflowRangeItem> leg2PrincipalExchangeCashflowList, List <AdditionalPaymentRangeItem> leg1AdditionalPaymentList, List <AdditionalPaymentRangeItem> leg2AdditionalPaymentList ) { //Check if the calendars are null. If not build them! // // // // // InterestRateStream stream1 = GetCashflowsSchedule(fixingCalendar, paymentCalendar, leg1ParametersRange); //parametric definiton + cashflows schedule InterestRateStream stream2 = GetCashflowsSchedule(fixingCalendar, paymentCalendar, leg2ParametersRange); //parametric definiton + cashflows schedule var swap = SwapFactory.Create(stream1, stream2); // Update FpML cashflows // InterestRateSwapPricer.UpdateCashflowsWithDetailedCashflows(stream1.cashflows, leg1DetailedCashflowsList); InterestRateSwapPricer.UpdateCashflowsWithDetailedCashflows(stream2.cashflows, leg2DetailedCashflowsList); // Update PE // CreatePrincipalExchangesFromListOfRanges(stream1.cashflows, leg1PrincipalExchangeCashflowList); CreatePrincipalExchangesFromListOfRanges(stream2.cashflows, leg2PrincipalExchangeCashflowList); // Add bullet payments... // var bulletPaymentList = new List <Payment>(); if (null != leg1AdditionalPaymentList) { bulletPaymentList.AddRange(leg1AdditionalPaymentList.Select(bulletPaymentRangeItem => new Payment { payerPartyReference = PartyReferenceFactory.Create(leg1ParametersRange.Payer), receiverPartyReference = PartyReferenceFactory.Create(leg1ParametersRange.Receiver), paymentAmount = MoneyHelper.GetNonNegativeAmount(bulletPaymentRangeItem.Amount), paymentDate = DateTypesHelper.ToAdjustableOrAdjustedDate(bulletPaymentRangeItem.PaymentDate) })); } if (null != leg2AdditionalPaymentList) { bulletPaymentList.AddRange(leg2AdditionalPaymentList.Select(bulletPaymentRangeItem => new Payment { payerPartyReference = PartyReferenceFactory.Create(leg2ParametersRange.Payer), receiverPartyReference = PartyReferenceFactory.Create(leg2ParametersRange.Receiver), paymentAmount = MoneyHelper.GetNonNegativeAmount(bulletPaymentRangeItem.Amount), paymentDate = DateTypesHelper.ToAdjustableOrAdjustedDate(bulletPaymentRangeItem.PaymentDate) })); } swap.additionalPayment = bulletPaymentList.ToArray(); // Update FpML cashflows with DF,FV,PV, etc (LegParametersRange needed to access curve functionality) // UpdateCashflowsWithAmounts(logger, cache, nameSpace, stream1, leg1ParametersRange, valuationRange); UpdateCashflowsWithAmounts(logger, cache, nameSpace, stream2, leg2ParametersRange, valuationRange); // Update additional payments // var leg1DiscountCurve = CurveLoader.LoadInterestRateCurve(logger, cache, nameSpace, leg1ParametersRange.DiscountCurve); var leg2DiscountCurve = CurveLoader.LoadInterestRateCurve(logger, cache, nameSpace, leg2ParametersRange.DiscountCurve); SwapGenerator.UpdatePaymentsAmounts(logger, cache, nameSpace, swap, leg1ParametersRange, leg2ParametersRange, leg1DiscountCurve, leg2DiscountCurve, valuationRange.ValuationDate, paymentCalendar); //~ Update additional payments string baseParty = valuationRange.BaseParty; return(new Pair <ValuationResultRange, Swap>(CreateValuationRange(swap, baseParty), swap)); }
public InterestRateSwapParRateObjectiveFunction(SwapLegParametersRange payLegParametersRange, SwapLegParametersRange receiveLegParametersRange, ValuationRange valuationRange) { _payLegParametersRange = payLegParametersRange; _receiveLegParametersRange = receiveLegParametersRange; _valuationRange = valuationRange; }
/// <summary> /// /// </summary> /// <param name="logger"></param> /// <param name="cache"></param> /// <param name="nameSpace"></param> /// <param name="leg1Parameters"></param> /// <param name="leg1Calendars"></param> /// <param name="leg2Parameters"></param> /// <param name="leg2Calendars"></param> /// <param name="fixedRateSchedule"></param> /// <param name="spreadSchedule"></param> /// <param name="notionalSchedule"></param> /// <returns></returns> public static Swap GenerateDefinitionCashflows(ILogger logger, ICoreCache cache, string nameSpace, SwapLegParametersRange leg1Parameters, Pair <IBusinessCalendar, IBusinessCalendar> leg1Calendars, SwapLegParametersRange leg2Parameters, Pair <IBusinessCalendar, IBusinessCalendar> leg2Calendars, Schedule fixedRateSchedule, Schedule spreadSchedule, NonNegativeAmountSchedule notionalSchedule) { IBusinessCalendar leg1PaymentCalendar = null; IBusinessCalendar leg2PaymentCalendar = null; IBusinessCalendar leg1FixingCalendar = null; IBusinessCalendar leg2FixingCalendar = null; if (leg1Calendars != null) { leg1FixingCalendar = leg1Calendars.First; leg1PaymentCalendar = leg1Calendars.Second; } else { if (!string.IsNullOrEmpty(leg1Parameters.PaymentCalendar)) { var payCalendar = BusinessCentersHelper.Parse(leg1Parameters.PaymentCalendar); leg1PaymentCalendar = BusinessCenterHelper.ToBusinessCalendar(cache, payCalendar, nameSpace); leg1FixingCalendar = leg1PaymentCalendar; } if (!string.IsNullOrEmpty(leg1Parameters.FixingCalendar)) { var fixingCalendar = BusinessCentersHelper.Parse(leg1Parameters.FixingCalendar); leg1FixingCalendar = BusinessCenterHelper.ToBusinessCalendar(cache, fixingCalendar, nameSpace); } } if (leg2Calendars != null) { leg2FixingCalendar = leg2Calendars.First; leg2PaymentCalendar = leg2Calendars.Second; } else { if (!string.IsNullOrEmpty(leg2Parameters.PaymentCalendar)) { var payCalendar = BusinessCentersHelper.Parse(leg2Parameters.PaymentCalendar); leg2PaymentCalendar = BusinessCenterHelper.ToBusinessCalendar(cache, payCalendar, nameSpace); leg2FixingCalendar = leg2PaymentCalendar; } if (!string.IsNullOrEmpty(leg2Parameters.FixingCalendar)) { var fixingCalendar = BusinessCentersHelper.Parse(leg2Parameters.FixingCalendar); leg2FixingCalendar = BusinessCenterHelper.ToBusinessCalendar(cache, fixingCalendar, nameSpace); } } var swap = GenerateDefiniton(leg1Parameters, leg2Parameters); InterestRateStream stream1 = swap.swapStream[0]; InterestRateStream stream2 = swap.swapStream[1]; if (null != fixedRateSchedule) { // Set FixedRateSchedule (if this is a fixed leg) // if (leg1Parameters.IsFixedLegType()) { InterestRateStreamParametricDefinitionGenerator.SetFixedRateSchedule(stream1, fixedRateSchedule); } // Set FixedRateSchedule (if this is a fixed leg) // if (leg2Parameters.IsFixedLegType()) { InterestRateStreamParametricDefinitionGenerator.SetFixedRateSchedule(stream2, fixedRateSchedule); } } if (null != spreadSchedule) //for float legs only { if (leg1Parameters.IsFloatingLegType()) { InterestRateStreamParametricDefinitionGenerator.SetSpreadSchedule(stream1, spreadSchedule); } if (leg2Parameters.IsFloatingLegType()) { InterestRateStreamParametricDefinitionGenerator.SetSpreadSchedule(stream2, spreadSchedule); } } if (null != notionalSchedule) { // Set notional schedule // InterestRateStreamParametricDefinitionGenerator.SetNotionalSchedule(stream1, notionalSchedule); InterestRateStreamParametricDefinitionGenerator.SetNotionalSchedule(stream2, notionalSchedule); } stream1.cashflows = FixedAndFloatingRateStreamCashflowGenerator.GetCashflows(stream1, leg1FixingCalendar, leg1PaymentCalendar); stream2.cashflows = FixedAndFloatingRateStreamCashflowGenerator.GetCashflows(stream2, leg2FixingCalendar, leg2PaymentCalendar); return(swap); }