//------------------------------------------------------------------------- //JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @ImmutablePreBuild private static void preBuild(Builder builder) private static void preBuild(Builder builder) { if (builder.fixingDateOffset_Renamed == null && builder.fixingCalendar_Renamed != null && builder.maturityDateOffset_Renamed != null) { int days = builder.maturityDateOffset_Renamed.Days; HolidayCalendarId maturityCal = builder.maturityDateOffset_Renamed.Calendar; if (maturityCal.combinedWith(builder.fixingCalendar_Renamed).Equals(maturityCal)) { builder.fixingDateOffset_Renamed = DaysAdjustment.ofBusinessDays(-days, maturityCal); } else { builder.fixingDateOffset_Renamed = DaysAdjustment.ofBusinessDays(-days, maturityCal, BusinessDayAdjustment.of(BusinessDayConventions.PRECEDING, builder.fixingCalendar_Renamed)); } } }
static CalibrationZeroRateUsd3OisIrsBsTest() { DSC_NAMES[DSCON_CURVE_NAME] = USD; ISet <Index> usdFedFundSet = new HashSet <Index>(); usdFedFundSet.Add(USD_FED_FUND); IDX_NAMES[DSCON_CURVE_NAME] = usdFedFundSet; ISet <Index> usdLibor3Set = new HashSet <Index>(); usdLibor3Set.Add(USD_LIBOR_3M); IDX_NAMES[FWD3_CURVE_NAME] = usdLibor3Set; ISet <Index> usdLibor6Set = new HashSet <Index>(); usdLibor6Set.Add(USD_LIBOR_6M); IDX_NAMES[FWD6_CURVE_NAME] = usdLibor6Set; for (int i = 0; i < DSC_NB_DEPO_NODES; i++) { BusinessDayAdjustment bda = BusinessDayAdjustment.of(FOLLOWING, USNY); TermDepositConvention convention = ImmutableTermDepositConvention.of("USD-Dep", USD, bda, ACT_360, DaysAdjustment.ofBusinessDays(DSC_DEPO_OFFSET[i], USNY)); DSC_NODES[i] = TermDepositCurveNode.of(TermDepositTemplate.of(Period.ofDays(1), convention), QuoteId.of(StandardId.of(SCHEME, DSC_ID_VALUE[i]))); } for (int i = 0; i < DSC_NB_OIS_NODES; i++) { DSC_NODES[DSC_NB_DEPO_NODES + i] = FixedOvernightSwapCurveNode.of(FixedOvernightSwapTemplate.of(Period.ZERO, Tenor.of(DSC_OIS_TENORS[i]), USD_FIXED_1Y_FED_FUND_OIS), QuoteId.of(StandardId.of(SCHEME, DSC_ID_VALUE[DSC_NB_DEPO_NODES + i]))); } FWD3_NODES[0] = IborFixingDepositCurveNode.of(IborFixingDepositTemplate.of(USD_LIBOR_3M), QuoteId.of(StandardId.of(SCHEME, FWD3_ID_VALUE[0]))); for (int i = 0; i < FWD3_NB_FRA_NODES; i++) { FWD3_NODES[i + 1] = FraCurveNode.of(FraTemplate.of(FWD3_FRA_TENORS[i], USD_LIBOR_3M), QuoteId.of(StandardId.of(SCHEME, FWD3_ID_VALUE[i + 1]))); } for (int i = 0; i < FWD3_NB_IRS_NODES; i++) { FWD3_NODES[i + 1 + FWD3_NB_FRA_NODES] = FixedIborSwapCurveNode.of(FixedIborSwapTemplate.of(Period.ZERO, Tenor.of(FWD3_IRS_TENORS[i]), USD_FIXED_6M_LIBOR_3M), QuoteId.of(StandardId.of(SCHEME, FWD3_ID_VALUE[i + 1 + FWD3_NB_FRA_NODES]))); } FWD6_NODES[0] = IborFixingDepositCurveNode.of(IborFixingDepositTemplate.of(USD_LIBOR_6M), QuoteId.of(StandardId.of(SCHEME, FWD6_ID_VALUE[0]))); for (int i = 0; i < FWD6_NB_FRA_NODES; i++) { FWD6_NODES[i + 1] = FraCurveNode.of(FraTemplate.of(FWD6_FRA_TENORS[i], USD_LIBOR_6M), QuoteId.of(StandardId.of(SCHEME, FWD6_ID_VALUE[i + 1]))); } for (int i = 0; i < FWD6_NB_IRS_NODES; i++) { FWD6_NODES[i + 1 + FWD6_NB_FRA_NODES] = IborIborSwapCurveNode.of(IborIborSwapTemplate.of(Period.ZERO, Tenor.of(FWD6_IRS_TENORS[i]), USD_LIBOR_3M_LIBOR_6M), QuoteId.of(StandardId.of(SCHEME, FWD6_ID_VALUE[i + 1 + FWD6_NB_FRA_NODES]))); } ImmutableMarketDataBuilder builder = ImmutableMarketData.builder(VAL_DATE); for (int i = 0; i < DSC_NB_NODES; i++) { builder.addValue(QuoteId.of(StandardId.of(SCHEME, DSC_ID_VALUE[i])), DSC_MARKET_QUOTES[i]); } for (int i = 0; i < FWD3_NB_NODES; i++) { builder.addValue(QuoteId.of(StandardId.of(SCHEME, FWD3_ID_VALUE[i])), FWD3_MARKET_QUOTES[i]); } for (int i = 0; i < FWD6_NB_NODES; i++) { builder.addValue(QuoteId.of(StandardId.of(SCHEME, FWD6_ID_VALUE[i])), FWD6_MARKET_QUOTES[i]); } ALL_QUOTES = builder.build(); IList <CurveNode[]> groupDsc = new List <CurveNode[]>(); groupDsc.Add(DSC_NODES); CURVES_NODES.Add(groupDsc); IList <CurveNode[]> groupFwd3 = new List <CurveNode[]>(); groupFwd3.Add(FWD3_NODES); CURVES_NODES.Add(groupFwd3); IList <CurveNode[]> groupFwd6 = new List <CurveNode[]>(); groupFwd6.Add(FWD6_NODES); CURVES_NODES.Add(groupFwd6); IList <CurveMetadata> groupDsc = new List <CurveMetadata>(); groupDsc.Add(DefaultCurveMetadata.builder().curveName(DSCON_CURVE_NAME).xValueType(ValueType.YEAR_FRACTION).yValueType(ValueType.ZERO_RATE).dayCount(CURVE_DC).build()); CURVES_METADATA.Add(groupDsc); IList <CurveMetadata> groupFwd3 = new List <CurveMetadata>(); groupFwd3.Add(DefaultCurveMetadata.builder().curveName(FWD3_CURVE_NAME).xValueType(ValueType.YEAR_FRACTION).yValueType(ValueType.ZERO_RATE).dayCount(CURVE_DC).build()); CURVES_METADATA.Add(groupFwd3); IList <CurveMetadata> groupFwd6 = new List <CurveMetadata>(); groupFwd6.Add(DefaultCurveMetadata.builder().curveName(FWD6_CURVE_NAME).xValueType(ValueType.YEAR_FRACTION).yValueType(ValueType.ZERO_RATE).dayCount(CURVE_DC).build()); CURVES_METADATA.Add(groupFwd6); }
//----------------------------------------------------------------------- // XCcy swap with exchange of notional public virtual void test_XCcyEur3MSpreadVsUSD3M() { SwapLeg payLeg = RateCalculationSwapLeg.builder().payReceive(PAY).accrualSchedule(PeriodicSchedule.builder().startDate(LocalDate.of(2014, 1, 24)).endDate(LocalDate.of(2016, 1, 24)).frequency(P3M).businessDayAdjustment(BDA_MF).build()).paymentSchedule(PaymentSchedule.builder().paymentFrequency(P3M).paymentDateOffset(DaysAdjustment.NONE).build()).notionalSchedule(NotionalSchedule.builder().finalExchange(true).initialExchange(true).amount(ValueSchedule.of(NOTIONAL_EUR)).currency(EUR).build()).calculation(IborRateCalculation.builder().index(EUR_EURIBOR_3M).fixingDateOffset(DaysAdjustment.ofBusinessDays(-2, CalendarUSD.NYC, BDA_P)).spread(ValueSchedule.of(0.0020)).build()).build(); SwapLeg receiveLeg = RateCalculationSwapLeg.builder().payReceive(RECEIVE).accrualSchedule(PeriodicSchedule.builder().startDate(LocalDate.of(2014, 1, 24)).endDate(LocalDate.of(2016, 1, 24)).frequency(P3M).businessDayAdjustment(BDA_MF).build()).paymentSchedule(PaymentSchedule.builder().paymentFrequency(P3M).paymentDateOffset(DaysAdjustment.NONE).build()).notionalSchedule(NotionalSchedule.builder().finalExchange(true).initialExchange(true).amount(ValueSchedule.of(NOTIONAL_USD)).currency(USD).build()).calculation(IborRateCalculation.builder().index(USD_LIBOR_3M).fixingDateOffset(DaysAdjustment.ofBusinessDays(-2, CalendarUSD.NYC, BDA_P)).build()).build(); ResolvedSwapTrade trade = SwapTrade.builder().info(TradeInfo.builder().tradeDate(LocalDate.of(2014, 9, 10)).build()).product(Swap.of(payLeg, receiveLeg)).build().resolve(REF_DATA); double pvUsdExpected = 431944.6868; double pvEurExpected = -731021.1778; DiscountingSwapTradePricer pricer = swapPricer(); MultiCurrencyAmount pv = pricer.presentValue(trade, provider()); assertEquals(pv.getAmount(USD).Amount, pvUsdExpected, TOLERANCE_PV); assertEquals(pv.getAmount(EUR).Amount, pvEurExpected, TOLERANCE_PV); }
private SwapTrade getMtmTrade(bool initialExchange, bool intermediateExchange, bool finalExchange, double?initialNotional) { SwapLeg payLeg = RateCalculationSwapLeg.builder().payReceive(PAY).accrualSchedule(PeriodicSchedule.builder().startDate(LocalDate.of(2014, 1, 24)).endDate(LocalDate.of(2016, 1, 24)).frequency(P3M).businessDayAdjustment(BDA_MF).build()).paymentSchedule(PaymentSchedule.builder().paymentFrequency(P3M).paymentDateOffset(DaysAdjustment.NONE).build()).notionalSchedule(NotionalSchedule.builder().finalExchange(finalExchange).initialExchange(initialExchange).amount(ValueSchedule.of(NOTIONAL_EUR)).currency(EUR).build()).calculation(IborRateCalculation.builder().index(EUR_EURIBOR_3M).fixingDateOffset(DaysAdjustment.ofBusinessDays(-2, CalendarUSD.NYC, BDA_P)).spread(ValueSchedule.of(0.0020)).build()).build(); SwapLeg receiveLeg = RateCalculationSwapLeg.builder().payReceive(RECEIVE).accrualSchedule(PeriodicSchedule.builder().startDate(LocalDate.of(2014, 1, 24)).endDate(LocalDate.of(2016, 1, 24)).frequency(P3M).businessDayAdjustment(BDA_MF).build()).paymentSchedule(PaymentSchedule.builder().paymentFrequency(P3M).paymentDateOffset(DaysAdjustment.NONE).build()).notionalSchedule(NotionalSchedule.builder().finalExchange(finalExchange).initialExchange(initialExchange).intermediateExchange(intermediateExchange).amount(ValueSchedule.of(NOTIONAL_USD)).currency(USD).fxReset(FxResetCalculation.builder().fixingDateOffset(DaysAdjustment.ofBusinessDays(-2, CalendarUSD.NYC, BDA_P)).referenceCurrency(EUR).index(EUR_USD_WM).initialNotionalValue(initialNotional).build()).build()).calculation(IborRateCalculation.builder().index(USD_LIBOR_3M).fixingDateOffset(DaysAdjustment.ofBusinessDays(-2, CalendarUSD.NYC, BDA_P)).build()).build(); return(SwapTrade.builder().info(TradeInfo.builder().tradeDate(LocalDate.of(2014, 9, 10)).build()).product(Swap.of(payLeg, receiveLeg)).build()); }
internal static CapitalIndexedBond sut2() { return(CapitalIndexedBond.builder().securityId(SECURITY_ID2).notional(5.0e7).currency(GBP).dayCount(NL_365).rateCalculation(InflationRateCalculation.builder().index(GB_RPI).lag(Period.ofMonths(2)).indexCalculationMethod(INTERPOLATED).firstIndexValue(124.556).build()).exCouponPeriod(EX_COUPON).legalEntityId(LegalEntityId.of("OG-Ticker", "US-Govt-1")).yieldConvention(GB_IL_FLOAT).settlementDateOffset(DaysAdjustment.ofBusinessDays(2, GBLO)).accrualSchedule(PeriodicSchedule.of(START, END, FREQUENCY, BusinessDayAdjustment.of(BusinessDayConventions.FOLLOWING, GBLO), StubConvention.NONE, RollConventions.NONE)).build()); }
//----------------------------------------------------------------------- public virtual void floatingSwapLeg() { // a PeriodicSchedule generates a schedule of accrual periods // - interest is accrued every 6 months from 2014-02-12 to 2014-07-31 // - accrual period dates are adjusted "modified following" using the "GBLO" holiday calendar // - there will be a long initial stub // - the regular accrual period dates will be at the end-of-month PeriodicSchedule accrualSchedule = PeriodicSchedule.builder().startDate(LocalDate.of(2014, 2, 12)).endDate(LocalDate.of(2016, 7, 31)).businessDayAdjustment(BusinessDayAdjustment.of(MODIFIED_FOLLOWING, HolidayCalendarIds.GBLO)).frequency(Frequency.P6M).stubConvention(StubConvention.LONG_INITIAL).rollConvention(RollConventions.EOM).build(); // a PaymentSchedule generates a schedule of payment periods, based on the accrual schedule // - payments are every 6 months // - payments are 2 business days after the end of the period // - no compounding is needed as the payment schedule matches the accrual schedule PaymentSchedule paymentSchedule = PaymentSchedule.builder().paymentFrequency(Frequency.P6M).paymentRelativeTo(PaymentRelativeTo.PERIOD_END).paymentDateOffset(DaysAdjustment.ofBusinessDays(2, HolidayCalendarIds.GBLO)).build(); // a NotionalSchedule generates a schedule of notional amounts, based on the payment schedule // - in this simple case the notional is 1 million GBP and does not change NotionalSchedule notionalSchedule = NotionalSchedule.of(Currency.GBP, 1_000_000); // a RateCalculationSwapLeg can represent a fixed or floating swap leg // - an IborRateCalculation is used to represent a floating Ibor rate // - the "Act/Act ISDA" day count is used // - the index is GBP LIBOR 6M // - fixing is 2 days before the start of the period using the "GBLO" holiday calendar RateCalculationSwapLeg swapLeg = RateCalculationSwapLeg.builder().payReceive(PayReceive.RECEIVE).accrualSchedule(accrualSchedule).paymentSchedule(paymentSchedule).notionalSchedule(notionalSchedule).calculation(IborRateCalculation.builder().dayCount(DayCounts.ACT_ACT_ISDA).index(IborIndices.GBP_LIBOR_6M).fixingRelativeTo(FixingRelativeTo.PERIOD_START).fixingDateOffset(DaysAdjustment.ofBusinessDays(-2, HolidayCalendarIds.GBLO)).build()).build(); // a ResolvedSwapLeg has all the dates of the cash flows // it remains valid so long as the holiday calendar does not change ResolvedSwapLeg resolvedLeg = swapLeg.resolve(ReferenceData.standard()); Console.WriteLine("===== Floating ====="); Console.WriteLine(JodaBeanSer.PRETTY.xmlWriter().write(swapLeg)); Console.WriteLine(); Console.WriteLine("===== Floating resolved ====="); Console.WriteLine(JodaBeanSer.PRETTY.xmlWriter().write(resolvedLeg)); Console.WriteLine(); }
public virtual void test_resolve_unadjustedAccrualAdjustedPayment() { Swap test = Swap.builder().legs(RateCalculationSwapLeg.builder().payReceive(RECEIVE).accrualSchedule(PeriodicSchedule.builder().startDate(date(2016, 1, 3)).endDate(date(2016, 5, 3)).frequency(Frequency.P1M).businessDayAdjustment(BusinessDayAdjustment.NONE).build()).paymentSchedule(PaymentSchedule.builder().paymentFrequency(Frequency.P1M).businessDayAdjustment(BusinessDayAdjustment.of(FOLLOWING, SAT_SUN)).paymentDateOffset(DaysAdjustment.ofBusinessDays(2, SAT_SUN)).build()).notionalSchedule(NotionalSchedule.of(GBP, NOTIONAL)).calculation(FixedRateCalculation.of(RATE, ACT_360)).build()).build(); RatePaymentPeriod pp1 = RatePaymentPeriod.builder().paymentDate(date(2016, 2, 5)).accrualPeriods(RateAccrualPeriod.builder().startDate(date(2016, 1, 3)).unadjustedStartDate(date(2016, 1, 3)).endDate(date(2016, 2, 3)).unadjustedEndDate(date(2016, 2, 3)).yearFraction(ACT_360.yearFraction(date(2016, 1, 3), date(2016, 2, 3))).rateComputation(FixedRateComputation.of(RATE)).build()).dayCount(ACT_360).currency(GBP).notional(NOTIONAL).build(); RatePaymentPeriod pp2 = RatePaymentPeriod.builder().paymentDate(date(2016, 3, 7)).accrualPeriods(RateAccrualPeriod.builder().startDate(date(2016, 2, 3)).unadjustedStartDate(date(2016, 2, 3)).endDate(date(2016, 3, 3)).unadjustedEndDate(date(2016, 3, 3)).yearFraction(ACT_360.yearFraction(date(2016, 2, 3), date(2016, 3, 3))).rateComputation(FixedRateComputation.of(RATE)).build()).dayCount(ACT_360).currency(GBP).notional(NOTIONAL).build(); RatePaymentPeriod pp3 = RatePaymentPeriod.builder().paymentDate(date(2016, 4, 6)).accrualPeriods(RateAccrualPeriod.builder().startDate(date(2016, 3, 3)).unadjustedStartDate(date(2016, 3, 3)).endDate(date(2016, 4, 3)).unadjustedEndDate(date(2016, 4, 3)).yearFraction(ACT_360.yearFraction(date(2016, 3, 3), date(2016, 4, 3))).rateComputation(FixedRateComputation.of(RATE)).build()).dayCount(ACT_360).currency(GBP).notional(NOTIONAL).build(); RatePaymentPeriod pp4 = RatePaymentPeriod.builder().paymentDate(date(2016, 5, 5)).accrualPeriods(RateAccrualPeriod.builder().startDate(date(2016, 4, 3)).unadjustedStartDate(date(2016, 4, 3)).endDate(date(2016, 5, 3)).unadjustedEndDate(date(2016, 5, 3)).yearFraction(ACT_360.yearFraction(date(2016, 4, 3), date(2016, 5, 3))).rateComputation(FixedRateComputation.of(RATE)).build()).dayCount(ACT_360).currency(GBP).notional(NOTIONAL).build(); ResolvedSwap expected = ResolvedSwap.builder().legs(ResolvedSwapLeg.builder().paymentPeriods(pp1, pp2, pp3, pp4).payReceive(RECEIVE).type(FIXED).build()).build(); assertEqualsBean(test.resolve(REF_DATA), expected); }
static CalibrationInflationUsdTest() { DSC_NAMES[DSCON_CURVE_NAME] = USD; ISet <Index> usdFedFundSet = new HashSet <Index>(); usdFedFundSet.Add(USD_FED_FUND); IDX_NAMES[DSCON_CURVE_NAME] = usdFedFundSet; ISet <Index> usdLibor3Set = new HashSet <Index>(); usdLibor3Set.Add(USD_LIBOR_3M); IDX_NAMES[CPI_CURVE_NAME] = usdLibor3Set; for (int i = 0; i < DSC_NB_DEPO_NODES; i++) { BusinessDayAdjustment bda = BusinessDayAdjustment.of(FOLLOWING, USNY); TermDepositConvention convention = ImmutableTermDepositConvention.of("USD-Dep", USD, bda, ACT_360, DaysAdjustment.ofBusinessDays(DSC_DEPO_OFFSET[i], USNY)); DSC_NODES[i] = TermDepositCurveNode.of(TermDepositTemplate.of(Period.ofDays(1), convention), QuoteId.of(StandardId.of(SCHEME, DSC_ID_VALUE[i]))); } for (int i = 0; i < DSC_NB_OIS_NODES; i++) { DSC_NODES[DSC_NB_DEPO_NODES + i] = FixedOvernightSwapCurveNode.of(FixedOvernightSwapTemplate.of(Period.ZERO, Tenor.of(DSC_OIS_TENORS[i]), USD_FIXED_1Y_FED_FUND_OIS), QuoteId.of(StandardId.of(SCHEME, DSC_ID_VALUE[DSC_NB_DEPO_NODES + i]))); } for (int i = 0; i < CPI_NB_NODES; i++) { CPI_NODES[i] = FixedInflationSwapCurveNode.builder().template(FixedInflationSwapTemplate.of(Tenor.of(CPI_TENORS[i]), FixedInflationSwapConventions.USD_FIXED_ZC_US_CPI)).rateId(QuoteId.of(StandardId.of(SCHEME, CPI_ID_VALUE[i]))).date(CurveNodeDate.LAST_FIXING).build(); } ImmutableMarketDataBuilder builder = ImmutableMarketData.builder(VAL_DATE); for (int i = 0; i < DSC_NB_NODES; i++) { builder.addValue(QuoteId.of(StandardId.of(SCHEME, DSC_ID_VALUE[i])), DSC_MARKET_QUOTES[i]); } for (int i = 0; i < CPI_NB_NODES; i++) { builder.addValue(QuoteId.of(StandardId.of(SCHEME, CPI_ID_VALUE[i])), CPI_MARKET_QUOTES[i]); } builder.addTimeSeries(IndexQuoteId.of(US_CPI_U), TS_USD_CPI); ALL_QUOTES = builder.build(); IList <CurveNode[]> groupDsc = new List <CurveNode[]>(); groupDsc.Add(DSC_NODES); CURVES_NODES.Add(groupDsc); IList <CurveNode[]> groupCpi = new List <CurveNode[]>(); groupCpi.Add(CPI_NODES); CURVES_NODES.Add(groupCpi); }
//------------------------------------------------------------------------- public virtual void test_CompoundingOisFixed2mVsFedFund12mSwapWithFixing() { SwapLeg payLeg = RateCalculationSwapLeg.builder().payReceive(PAY).accrualSchedule(PeriodicSchedule.builder().startDate(LocalDate.of(2014, 1, 17)).endDate(LocalDate.of(2014, 3, 17)).frequency(TERM).businessDayAdjustment(BDA_MF).build()).paymentSchedule(PaymentSchedule.builder().paymentFrequency(TERM).paymentDateOffset(DaysAdjustment.ofBusinessDays(2, CalendarUSD.NYC)).build()).notionalSchedule(NOTIONAL).calculation(FixedRateCalculation.builder().dayCount(ACT_360).rate(ValueSchedule.of(0.00123)).build()).build(); SwapLeg receiveLeg = RateCalculationSwapLeg.builder().payReceive(RECEIVE).accrualSchedule(PeriodicSchedule.builder().startDate(LocalDate.of(2014, 1, 17)).endDate(LocalDate.of(2014, 3, 17)).frequency(TERM).businessDayAdjustment(BDA_MF).stubConvention(StubConvention.SHORT_INITIAL).build()).paymentSchedule(PaymentSchedule.builder().paymentFrequency(TERM).paymentDateOffset(DaysAdjustment.ofBusinessDays(2, CalendarUSD.NYC)).build()).notionalSchedule(NOTIONAL).calculation(OvernightRateCalculation.builder().dayCount(ACT_360).index(USD_FED_FUND).build()).build(); ResolvedSwapTrade trade = SwapTrade.builder().info(TradeInfo.builder().tradeDate(LocalDate.of(2014, 1, 15)).build()).product(Swap.of(payLeg, receiveLeg)).build().resolve(REF_DATA); DiscountingSwapTradePricer pricer = swapPricer(); CurrencyAmount pv = pricer.presentValue(trade, provider()).getAmount(USD); assertEquals(pv.Amount, -7352.973875972721, TOLERANCE_PV); }
//------------------------------------------------------------------------- public virtual void test_AmortizingFixedVsLibor3mSwap() { ValueAdjustment stepReduction = ValueAdjustment.ofDeltaAmount(-3_000_000); IList <ValueStep> steps = new List <ValueStep>(); for (int i = 1; i < 28; i++) { steps.Add(ValueStep.of(i, stepReduction)); } ValueSchedule notionalSchedule = ValueSchedule.of(100_000_000, steps); SwapLeg receiveLeg = RateCalculationSwapLeg.builder().payReceive(RECEIVE).accrualSchedule(PeriodicSchedule.builder().startDate(LocalDate.of(2014, 9, 12)).endDate(LocalDate.of(2021, 9, 12)).frequency(P3M).businessDayAdjustment(BDA_MF).build()).paymentSchedule(PaymentSchedule.builder().paymentFrequency(P3M).paymentDateOffset(DaysAdjustment.NONE).build()).notionalSchedule(NotionalSchedule.of(USD, notionalSchedule)).calculation(FixedRateCalculation.builder().dayCount(THIRTY_U_360).rate(ValueSchedule.of(0.016)).build()).build(); SwapLeg payLeg = RateCalculationSwapLeg.builder().payReceive(PAY).accrualSchedule(PeriodicSchedule.builder().startDate(LocalDate.of(2014, 9, 12)).endDate(LocalDate.of(2021, 9, 12)).frequency(P3M).businessDayAdjustment(BDA_MF).stubConvention(StubConvention.SHORT_INITIAL).build()).paymentSchedule(PaymentSchedule.builder().paymentFrequency(P3M).paymentDateOffset(DaysAdjustment.NONE).build()).notionalSchedule(NotionalSchedule.of(USD, notionalSchedule)).calculation(IborRateCalculation.builder().index(USD_LIBOR_3M).fixingDateOffset(DaysAdjustment.ofBusinessDays(-2, CalendarUSD.NYC, BDA_P)).build()).build(); ResolvedSwapTrade trade = SwapTrade.builder().info(TradeInfo.builder().tradeDate(LocalDate.of(2014, 9, 10)).build()).product(Swap.of(receiveLeg, payLeg)).build().resolve(REF_DATA); DiscountingSwapTradePricer pricer = swapPricer(); CurrencyAmount pv = pricer.presentValue(trade, provider()).getAmount(USD); assertEquals(pv.Amount, -1850080.2895532502, TOLERANCE_PV); }
//------------------------------------------------------------------------- public virtual void test_ZeroCouponFixedVsLibor3mSwap() { SwapLeg payLeg = RateCalculationSwapLeg.builder().payReceive(PAY).accrualSchedule(PeriodicSchedule.builder().startDate(LocalDate.of(2014, 9, 12)).endDate(LocalDate.of(2021, 9, 12)).frequency(P12M).businessDayAdjustment(BDA_MF).build()).paymentSchedule(PaymentSchedule.builder().paymentFrequency(TERM).paymentDateOffset(DaysAdjustment.NONE).compoundingMethod(CompoundingMethod.STRAIGHT).build()).notionalSchedule(NOTIONAL).calculation(FixedRateCalculation.builder().dayCount(THIRTY_U_360).rate(ValueSchedule.of(0.015)).build()).build(); SwapLeg receiveLeg = RateCalculationSwapLeg.builder().payReceive(RECEIVE).accrualSchedule(PeriodicSchedule.builder().startDate(LocalDate.of(2014, 9, 12)).endDate(LocalDate.of(2021, 9, 12)).frequency(P3M).businessDayAdjustment(BDA_MF).stubConvention(StubConvention.SHORT_INITIAL).build()).paymentSchedule(PaymentSchedule.builder().paymentFrequency(TERM).paymentDateOffset(DaysAdjustment.NONE).compoundingMethod(CompoundingMethod.STRAIGHT).build()).notionalSchedule(NOTIONAL).calculation(IborRateCalculation.builder().index(USD_LIBOR_3M).fixingDateOffset(DaysAdjustment.ofBusinessDays(-2, CalendarUSD.NYC, BDA_P)).build()).build(); ResolvedSwapTrade trade = SwapTrade.builder().info(TradeInfo.builder().tradeDate(LocalDate.of(2014, 9, 10)).build()).product(Swap.of(payLeg, receiveLeg)).build().resolve(REF_DATA); DiscountingSwapTradePricer pricer = swapPricer(); CurrencyAmount pv = pricer.presentValue(trade, provider()).getAmount(USD); assertEquals(pv.Amount, 7850279.042216873, TOLERANCE_PV); }
//------------------------------------------------------------------------- public virtual void test_InterpolatedStub4mFixed6mVsLibor6mSwap() { SwapLeg receiveLeg = fixedLeg(LocalDate.of(2014, 9, 12), LocalDate.of(2016, 7, 12), P6M, RECEIVE, NOTIONAL, 0.01, StubConvention.SHORT_INITIAL); SwapLeg payLeg = RateCalculationSwapLeg.builder().payReceive(PAY).accrualSchedule(PeriodicSchedule.builder().startDate(LocalDate.of(2014, 9, 12)).endDate(LocalDate.of(2016, 7, 12)).frequency(P6M).businessDayAdjustment(BDA_MF).stubConvention(StubConvention.SHORT_INITIAL).build()).paymentSchedule(PaymentSchedule.builder().paymentFrequency(P6M).paymentDateOffset(DaysAdjustment.NONE).build()).notionalSchedule(NOTIONAL).calculation(IborRateCalculation.builder().index(USD_LIBOR_6M).fixingDateOffset(DaysAdjustment.ofBusinessDays(-2, CalendarUSD.NYC, BDA_P)).initialStub(IborRateStubCalculation.ofIborInterpolatedRate(USD_LIBOR_3M, USD_LIBOR_6M)).build()).build(); ResolvedSwapTrade trade = SwapTrade.builder().info(TradeInfo.builder().tradeDate(LocalDate.of(2014, 9, 10)).build()).product(Swap.of(receiveLeg, payLeg)).build().resolve(REF_DATA); DiscountingSwapTradePricer pricer = swapPricer(); CurrencyAmount pv = pricer.presentValue(trade, provider()).getAmount(USD); assertEquals(pv.Amount, 314215.2347116342, TOLERANCE_PV); }
//------------------------------------------------------------------------- public virtual void test_BasisCompoundedLibor1mVsLibor3mSwap() { SwapLeg receiveLeg = RateCalculationSwapLeg.builder().payReceive(RECEIVE).accrualSchedule(PeriodicSchedule.builder().startDate(LocalDate.of(2014, 8, 29)).endDate(LocalDate.of(2019, 8, 29)).frequency(P1M).businessDayAdjustment(BDA_MF).build()).paymentSchedule(PaymentSchedule.builder().paymentFrequency(Frequency.P3M).paymentDateOffset(DaysAdjustment.NONE).compoundingMethod(CompoundingMethod.FLAT).build()).notionalSchedule(NOTIONAL).calculation(IborRateCalculation.builder().index(USD_LIBOR_1M).fixingDateOffset(DaysAdjustment.ofBusinessDays(-2, CalendarUSD.NYC, BDA_P)).build()).build(); SwapLeg payLeg = RateCalculationSwapLeg.builder().payReceive(PAY).accrualSchedule(PeriodicSchedule.builder().startDate(LocalDate.of(2014, 8, 29)).endDate(LocalDate.of(2019, 8, 29)).frequency(P3M).businessDayAdjustment(BDA_MF).build()).paymentSchedule(PaymentSchedule.builder().paymentFrequency(Frequency.P3M).paymentDateOffset(DaysAdjustment.NONE).build()).notionalSchedule(NOTIONAL).calculation(IborRateCalculation.builder().index(USD_LIBOR_3M).fixingDateOffset(DaysAdjustment.ofBusinessDays(-2, CalendarUSD.NYC, BDA_P)).build()).build(); ResolvedSwapTrade trade = SwapTrade.builder().info(TradeInfo.builder().tradeDate(LocalDate.of(2014, 8, 27)).build()).product(Swap.of(receiveLeg, payLeg)).build().resolve(REF_DATA); DiscountingSwapTradePricer pricer = swapPricer(); CurrencyAmount pv = pricer.presentValue(trade, provider()).getAmount(USD); assertEquals(pv.Amount, -342874.98367929866, TOLERANCE_PV); }
//------------------------------------------------------------------------- public virtual void test_BasisLibor3mVsLibor6mSwapWithSpread() { SwapLeg payLeg = RateCalculationSwapLeg.builder().payReceive(PAY).accrualSchedule(PeriodicSchedule.builder().startDate(LocalDate.of(2014, 8, 29)).endDate(LocalDate.of(2024, 8, 29)).frequency(P6M).businessDayAdjustment(BDA_MF).build()).paymentSchedule(PaymentSchedule.builder().paymentFrequency(Frequency.P6M).paymentDateOffset(DaysAdjustment.NONE).build()).notionalSchedule(NOTIONAL).calculation(IborRateCalculation.builder().index(USD_LIBOR_6M).fixingDateOffset(DaysAdjustment.ofBusinessDays(-2, CalendarUSD.NYC, BDA_P)).build()).build(); SwapLeg receiveLeg = RateCalculationSwapLeg.builder().payReceive(RECEIVE).accrualSchedule(PeriodicSchedule.builder().startDate(LocalDate.of(2014, 8, 29)).endDate(LocalDate.of(2024, 8, 29)).frequency(P3M).businessDayAdjustment(BDA_MF).build()).paymentSchedule(PaymentSchedule.builder().paymentFrequency(Frequency.P3M).paymentDateOffset(DaysAdjustment.NONE).build()).notionalSchedule(NOTIONAL).calculation(IborRateCalculation.builder().index(USD_LIBOR_3M).fixingDateOffset(DaysAdjustment.ofBusinessDays(-2, CalendarUSD.NYC, BDA_P)).spread(ValueSchedule.of(0.0010)).build()).build(); ResolvedSwapTrade trade = SwapTrade.builder().info(TradeInfo.builder().tradeDate(LocalDate.of(2014, 8, 27)).build()).product(Swap.of(payLeg, receiveLeg)).build().resolve(REF_DATA); DiscountingSwapTradePricer pricer = swapPricer(); CurrencyAmount pv = pricer.presentValue(trade, provider()).getAmount(USD); assertEquals(pv.Amount, -21875.376339152455, TOLERANCE_PV); }
//------------------------------------------------------------------------- public virtual void test_VanillaFixedVsLibor3mSwapWithFixing() { SwapLeg payLeg = fixedLeg(LocalDate.of(2013, 9, 12), LocalDate.of(2020, 9, 12), P6M, PAY, NOTIONAL, 0.015, null); SwapLeg receiveLeg = RateCalculationSwapLeg.builder().payReceive(RECEIVE).accrualSchedule(PeriodicSchedule.builder().startDate(LocalDate.of(2013, 9, 12)).endDate(LocalDate.of(2020, 9, 12)).frequency(P3M).businessDayAdjustment(BDA_MF).build()).paymentSchedule(PaymentSchedule.builder().paymentFrequency(P3M).paymentDateOffset(DaysAdjustment.NONE).build()).notionalSchedule(NOTIONAL).calculation(IborRateCalculation.builder().index(USD_LIBOR_3M).fixingDateOffset(DaysAdjustment.ofBusinessDays(-2, CalendarUSD.NYC, BDA_P)).build()).build(); ResolvedSwapTrade trade = SwapTrade.builder().info(TradeInfo.builder().tradeDate(LocalDate.of(2013, 9, 10)).build()).product(Swap.of(payLeg, receiveLeg)).build().resolve(REF_DATA); DiscountingSwapTradePricer pricer = swapPricer(); CurrencyAmount pv = pricer.presentValue(trade, provider()).getAmount(USD); assertEquals(pv.Amount, 3588376.471608199, TOLERANCE_PV); }
private static Trade createTrade1() { NotionalSchedule notional = NotionalSchedule.of(Currency.USD, 12_000_000); PeriodicSchedule accrual = PeriodicSchedule.builder().startDate(LocalDate.of(2006, 2, 24)).endDate(LocalDate.of(2011, 2, 24)).frequency(Frequency.P3M).businessDayAdjustment(BusinessDayAdjustment.of(MODIFIED_FOLLOWING, HolidayCalendarIds.USNY)).build(); PaymentSchedule payment = PaymentSchedule.builder().paymentFrequency(Frequency.P3M).paymentDateOffset(DaysAdjustment.ofBusinessDays(2, HolidayCalendarIds.USNY)).build(); SwapLeg payLeg = RateCalculationSwapLeg.builder().payReceive(PayReceive.PAY).accrualSchedule(accrual).paymentSchedule(payment).notionalSchedule(notional).calculation(FixedRateCalculation.of(0.05004, DayCounts.ACT_360)).build(); SwapLeg receiveLeg = RateCalculationSwapLeg.builder().payReceive(PayReceive.RECEIVE).accrualSchedule(accrual).paymentSchedule(payment).notionalSchedule(notional).calculation(IborRateCalculation.of(IborIndices.USD_LIBOR_3M)).build(); return(SwapTrade.builder().product(Swap.builder().legs(payLeg, receiveLeg).build()).info(TradeInfo.builder().id(StandardId.of("mn", "14248")).counterparty(StandardId.of("mn", "Dealer A")).settlementDate(LocalDate.of(2006, 2, 24)).build()).build()); }
//------------------------------------------------------------------------- public virtual void presentValueVanillaFixedVsLibor1mSwap() { SwapLeg payLeg = fixedLeg(LocalDate.of(2014, 9, 12), LocalDate.of(2016, 9, 12), Frequency.P6M, PayReceive.PAY, NOTIONAL, 0.0125, null); SwapLeg receiveLeg = RateCalculationSwapLeg.builder().payReceive(RECEIVE).accrualSchedule(PeriodicSchedule.builder().startDate(LocalDate.of(2014, 9, 12)).endDate(LocalDate.of(2016, 9, 12)).frequency(Frequency.P1M).businessDayAdjustment(BDA_MF).build()).paymentSchedule(PaymentSchedule.builder().paymentFrequency(Frequency.P1M).paymentDateOffset(DaysAdjustment.NONE).build()).notionalSchedule(NOTIONAL).calculation(IborRateCalculation.builder().index(USD_LIBOR_1M).fixingDateOffset(DaysAdjustment.ofBusinessDays(-2, CalendarUSD.NYC, BDA_P)).build()).build(); SwapTrade trade = SwapTrade.builder().info(TradeInfo.builder().tradeDate(LocalDate.of(2014, 9, 10)).build()).product(Swap.of(payLeg, receiveLeg)).build(); CurveGroupName groupName = CurveGroupName.of("Test"); CurveId idUsdDsc = CurveId.of(groupName, StandardDataSets.GROUP1_USD_DSC.Name); CurveId idUsdOn = CurveId.of(groupName, StandardDataSets.GROUP1_USD_ON.Name); CurveId idUsdL1M = CurveId.of(groupName, StandardDataSets.GROUP1_USD_L1M.Name); CurveId idUsdL3M = CurveId.of(groupName, StandardDataSets.GROUP1_USD_L3M.Name); CurveId idUsdL6M = CurveId.of(groupName, StandardDataSets.GROUP1_USD_L6M.Name); MarketData suppliedData = ImmutableMarketData.builder(VAL_DATE).addValue(idUsdDsc, StandardDataSets.GROUP1_USD_DSC).addValue(idUsdOn, StandardDataSets.GROUP1_USD_ON).addValue(idUsdL1M, StandardDataSets.GROUP1_USD_L1M).addValue(idUsdL3M, StandardDataSets.GROUP1_USD_L3M).addValue(idUsdL6M, StandardDataSets.GROUP1_USD_L6M).build(); CalculationFunctions functions = StandardComponents.calculationFunctions(); RatesMarketDataLookup ratesLookup = RatesMarketDataLookup.of(ImmutableMap.of(USD, idUsdDsc), ImmutableMap.of(USD_FED_FUND, idUsdOn, USD_LIBOR_1M, idUsdL1M, USD_LIBOR_3M, idUsdL3M, USD_LIBOR_6M, idUsdL6M)); // create the calculation runner IList <SwapTrade> trades = ImmutableList.of(trade); IList <Column> columns = ImmutableList.of(Column.of(Measures.PRESENT_VALUE)); CalculationRules rules = CalculationRules.of(functions, USD, ratesLookup); // calculate results using the runner // using the direct executor means there is no need to close/shutdown the runner CalculationRunner runner = CalculationRunner.of(MoreExecutors.newDirectExecutorService()); Results results = runner.calculate(rules, trades, columns, suppliedData, REF_DATA); //JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET: //ORIGINAL LINE: com.opengamma.strata.collect.result.Result<?> result = results.get(0, 0); Result <object> result = results.get(0, 0); assertThat(result).Success; CurrencyAmount pv = (CurrencyAmount)result.Value; assertThat(pv.Amount).isCloseTo(-1003684.8402, offset(TOLERANCE_PV)); }
//------------------------------------------------------------------------- public virtual void test_OnAASpreadVsLibor3MSwap() { SwapLeg payLeg = RateCalculationSwapLeg.builder().payReceive(PAY).accrualSchedule(PeriodicSchedule.builder().startDate(LocalDate.of(2014, 9, 12)).endDate(LocalDate.of(2020, 9, 12)).frequency(P3M).businessDayAdjustment(BDA_MF).build()).paymentSchedule(PaymentSchedule.builder().paymentFrequency(P3M).paymentDateOffset(DaysAdjustment.NONE).build()).notionalSchedule(NOTIONAL).calculation(IborRateCalculation.builder().index(USD_LIBOR_3M).fixingDateOffset(DaysAdjustment.ofBusinessDays(-2, CalendarUSD.NYC, BDA_P)).build()).build(); SwapLeg receiveLeg = RateCalculationSwapLeg.builder().payReceive(RECEIVE).accrualSchedule(PeriodicSchedule.builder().startDate(LocalDate.of(2014, 9, 12)).endDate(LocalDate.of(2020, 9, 12)).frequency(P3M).businessDayAdjustment(BDA_MF).build()).paymentSchedule(PaymentSchedule.builder().paymentFrequency(P3M).paymentDateOffset(DaysAdjustment.NONE).build()).notionalSchedule(NOTIONAL).calculation(OvernightRateCalculation.builder().dayCount(ACT_360).index(USD_FED_FUND).accrualMethod(OvernightAccrualMethod.AVERAGED).rateCutOffDays(0).spread(ValueSchedule.of(0.0025)).build()).build(); ResolvedSwapTrade trade = SwapTrade.builder().info(TradeInfo.builder().tradeDate(LocalDate.of(2014, 1, 15)).build()).product(Swap.of(payLeg, receiveLeg)).build().resolve(REF_DATA); DiscountingSwapTradePricer pricer = swapPricer(); CurrencyAmount pv = pricer.presentValue(trade, provider()).getAmount(USD); assertEquals(pv.Amount, -160663.8362, TOLERANCE_PV); }
// ibor rate leg private static SwapLeg iborLeg(LocalDate start, LocalDate end, IborIndex index, PayReceive payReceive, NotionalSchedule notional, StubConvention stubConvention) { Frequency freq = Frequency.of(index.Tenor.Period); return(RateCalculationSwapLeg.builder().payReceive(payReceive).accrualSchedule(PeriodicSchedule.builder().startDate(start).endDate(end).frequency(freq).businessDayAdjustment(BDA_MF).stubConvention(stubConvention).build()).paymentSchedule(PaymentSchedule.builder().paymentFrequency(freq).paymentDateOffset(DaysAdjustment.NONE).build()).notionalSchedule(notional).calculation(IborRateCalculation.builder().index(index).fixingDateOffset(DaysAdjustment.ofBusinessDays(-2, index.FixingCalendar, BDA_P)).build()).build()); }
private static FxIndex parseFxIndex(CsvRow row) { string name = row.getField(NAME_FIELD); Currency baseCurrency = Currency.parse(row.getField(BASE_CURRENCY_FIELD)); Currency counterCurrency = Currency.parse(row.getField(COUNTER_CURRENCY_FIELD)); HolidayCalendarId fixingCal = HolidayCalendarId.of(row.getField(FIXING_CALENDAR_FIELD)); int maturityDays = int.Parse(row.getField(MATURITY_DAYS_FIELD)); HolidayCalendarId maturityCal = HolidayCalendarId.of(row.getField(MATURITY_CALENDAR_FIELD)); // build result return(ImmutableFxIndex.builder().name(name).currencyPair(CurrencyPair.of(baseCurrency, counterCurrency)).fixingCalendar(fixingCal).maturityDateOffset(DaysAdjustment.ofBusinessDays(maturityDays, maturityCal)).build()); }
static CalibrationDiscountFactorUsd2FomcDatesOisIrsTest() { DSC_NAMES[DSCON_CURVE_NAME] = USD; ISet <Index> usdFedFundSet = new HashSet <Index>(); usdFedFundSet.Add(USD_FED_FUND); IDX_NAMES[DSCON_CURVE_NAME] = usdFedFundSet; ISet <Index> usdLibor3Set = new HashSet <Index>(); usdLibor3Set.Add(USD_LIBOR_3M); IDX_NAMES[FWD3_CURVE_NAME] = usdLibor3Set; double fixingValue = 0.002345; LocalDateDoubleTimeSeries tsBdUsdLibor3M = LocalDateDoubleTimeSeries.builder().put(VAL_DATE_BD, fixingValue).build(); TS_BD_LIBOR3M = ImmutableMarketData.builder(VAL_DATE_BD).addTimeSeries(IndexQuoteId.of(USD_LIBOR_3M), tsBdUsdLibor3M).build(); for (int i = 0; i < DSC_NB_DEPO_NODES; i++) { BusinessDayAdjustment bda = BusinessDayAdjustment.of(FOLLOWING, USNY); TermDepositConvention convention = ImmutableTermDepositConvention.of("USD-Dep", USD, bda, ACT_360, DaysAdjustment.ofBusinessDays(DSC_DEPO_OFFSET[i], USNY)); LocalDate nodeDate = FOMC_NODES[i]; if (nodeDate != null) { DSC_NODES[i] = TermDepositCurveNode.builder().template(TermDepositTemplate.of(Period.ofDays(1), convention)).rateId(QuoteId.of(StandardId.of(SCHEME, DSC_ID_VALUE[i]))).date(CurveNodeDate.of(nodeDate)).build(); } else { DSC_NODES[i] = TermDepositCurveNode.of(TermDepositTemplate.of(Period.ofDays(1), convention), QuoteId.of(StandardId.of(SCHEME, DSC_ID_VALUE[i]))); } } for (int i = 0; i < DSC_NB_OIS_NODES; i++) { LocalDate nodeDate = FOMC_NODES[DSC_NB_DEPO_NODES + i]; if (nodeDate != null) { DSC_NODES[DSC_NB_DEPO_NODES + i] = FixedOvernightSwapCurveNode.builder().template(FixedOvernightSwapTemplate.of(Period.ZERO, Tenor.of(DSC_OIS_TENORS[i]), USD_FIXED_1Y_FED_FUND_OIS)).rateId(QuoteId.of(StandardId.of(SCHEME, DSC_ID_VALUE[DSC_NB_DEPO_NODES + i]))).date(CurveNodeDate.of(nodeDate)).build(); } else { DSC_NODES[DSC_NB_DEPO_NODES + i] = FixedOvernightSwapCurveNode.of(FixedOvernightSwapTemplate.of(Period.ZERO, Tenor.of(DSC_OIS_TENORS[i]), USD_FIXED_1Y_FED_FUND_OIS), QuoteId.of(StandardId.of(SCHEME, DSC_ID_VALUE[DSC_NB_DEPO_NODES + i]))); } } FWD3_NODES[0] = IborFixingDepositCurveNode.of(IborFixingDepositTemplate.of(USD_LIBOR_3M), QuoteId.of(StandardId.of(SCHEME, FWD3_ID_VALUE[0]))); for (int i = 0; i < FWD3_NB_FRA_NODES; i++) { FWD3_NODES[i + 1] = FraCurveNode.of(FraTemplate.of(FWD3_FRA_TENORS[i], USD_LIBOR_3M), QuoteId.of(StandardId.of(SCHEME, FWD3_ID_VALUE[i + 1]))); } for (int i = 0; i < FWD3_NB_IRS_NODES; i++) { FWD3_NODES[i + 1 + FWD3_NB_FRA_NODES] = FixedIborSwapCurveNode.of(FixedIborSwapTemplate.of(Period.ZERO, Tenor.of(FWD3_IRS_TENORS[i]), USD_FIXED_6M_LIBOR_3M), QuoteId.of(StandardId.of(SCHEME, FWD3_ID_VALUE[i + 1 + FWD3_NB_FRA_NODES]))); } ImmutableMarketDataBuilder builder = ImmutableMarketData.builder(VAL_DATE_BD); for (int i = 0; i < FWD3_NB_NODES; i++) { builder.addValue(QuoteId.of(StandardId.of(SCHEME, FWD3_ID_VALUE[i])), FWD3_MARKET_QUOTES[i]); } for (int i = 0; i < DSC_NB_NODES; i++) { builder.addValue(QuoteId.of(StandardId.of(SCHEME, DSC_ID_VALUE[i])), DSC_MARKET_QUOTES[i]); } ALL_QUOTES_BD = builder.build(); IList <CurveNode[]> groupDsc = new List <CurveNode[]>(); groupDsc.Add(DSC_NODES); CURVES_NODES.Add(groupDsc); IList <CurveNode[]> groupFwd3 = new List <CurveNode[]>(); groupFwd3.Add(FWD3_NODES); CURVES_NODES.Add(groupFwd3); IList <CurveMetadata> groupDsc = new List <CurveMetadata>(); groupDsc.Add(DefaultCurveMetadata.builder().curveName(DSCON_CURVE_NAME).xValueType(ValueType.YEAR_FRACTION).yValueType(ValueType.ZERO_RATE).dayCount(CURVE_DC).build()); CURVES_METADATA.Add(groupDsc); IList <CurveMetadata> groupFwd3 = new List <CurveMetadata>(); groupFwd3.Add(DefaultCurveMetadata.builder().curveName(FWD3_CURVE_NAME).xValueType(ValueType.YEAR_FRACTION).yValueType(ValueType.ZERO_RATE).dayCount(CURVE_DC).build()); CURVES_METADATA.Add(groupFwd3); }
// parses the payment schedule private PaymentSchedule parseSwapPaymentSchedule(XmlElement legEl, XmlElement calcEl, FpmlDocument document) { // supported elements: // 'paymentDates/paymentFrequency' // 'paymentDates/payRelativeTo' // 'paymentDates/paymentDaysOffset?' // 'paymentDates/paymentDatesAdjustments' // 'calculationPeriodAmount/calculation/compoundingMethod' // 'paymentDates/firstPaymentDate?' // 'paymentDates/lastRegularPaymentDate?' // ignored elements: // 'paymentDates/calculationPeriodDatesReference' // 'paymentDates/resetDatesReference' // 'paymentDates/valuationDatesReference' PaymentSchedule.Builder paymentScheduleBuilder = PaymentSchedule.builder(); // payment dates XmlElement paymentDatesEl = legEl.getChild("paymentDates"); // frequency paymentScheduleBuilder.paymentFrequency(document.parseFrequency(paymentDatesEl.getChild("paymentFrequency"))); //default for IRS is pay relative to period end; Strata model will apply the defaulting but the values is needed //here for first and last payment date checks PaymentRelativeTo payRelativeTo = paymentDatesEl.findChild("payRelativeTo").map(el => parsePayRelativeTo(el)).orElse(PaymentRelativeTo.PERIOD_END); paymentScheduleBuilder.paymentRelativeTo(payRelativeTo); // dates if (payRelativeTo == PaymentRelativeTo.PERIOD_END) { // ignore data if not PeriodEnd and hope schedule is worked out correctly by other means // this provides compatibility for old code that ignored these FpML fields paymentDatesEl.findChild("firstPaymentDate").map(el => document.parseDate(el)).ifPresent(date => paymentScheduleBuilder.firstRegularStartDate(date)); paymentDatesEl.findChild("lastRegularPaymentDate").map(el => document.parseDate(el)).ifPresent(date => paymentScheduleBuilder.lastRegularEndDate(date)); } // offset Optional <XmlElement> paymentOffsetEl = paymentDatesEl.findChild("paymentDaysOffset"); BusinessDayAdjustment payAdjustment = document.parseBusinessDayAdjustments(paymentDatesEl.getChild("paymentDatesAdjustments")); if (paymentOffsetEl.Present) { Period period = document.parsePeriod(paymentOffsetEl.get()); if (period.toTotalMonths() != 0) { throw new FpmlParseException("Invalid 'paymentDatesAdjustments' value, expected days-based period: " + period); } Optional <XmlElement> dayTypeEl = paymentOffsetEl.get().findChild("dayType"); bool fixingCalendarDays = period.Zero || (dayTypeEl.Present && dayTypeEl.get().Content.Equals("Calendar")); if (fixingCalendarDays) { paymentScheduleBuilder.paymentDateOffset(DaysAdjustment.ofCalendarDays(period.Days, payAdjustment)); } else { paymentScheduleBuilder.paymentDateOffset(DaysAdjustment.ofBusinessDays(period.Days, payAdjustment.Calendar)); } } else { paymentScheduleBuilder.paymentDateOffset(DaysAdjustment.ofCalendarDays(0, payAdjustment)); } // compounding calcEl.findChild("compoundingMethod").ifPresent(compoundingEl => { paymentScheduleBuilder.compoundingMethod(CompoundingMethod.of(compoundingEl.Content)); }); return(paymentScheduleBuilder.build()); }
//----------------------------------------------------------------------- public virtual void fixedSwapLeg() { // a PeriodicSchedule generates a schedule of accrual periods // - interest is accrued every 3 months from 2014-02-12 to 2014-07-31 // - accrual period dates are adjusted "modified following" using the "GBLO" holiday calendar // - there will be a long initial stub // - the regular accrual period dates will be at the end-of-month PeriodicSchedule accrualSchedule = PeriodicSchedule.builder().startDate(LocalDate.of(2014, 2, 12)).endDate(LocalDate.of(2016, 7, 31)).businessDayAdjustment(BusinessDayAdjustment.of(MODIFIED_FOLLOWING, HolidayCalendarIds.GBLO)).frequency(Frequency.P3M).stubConvention(StubConvention.LONG_INITIAL).rollConvention(RollConventions.EOM).build(); // a PaymentSchedule generates a schedule of payment periods, based on the accrual schedule // - payments are every 6 months // - payments are 2 business days after the end of the period // - straight compounding is used (the payments are less frequent than the accrual, so compounding occurs) PaymentSchedule paymentSchedule = PaymentSchedule.builder().paymentFrequency(Frequency.P6M).paymentRelativeTo(PaymentRelativeTo.PERIOD_END).paymentDateOffset(DaysAdjustment.ofBusinessDays(2, HolidayCalendarIds.GBLO)).compoundingMethod(CompoundingMethod.STRAIGHT).build(); // a NotionalSchedule generates a schedule of notional amounts, based on the payment schedule // - in this simple case the notional is 1 million GBP and does not change NotionalSchedule notionalSchedule = NotionalSchedule.of(Currency.GBP, 1_000_000); // a RateCalculationSwapLeg can represent a fixed or floating swap leg // - a FixedRateCalculation is used to represent a fixed rate // - the "Act/Act ISDA" day count is used // - the rate starts at 0.8% and reduces to 0.7% RateCalculationSwapLeg swapLeg = RateCalculationSwapLeg.builder().payReceive(PayReceive.PAY).accrualSchedule(accrualSchedule).paymentSchedule(paymentSchedule).notionalSchedule(notionalSchedule).calculation(FixedRateCalculation.builder().dayCount(DayCounts.ACT_ACT_ISDA).rate(ValueSchedule.of(0.008, ValueStep.of(LocalDate.of(2015, 1, 31), ValueAdjustment.ofReplace(0.007)))).build()).build(); // a ResolvedSwapLeg has all the dates of the cash flows // it remains valid so long as the holiday calendar does not change ResolvedSwapLeg resolvedLeg = swapLeg.resolve(ReferenceData.standard()); Console.WriteLine("===== Fixed ====="); Console.WriteLine(JodaBeanSer.PRETTY.xmlWriter().write(swapLeg)); Console.WriteLine(); Console.WriteLine("===== Fixed resolved ====="); Console.WriteLine(JodaBeanSer.PRETTY.xmlWriter().write(resolvedLeg)); Console.WriteLine(); }
public virtual void test_builder_fail() { // negative settlement date offset assertThrowsIllegalArg(() => CapitalIndexedBond.builder().securityId(SECURITY_ID).notional(NOTIONAL).currency(USD).dayCount(ACT_ACT_ISDA).rateCalculation(RATE_CALC).exCouponPeriod(EX_COUPON).legalEntityId(LEGAL_ENTITY).yieldConvention(US_IL_REAL).settlementDateOffset(DaysAdjustment.ofBusinessDays(-2, USNY)).accrualSchedule(SCHEDULE).build()); // positive ex-coupon days assertThrowsIllegalArg(() => CapitalIndexedBond.builder().securityId(SECURITY_ID).notional(NOTIONAL).currency(USD).dayCount(ACT_ACT_ISDA).rateCalculation(RATE_CALC).exCouponPeriod(DaysAdjustment.ofCalendarDays(7, BusinessDayAdjustment.of(BusinessDayConventions.FOLLOWING, USNY))).legalEntityId(LEGAL_ENTITY).yieldConvention(US_IL_REAL).settlementDateOffset(SETTLE_OFFSET).accrualSchedule(SCHEDULE).build()); }