public virtual void test_createCap() { SabrIborCapletFloorletVolatilityBootstrapDefinition @base = SabrIborCapletFloorletVolatilityBootstrapDefinition.ofFixedBeta(NAME, USD_LIBOR_3M, ACT_ACT_ISDA, 0.5, STEP_UPPER, FLAT, FLAT, SabrVolatilityFormula.hagan()); LocalDate startDate = LocalDate.of(2012, 4, 20); LocalDate endDate = LocalDate.of(2017, 4, 20); double strike = 0.01; IborCapFloorLeg expected = IborCapFloorLeg.builder().calculation(IborRateCalculation.of(USD_LIBOR_3M)).capSchedule(ValueSchedule.of(strike)).currency(USD_LIBOR_3M.Currency).notional(ValueSchedule.ALWAYS_1).paymentDateOffset(DaysAdjustment.NONE).paymentSchedule(PeriodicSchedule.of(startDate, endDate, Frequency.of(USD_LIBOR_3M.Tenor.Period), BusinessDayAdjustment.of(BusinessDayConventions.MODIFIED_FOLLOWING, USD_LIBOR_3M.FixingCalendar), StubConvention.NONE, RollConventions.NONE)).payReceive(PayReceive.RECEIVE).build(); IborCapFloorLeg computed = @base.createCap(startDate, endDate, strike); assertEquals(computed, expected); }
/// <summary> /// Creates an Ibor cap/floor leg. /// <para> /// The Ibor index should be {@code EUR_EURIBOR_3M} or {@code EUR_EURIBOR_6M} to match the availability of the curve /// data in <seealso cref="IborCapletFloorletDataSet"/>. /// /// </para> /// </summary> /// <param name="index"> the index </param> /// <param name="startDate"> the start date </param> /// <param name="endDate"> the end date </param> /// <param name="strikeSchedule"> the strike </param> /// <param name="notionalSchedule"> the notional </param> /// <param name="putCall"> cap or floor </param> /// <param name="payRec"> pay or receive </param> /// <returns> the instance </returns> public static IborCapFloorLeg createCapFloorLegUnresolved(IborIndex index, LocalDate startDate, LocalDate endDate, ValueSchedule strikeSchedule, ValueSchedule notionalSchedule, PutCall putCall, PayReceive payRec) { Frequency frequency = Frequency.of(index.Tenor.Period); PeriodicSchedule paySchedule = PeriodicSchedule.of(startDate, endDate, frequency, BUSINESS_ADJ, StubConvention.NONE, RollConventions.NONE); IborRateCalculation rateCalculation = IborRateCalculation.of(index); if (putCall.Call) { return(IborCapFloorLeg.builder().calculation(rateCalculation).capSchedule(strikeSchedule).notional(notionalSchedule).paymentSchedule(paySchedule).payReceive(payRec).build()); } return(IborCapFloorLeg.builder().calculation(rateCalculation).floorSchedule(strikeSchedule).notional(notionalSchedule).paymentSchedule(paySchedule).payReceive(payRec).build()); }
internal static Dsf sut2() { SwapLeg iborLeg = RateCalculationSwapLeg.builder().payReceive(PAY).accrualSchedule(PeriodicSchedule.builder().startDate(LocalDate.of(2014, 9, 12)).endDate(LocalDate.of(2016, 9, 12)).frequency(P1M).businessDayAdjustment(BDA_MF).stubConvention(StubConvention.SHORT_INITIAL).build()).paymentSchedule(PaymentSchedule.builder().paymentFrequency(P3M).paymentDateOffset(DaysAdjustment.NONE).build()).notionalSchedule(NotionalSchedule.builder().currency(USD).amount(ValueSchedule.of(1d)).finalExchange(true).initialExchange(true).build()).calculation(IborRateCalculation.builder().index(INDEX).fixingDateOffset(DaysAdjustment.ofBusinessDays(-2, SAT_SUN, BDA_P)).build()).build(); Swap swap2 = Swap.of(SWAP.getLeg(RECEIVE).get(), iborLeg); return(Dsf.builder().securityId(SECURITY_ID2).notional(20000L).deliveryDate(LocalDate.of(2014, 9, 5)).lastTradeDate(LocalDate.of(2014, 9, 2)).underlyingSwap(swap2).build()); }
public virtual void test_builder_notUnitNotional() { SwapLeg fixedLeg10 = RateCalculationSwapLeg.builder().payReceive(RECEIVE).accrualSchedule(PeriodicSchedule.builder().startDate(LocalDate.of(2014, 9, 12)).endDate(LocalDate.of(2016, 9, 12)).frequency(P6M).businessDayAdjustment(BDA_MF).stubConvention(StubConvention.SHORT_INITIAL).build()).paymentSchedule(PaymentSchedule.builder().paymentFrequency(P6M).paymentDateOffset(DaysAdjustment.NONE).build()).notionalSchedule(NotionalSchedule.of(USD, 10d)).calculation(FixedRateCalculation.builder().dayCount(THIRTY_U_360).rate(ValueSchedule.of(0.015)).build()).build(); SwapLeg knownAmountLeg = KnownAmountSwapLeg.builder().payReceive(RECEIVE).accrualSchedule(PeriodicSchedule.builder().startDate(LocalDate.of(2014, 9, 12)).endDate(LocalDate.of(2016, 9, 12)).frequency(P6M).businessDayAdjustment(BDA_MF).stubConvention(StubConvention.SHORT_INITIAL).build()).paymentSchedule(PaymentSchedule.builder().paymentFrequency(P6M).paymentDateOffset(DaysAdjustment.NONE).build()).amount(ValueSchedule.of(0.015)).currency(USD).build(); SwapLeg iborLeg500 = RateCalculationSwapLeg.builder().payReceive(PAY).accrualSchedule(PeriodicSchedule.builder().startDate(LocalDate.of(2014, 9, 12)).endDate(LocalDate.of(2016, 9, 12)).frequency(P1M).businessDayAdjustment(BDA_MF).stubConvention(StubConvention.SHORT_INITIAL).build()).paymentSchedule(PaymentSchedule.builder().paymentFrequency(P3M).paymentDateOffset(DaysAdjustment.NONE).build()).notionalSchedule(NotionalSchedule.builder().currency(USD).amount(ValueSchedule.of(500d)).finalExchange(true).initialExchange(true).build()).calculation(IborRateCalculation.builder().index(INDEX).fixingDateOffset(DaysAdjustment.ofBusinessDays(-2, SAT_SUN, BDA_P)).build()).build(); Swap swap1 = Swap.of(fixedLeg10, SWAP.getLeg(PAY).get()); Swap swap2 = Swap.of(SWAP.getLeg(RECEIVE).get(), iborLeg500); Swap swap3 = Swap.of(knownAmountLeg, SWAP.getLeg(PAY).get()); assertThrowsIllegalArg(() => Dsf.builder().securityId(SECURITY_ID).notional(NOTIONAL).deliveryDate(DELIVERY_DATE).lastTradeDate(LAST_TRADE_DATE).underlyingSwap(swap1).build()); assertThrowsIllegalArg(() => Dsf.builder().securityId(SECURITY_ID).notional(NOTIONAL).deliveryDate(DELIVERY_DATE).lastTradeDate(LAST_TRADE_DATE).underlyingSwap(swap2).build()); // should succeed normally (no notional to validate on known amount leg) Dsf.builder().securityId(SECURITY_ID).notional(NOTIONAL).deliveryDate(DELIVERY_DATE).lastTradeDate(LAST_TRADE_DATE).underlyingSwap(swap3).build(); }
// fixed 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()); }