private static InterestRateStream CreateGenericStream(PayRelativeToEnum paymentDateRelativeTo) { InterestRateStream stream = new InterestRateStream(); CalculationPeriodDates calculationPeriodDates = new CalculationPeriodDates(); stream.calculationPeriodDates = calculationPeriodDates; PaymentDates paymentDates = new PaymentDates(); stream.paymentDates = paymentDates; paymentDates.payRelativeTo = paymentDateRelativeTo; CalculationPeriodAmount calculationPeriodAmount = new CalculationPeriodAmount(); stream.calculationPeriodAmount = calculationPeriodAmount; Calculation calculation = new Calculation(); stream.calculationPeriodAmount.Item = calculation; return(stream); }
/// <summary> /// Initializes a new instance of the <see cref="PriceableInterestRateStream"/> class. /// </summary> /// <param name="logger">The logger.</param> /// <param name="cache">The cache.</param> /// <param name="nameSpace">THe nameSpace</param> /// <param name="swapId">The swap Id.</param> /// <param name="payerPartyReference">The payer party reference.</param> /// <param name="receiverPartyReference">The receiver party reference.</param> /// <param name="payerIsBase">The flag for whether the payerreference is the base party.</param> /// <param name="calculationPeriodDates">The caluclation period date information.</param> /// <param name="paymentDates">The payment dates of the swap leg.</param> /// <param name="resetDates">The reset dates of the swap leg.</param> /// <param name="principalExchanges">The principal Exchange type.</param> /// <param name="calculationPeriodAmount">The calculation period amount data.</param> /// <param name="stubCalculationPeriodAmount">The stub calculation information.</param> /// <param name="cashflows">The FpML cashflows for that stream.</param> /// <param name="settlementProvision">The settlement provision data.</param> /// <param name="fixingCalendar">The fixingCalendar.</param> /// <param name="paymentCalendar">The paymentCalendar.</param> public PriceableInterestRateStream ( ILogger logger , ICoreCache cache , String nameSpace , string swapId , string payerPartyReference , string receiverPartyReference , bool payerIsBase , CalculationPeriodDates calculationPeriodDates , PaymentDates paymentDates , ResetDates resetDates , PrincipalExchanges principalExchanges , CalculationPeriodAmount calculationPeriodAmount , StubCalculationPeriodAmount stubCalculationPeriodAmount , Cashflows cashflows , SettlementProvision settlementProvision , IBusinessCalendar fixingCalendar , IBusinessCalendar paymentCalendar) : this(logger, cache, nameSpace, swapId, payerPartyReference, receiverPartyReference, payerIsBase, calculationPeriodDates, paymentDates, resetDates, principalExchanges, calculationPeriodAmount, stubCalculationPeriodAmount, cashflows, settlementProvision, true, fixingCalendar, paymentCalendar) { }
public void CalculateFuturePaymentDate_InputCausesSaturdayOrSundayDate_DateReturned30DaysInFuture() { //arrange phase var pd = new PaymentDates(); DateTime sampleDate = DateTime.Parse("30/4/2020"); //act phase DateTime resultDateWhichShouldBe30DayLater = pd.CalculateFuturePaymentDate(sampleDate); DayOfWeek date = sampleDate.AddDays(30).DayOfWeek; int addDay = 0; if (date.Equals(DayOfWeek.Saturday)) { addDay += 2; } else if (date.Equals(DayOfWeek.Sunday)) { addDay++; } //assert phase Assert.AreEqual(sampleDate.AddDays(30 + addDay), resultDateWhichShouldBe30DayLater); }
/// <summary> /// Initializes a new instance of the <see cref="PriceableInterestRateStream"/> class. /// </summary> /// <param name="logger">The logger.</param> /// <param name="cache">The cache.</param> /// <param name="nameSpace">The client namesspace.</param> /// <param name="swapId">The swap Id.</param> /// <param name="payerPartyReference">The payer party reference.</param> /// <param name="receiverPartyReference">The receiver party reference.</param> /// <param name="payerIsBase">The flag for whether the payerreference is the base party.</param> /// <param name="calculationPeriodDates">The caluclation period date information.</param> /// <param name="paymentDates">The payment dates of the swap leg.</param> /// <param name="resetDates">The reset dates of the swap leg.</param> /// <param name="principalExchanges">The principal Exchange type.</param> /// <param name="calculationPeriodAmount">The calculation period amount data.</param> /// <param name="stubCalculationPeriodAmount">The stub calculation information.</param> /// <param name="cashflows">The FpML cashflows for that stream.</param> /// <param name="settlementProvision">The settlement provision data.</param> /// <param name="forecastRateInterpolation">ForwardEndDate = forecastRateInterpolation ? AccrualEndDate /// : AdjustedDateHelper.ToAdjustedDate(forecastRateIndex.indexTenor.Add(AccrualStartDate), AccrualBusinessDayAdjustments);</param> /// <param name="fixingCalendar">The fixingCalendar.</param> /// <param name="paymentCalendar">The paymentCalendar.</param> public PriceableInterestRateStream ( ILogger logger , ICoreCache cache , String nameSpace , string swapId , string payerPartyReference , string receiverPartyReference , bool payerIsBase , CalculationPeriodDates calculationPeriodDates , PaymentDates paymentDates , ResetDates resetDates , PrincipalExchanges principalExchanges , CalculationPeriodAmount calculationPeriodAmount , StubCalculationPeriodAmount stubCalculationPeriodAmount , Cashflows cashflows , SettlementProvision settlementProvision , bool forecastRateInterpolation , IBusinessCalendar fixingCalendar , IBusinessCalendar paymentCalendar) { Multiplier = 1.0m; Payer = payerPartyReference; Receiver = receiverPartyReference; PayerIsBaseParty = payerIsBase; CalculationPeriodDates = calculationPeriodDates; PaymentDates = paymentDates; PaymentCurrencies = new List <string>(); ResetDates = resetDates; PrincipalExchanges = principalExchanges; CalculationPeriodAmount = calculationPeriodAmount; AnalyticsModel = new StructuredStreamAnalytic(); Calculation = (Calculation)CalculationPeriodAmount.Item; if (Calculation.Items?[0] is Schedule strikeSchedule) { Strike = strikeSchedule.initialValue;//Only picks up the first fixed rate for the swaption calculation. } StubCalculationPeriodAmount = stubCalculationPeriodAmount; Cashflows = cashflows; CouponStreamType = CouponTypeFromCalculation(Calculation); Id = BuildId(swapId, CouponStreamType); ForecastRateInterpolation = forecastRateInterpolation; var isThereDiscounting = XsdClassesFieldResolver.CalculationHasDiscounting(Calculation); if (isThereDiscounting) { IsDiscounted = true; //TODO need to include rate logic for the correct solved answers. What about reset cashflows?? } //Get the currency. var currency = XsdClassesFieldResolver.CalculationGetNotionalSchedule(Calculation); Currency = currency.notionalStepSchedule.currency; if (!PaymentCurrencies.Contains(Currency.Value)) { PaymentCurrencies.Add(Currency.Value); } //The calendars if (paymentCalendar == null) { paymentCalendar = BusinessCenterHelper.ToBusinessCalendar(cache, PaymentDates.paymentDatesAdjustments.businessCenters, nameSpace); } SettlementProvision = settlementProvision; //Set the default discount curve name. DiscountCurveName = CurveNameHelpers.GetDiscountCurveName(Currency.Value, true); //Set the forecast curve name.//TODO extend this to the other types. if (CouponStreamType != CouponStreamType.GenericFixedRate) { if (fixingCalendar == null) { fixingCalendar = BusinessCenterHelper.ToBusinessCalendar(cache, ResetDates.resetDatesAdjustments.businessCenters, nameSpace); } ForecastCurveName = null; if (Calculation.Items != null) { var floatingRateCalculation = Calculation.Items; var floatingRateIndex = (FloatingRateCalculation)floatingRateCalculation[0]; ForecastCurveName = CurveNameHelpers.GetForecastCurveName(floatingRateIndex); } } //Build the coupons and principal exchanges. if (GetCashflowPaymentCalculationPeriods() != null) { Coupons = PriceableInstrumentsFactory.CreatePriceableCoupons(PayerIsBaseParty, GetCashflowPaymentCalculationPeriods(), Calculation, ForecastRateInterpolation, fixingCalendar, paymentCalendar);//TODO add the stubcalculation. UpdateCouponIds(); } if (GetCashflowPrincipalExchanges() != null) { var exchanges = GetCashflowPrincipalExchanges(); Exchanges = PriceableInstrumentsFactory.CreatePriceablePrincipalExchanges(PayerIsBaseParty, exchanges, Currency.Value, paymentCalendar); UpdateExchangeIds(); } RiskMaturityDate = LastDate(); logger.LogInfo("Stream built"); }
public static List <PaymentCalculationPeriod> GetPaymentCalculationPeriods(InterestRateStream interestRateStream, CalculationPeriodsPrincipalExchangesAndStubs listCalculationPeriods, IBusinessCalendar paymentCalendar) { var result = new List <PaymentCalculationPeriod>(); // Calculate how much calculation periods comprise one payment calculation period // PaymentDates paymentDates = interestRateStream.paymentDates; Period paymentFrequency = IntervalHelper.FromFrequency(paymentDates.paymentFrequency); Period calculationPeriodFrequency = IntervalHelper.FromFrequency(interestRateStream.calculationPeriodDates.calculationPeriodFrequency); // If the payment frequency is less frequent than the frequency defined in the calculation period dates component //then more than one calculation period will contribute to e payment amount. // A payment frequency more frequent than the calculation period frequency //or one that is not a multiple of the calculation period frequency is invalid. if (paymentFrequency.period != calculationPeriodFrequency.period) { throw new NotSupportedException( $"Payment period type ({paymentFrequency.period}) and calculation period type ({calculationPeriodFrequency.period}) are different. This is not supported."); } if (0 != int.Parse(paymentFrequency.periodMultiplier) % int.Parse(calculationPeriodFrequency.periodMultiplier)) { throw new NotSupportedException(String.Format("Payment period frequency is not a multiple of the calculation period frequency. This is not supported.")); } if (int.Parse(paymentFrequency.periodMultiplier) < int.Parse(calculationPeriodFrequency.periodMultiplier)) { throw new NotSupportedException(String.Format("A payment frequency more frequent than the calculation period frequency. This is not supported.")); } int calculationPeriodsInPaymentPeriod = int.Parse(paymentFrequency.periodMultiplier) / int.Parse(calculationPeriodFrequency.periodMultiplier); IEnumerable <List <CalculationPeriod> > listOfCalculationPeriodsInSinglePayPeriod = SplitCalculationPeriodsByPaymentPeriods(listCalculationPeriods, calculationPeriodsInPaymentPeriod); Offset paymentDaysOffset = paymentDates.paymentDaysOffset; BusinessDayAdjustments paymentDatesBusinessDayAdjustments = paymentDates.paymentDatesAdjustments; PayRelativeToEnum payRelativeTo = paymentDates.payRelativeTo; //if (paymentCalendar == null) //{ // paymentCalendar = BusinessCenterHelper.ToBusinessCalendar(cache, paymentDatesBusinessDayAdjustments.businessCenters); //} // Initial stub // if (listCalculationPeriods.HasInitialStub) { var paymentCalculationPeriod = new PaymentCalculationPeriod { adjustedPaymentDate = CalculatePaymentDate(paymentDates, payRelativeTo, new List <CalculationPeriod>( new[] { listCalculationPeriods. InitialStubCalculationPeriod }), paymentDaysOffset, paymentDatesBusinessDayAdjustments, paymentCalendar), adjustedPaymentDateSpecified = true }; XsdClassesFieldResolver.SetPaymentCalculationPeriodCalculationPeriodArray(paymentCalculationPeriod, new[] { listCalculationPeriods.InitialStubCalculationPeriod }); result.Add(paymentCalculationPeriod); } // Regular periods // foreach (List <CalculationPeriod> calculationPeriodsInPamentPeriod in listOfCalculationPeriodsInSinglePayPeriod) { var paymentCalculationPeriod = new PaymentCalculationPeriod { adjustedPaymentDate = CalculatePaymentDate(paymentDates, payRelativeTo, calculationPeriodsInPamentPeriod, paymentDaysOffset, paymentDatesBusinessDayAdjustments, paymentCalendar), adjustedPaymentDateSpecified = true }; XsdClassesFieldResolver.SetPaymentCalculationPeriodCalculationPeriodArray(paymentCalculationPeriod, calculationPeriodsInPamentPeriod.ToArray()); result.Add(paymentCalculationPeriod); } // Final stub // if (listCalculationPeriods.HasFinalStub) { var paymentCalculationPeriod = new PaymentCalculationPeriod { adjustedPaymentDate = CalculatePaymentDate(paymentDates, payRelativeTo, new List <CalculationPeriod>( new[] { listCalculationPeriods. FinalStubCalculationPeriod }), paymentDaysOffset, paymentDatesBusinessDayAdjustments, paymentCalendar), adjustedPaymentDateSpecified = true }; XsdClassesFieldResolver.SetPaymentCalculationPeriodCalculationPeriodArray(paymentCalculationPeriod, new[] { listCalculationPeriods.FinalStubCalculationPeriod }); result.Add(paymentCalculationPeriod); } return(result); }
public void CalculateFuturePaymentDate_ValidInput_DateReturned30DaysInFuture() { var pmDate = new PaymentDates(); }