public void test_collectIndices_simple() { RateCalculationSwapLeg test = RateCalculationSwapLeg.builder() .payReceive(PAY) .accrualSchedule(PeriodicSchedule.builder() .startDate(DATE_01_05) .endDate(DATE_04_05) .frequency(P1M) .businessDayAdjustment(BusinessDayAdjustment.of(FOLLOWING, GBLO)) .build()) .paymentSchedule(PaymentSchedule.builder() .paymentFrequency(P1M) .paymentDateOffset(PLUS_TWO_DAYS) .build()) .notionalSchedule(NotionalSchedule.of(GBP, 1000d)) .calculation(IborRateCalculation.builder() .dayCount(DayCounts.ACT_365F) .index(GBP_LIBOR_3M) .fixingDateOffset(MINUS_TWO_DAYS) .build()) .build(); ImmutableSet.Builder<Index> builder = ImmutableSet.builder(); test.collectIndices(builder); assertEquals(builder.build(), ImmutableSet.of(GBP_LIBOR_3M)); assertEquals(test.allIndices(), ImmutableSet.of(GBP_LIBOR_3M)); assertEquals(test.allCurrencies(), ImmutableSet.of(GBP)); }
private static RateCalculationSwapLeg parseLeg( CsvRow row, String leg, FloatingRateIndex index, DayCount defaultFixedLegDayCount) { PayReceive payReceive = LoaderUtils.parsePayReceive(getValue(row, leg, DIRECTION_FIELD)); PeriodicSchedule accrualSch = parseAccrualSchedule(row, leg); PaymentSchedule paymentSch = parsePaymentSchedule(row, leg, accrualSch.getFrequency()); NotionalSchedule notionalSch = parseNotionalSchedule(row, leg); RateCalculation calc = parseRateCalculation( row, leg, index, defaultFixedLegDayCount, accrualSch.getBusinessDayAdjustment(), notionalSch.getCurrency()); return RateCalculationSwapLeg.builder() .payReceive(payReceive) .accrualSchedule(accrualSch) .paymentSchedule(paymentSch) .notionalSchedule(notionalSch) .calculation(calc) .build(); }
public void test_toLeg1() { FixedRateSwapLegConvention base = FixedRateSwapLegConvention.of(GBP, ACT_365F, P3M, BDA_MOD_FOLLOW); LocalDate startDate = LocalDate.of(2015, 5, 5); LocalDate endDate = LocalDate.of(2020, 5, 5); RateCalculationSwapLeg test = base.toLeg(startDate, endDate, PAY, NOTIONAL_2M, 0.25d); RateCalculationSwapLeg expected = RateCalculationSwapLeg.builder() .payReceive(PAY) .accrualSchedule(PeriodicSchedule.builder() .frequency(P3M) .startDate(startDate) .endDate(endDate) .businessDayAdjustment(BDA_MOD_FOLLOW) .stubConvention(StubConvention.SMART_INITIAL) .build()) .paymentSchedule(PaymentSchedule.builder() .paymentFrequency(P3M) .paymentDateOffset(DaysAdjustment.NONE) .build()) .notionalSchedule(NotionalSchedule.of(GBP, NOTIONAL_2M)) .calculation(FixedRateCalculation.of(0.25d, ACT_365F)) .build(); assertEquals(test, expected); }
public void test_toLeg() { InflationRateSwapLegConvention base = InflationRateSwapLegConvention.of(GB_HICP, LAG_3M, MONTHLY, BDA_MOD_FOLLOW); LocalDate startDate = LocalDate.of(2015, 5, 5); LocalDate endDate = LocalDate.of(2020, 5, 5); RateCalculationSwapLeg test = base.toLeg( startDate, endDate, PAY, NOTIONAL_2M); RateCalculationSwapLeg expected = RateCalculationSwapLeg.builder() .payReceive(PAY) .accrualSchedule(PeriodicSchedule.builder() .frequency(Frequency.TERM) .startDate(startDate) .endDate(endDate) .businessDayAdjustment(BDA_MOD_FOLLOW) .build()) .paymentSchedule(PaymentSchedule.builder() .paymentFrequency(Frequency.TERM) .paymentDateOffset(DaysAdjustment.NONE) .build()) .notionalSchedule(NotionalSchedule.of(GBP, NOTIONAL_2M)) .calculation(InflationRateCalculation.of(GB_HICP, 3, MONTHLY)) .build(); assertEquals(test, expected); }
public void test_toLeg() { IborRateSwapLegConvention base = IborRateSwapLegConvention.builder() .index(GBP_LIBOR_3M) .build(); LocalDate startDate = LocalDate.of(2015, 5, 5); LocalDate endDate = LocalDate.of(2020, 5, 5); RateCalculationSwapLeg test = base.toLeg(startDate, endDate, PAY, NOTIONAL_2M); RateCalculationSwapLeg expected = RateCalculationSwapLeg.builder() .payReceive(PAY) .accrualSchedule(PeriodicSchedule.builder() .frequency(P3M) .startDate(startDate) .endDate(endDate) .businessDayAdjustment(BDA_MOD_FOLLOW) .build()) .paymentSchedule(PaymentSchedule.builder() .paymentFrequency(P3M) .paymentDateOffset(DaysAdjustment.NONE) .build()) .notionalSchedule(NotionalSchedule.of(GBP, NOTIONAL_2M)) .calculation(IborRateCalculation.of(GBP_LIBOR_3M)) .build(); assertEquals(test, expected); }
public void test_toLeg() { OvernightRateSwapLegConvention base = OvernightRateSwapLegConvention.of(GBP_SONIA, TERM, 2); LocalDate startDate = LocalDate.of(2015, 5, 5); LocalDate endDate = LocalDate.of(2020, 5, 5); RateCalculationSwapLeg test = base.toLeg(startDate, endDate, PAY, NOTIONAL_2M); RateCalculationSwapLeg expected = RateCalculationSwapLeg.builder() .payReceive(PAY) .accrualSchedule(PeriodicSchedule.builder() .frequency(TERM) .startDate(startDate) .endDate(endDate) .businessDayAdjustment(BDA_MOD_FOLLOW) .stubConvention(StubConvention.SMART_INITIAL) .build()) .paymentSchedule(PaymentSchedule.builder() .paymentFrequency(TERM) .paymentDateOffset(DaysAdjustment.ofBusinessDays(2, GBP_SONIA.getFixingCalendar())) .build()) .notionalSchedule(NotionalSchedule.of(GBP, NOTIONAL_2M)) .calculation(OvernightRateCalculation.of(GBP_SONIA)) .build(); assertEquals(test, expected); }
public void test_VanillaFixedVsLibor1mSwap() { SwapLeg payLeg = fixedLeg( LocalDate.of(2014, 9, 12), LocalDate.of(2016, 9, 12), P6M, 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(P1M) .businessDayAdjustment(BDA_MF) .build()) .paymentSchedule(PaymentSchedule.builder() .paymentFrequency(P1M) .paymentDateOffset(DaysAdjustment.NONE) .build()) .notionalSchedule(NOTIONAL) .calculation(IborRateCalculation.builder() .index(USD_LIBOR_1M) .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.getAmount(), -1003684.8402, TOLERANCE_PV); }
public 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.getAmount(), 3588376.471608199, TOLERANCE_PV); }
LocalDate.of(2014, 9, 12), LocalDate.of(2016, 6, 12), P6M, RECEIVE, NOTIONAL, 0.01, StubConvention.SHORT_INITIAL); SwapLeg payLeg = RateCalculationSwapLeg.builder() .payReceive(PAY) .accrualSchedule(PeriodicSchedule.builder()
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()
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()
public void test_toLeg_withSpread() { IborRateSwapLegConvention base = IborRateSwapLegConvention.builder() .index(GBP_LIBOR_3M) .build(); LocalDate startDate = LocalDate.of(2015, 5, 5); LocalDate endDate = LocalDate.of(2020, 5, 5); RateCalculationSwapLeg test = base.toLeg(startDate, endDate, PAY, NOTIONAL_2M, 0.25d); RateCalculationSwapLeg expected = RateCalculationSwapLeg.builder() .payReceive(PAY) .accrualSchedule(PeriodicSchedule.builder() .frequency(P3M) .startDate(startDate) .endDate(endDate) .businessDayAdjustment(BDA_MOD_FOLLOW) .build()) .paymentSchedule(PaymentSchedule.builder() .paymentFrequency(P3M) .paymentDateOffset(DaysAdjustment.NONE) .build()) .notionalSchedule(NotionalSchedule.of(GBP, NOTIONAL_2M)) .calculation(IborRateCalculation.builder() .index(GBP_LIBOR_3M) .spread(ValueSchedule.of(0.25d)) .build()) .build(); assertEquals(test, expected); }
public void test_toLeg_withSpread() { OvernightRateSwapLegConvention base = OvernightRateSwapLegConvention.builder() .index(GBP_SONIA) .accrualMethod(AVERAGED) .build(); LocalDate startDate = LocalDate.of(2015, 5, 5); LocalDate endDate = LocalDate.of(2020, 5, 5); RateCalculationSwapLeg test = base.toLeg(startDate, endDate, PAY, NOTIONAL_2M, 0.25d); RateCalculationSwapLeg expected = RateCalculationSwapLeg.builder() .payReceive(PAY) .accrualSchedule(PeriodicSchedule.builder() .frequency(TERM) .startDate(startDate) .endDate(endDate) .businessDayAdjustment(BDA_MOD_FOLLOW) .build()) .paymentSchedule(PaymentSchedule.builder() .paymentFrequency(TERM) .paymentDateOffset(DaysAdjustment.NONE) .build()) .notionalSchedule(NotionalSchedule.of(GBP, NOTIONAL_2M)) .calculation(OvernightRateCalculation.builder() .index(GBP_SONIA) .accrualMethod(AVERAGED) .spread(ValueSchedule.of(0.25d)) .build()) .build(); assertEquals(test, expected); }
private static SwapLeg fixedLeg( LocalDate start, LocalDate end, Frequency frequency, PayReceive payReceive, NotionalSchedule notional, double fixedRate, StubConvention stubConvention) { return RateCalculationSwapLeg.builder() .payReceive(payReceive) .accrualSchedule(PeriodicSchedule.builder() .startDate(start) .endDate(end) .frequency(frequency) .businessDayAdjustment(BDA_MF) .stubConvention(stubConvention) .build()) .paymentSchedule(PaymentSchedule.builder() .paymentFrequency(frequency) .paymentDateOffset(DaysAdjustment.NONE) .build()) .notionalSchedule(notional) .calculation(FixedRateCalculation.builder() .dayCount(THIRTY_U_360) .rate(ValueSchedule.of(fixedRate)) .build()) .build(); }
public void test_serialization() { RateCalculationSwapLeg test = RateCalculationSwapLeg.builder() .payReceive(PAY) .accrualSchedule(PeriodicSchedule.builder() .startDate(DATE_01_05) .endDate(DATE_04_05) .frequency(P1M) .businessDayAdjustment(BusinessDayAdjustment.of(FOLLOWING, GBLO)) .build()) .paymentSchedule(PaymentSchedule.builder() .paymentFrequency(P1M) .paymentDateOffset(PLUS_TWO_DAYS) .build()) .notionalSchedule(NotionalSchedule.of(GBP, 1000d)) .calculation(FixedRateCalculation.builder() .dayCount(DayCounts.ACT_365F) .rate(ValueSchedule.of(0.025d)) .build()) .build(); assertSerialization(test); }
private static SwapLeg fixedLeg( LocalDate start, LocalDate end, Frequency frequency, PayReceive payReceive, NotionalSchedule notional, double fixedRate, StubConvention stubConvention) { return RateCalculationSwapLeg.builder() .payReceive(payReceive) .accrualSchedule(PeriodicSchedule.builder() .startDate(start) .endDate(end) .frequency(frequency) .businessDayAdjustment(BDA_MF) .stubConvention(stubConvention) .build()) .paymentSchedule(PaymentSchedule.builder() .paymentFrequency(frequency) .paymentDateOffset(DaysAdjustment.NONE) .build()) .notionalSchedule(notional) .calculation(FixedRateCalculation.builder() .dayCount(THIRTY_U_360) .rate(ValueSchedule.of(fixedRate)) .build()) .build(); }
private static SwapLeg fixedLeg( LocalDate start, LocalDate end, Frequency frequency, PayReceive payReceive, NotionalSchedule notional, double fixedRate, StubConvention stubConvention) { return RateCalculationSwapLeg.builder() .payReceive(payReceive) .accrualSchedule(PeriodicSchedule.builder() .startDate(start) .endDate(end) .frequency(frequency) .businessDayAdjustment(BDA_MF) .stubConvention(stubConvention) .build()) .paymentSchedule(PaymentSchedule.builder() .paymentFrequency(frequency) .paymentDateOffset(DaysAdjustment.NONE) .build()) .notionalSchedule(notional) .calculation(FixedRateCalculation.builder() .dayCount(THIRTY_U_360) .rate(ValueSchedule.of(fixedRate)) .build()) .build(); }
private static SwapLeg iborLeg( LocalDate start, LocalDate end, IborIndex index, PayReceive payReceive, NotionalSchedule notional, StubConvention stubConvention) { Frequency freq = Frequency.of(index.getTenor().getPeriod()); 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.getFixingCalendar(), BDA_P)) .build()) .build(); }
private static SwapLeg iborLeg( LocalDate start, LocalDate end, IborIndex index, PayReceive payReceive, NotionalSchedule notional, StubConvention stubConvention) { Frequency freq = Frequency.of(index.getTenor().getPeriod()); 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.getFixingCalendar(), BDA_P)) .build()) .build(); }
private SwapLeg createInflationSwapLeg(boolean interpolated, PayReceive pay) { BusinessDayAdjustment adj = BusinessDayAdjustment.of(FOLLOWING, GBLO); PeriodicSchedule accrualSchedule = PeriodicSchedule.builder() .startDate(DATE_14_06_09) .endDate(DATE_19_06_09) .frequency(Frequency.ofYears(5)) .businessDayAdjustment(adj) .build(); PaymentSchedule paymentSchedule = PaymentSchedule.builder() .paymentFrequency(Frequency.ofYears(5)) .paymentDateOffset(DaysAdjustment.ofBusinessDays(2, GBLO)) .build(); InflationRateCalculation rateCalc = InflationRateCalculation.builder() .index(GB_RPI) .indexCalculationMethod(interpolated ? INTERPOLATED : MONTHLY) .lag(Period.ofMonths(3)) .build(); NotionalSchedule notionalSchedule = NotionalSchedule.of(GBP, NOTIONAL); SwapLeg swapLeg = RateCalculationSwapLeg.builder() .payReceive(pay) .accrualSchedule(accrualSchedule) .paymentSchedule(paymentSchedule) .notionalSchedule(notionalSchedule) .calculation(rateCalc) .build(); return swapLeg; }