public void test_builder() { SwapTrade test = SwapTrade.builder() .product(SWAP1) .build(); assertEquals(test.getInfo(), TradeInfo.empty()); assertEquals(test.getProduct(), SWAP1); }
@Override public SwapTrade toTrade( TradeInfo tradeInfo, LocalDate startDate, LocalDate endDate, BuySell buySell, double notional, double fixedRate) { Optional<LocalDate> tradeDate = tradeInfo.getTradeDate(); if (tradeDate.isPresent()) { ArgChecker.inOrderOrEqual(tradeDate.get(), startDate, "tradeDate", "startDate"); } SwapLeg leg1 = fixedLeg.toLeg(startDate, endDate, PayReceive.ofPay(buySell.isBuy()), notional, fixedRate); SwapLeg leg2 = floatingLeg.toLeg(startDate, endDate, PayReceive.ofPay(buySell.isSell()), notional); return SwapTrade.builder() .info(tradeInfo) .product(Swap.of(leg1, leg2)) .build(); }
@Override public SwapTrade toTrade( TradeInfo tradeInfo, LocalDate startDate, LocalDate endDate, BuySell buySell, double notional, double fixedRate) { Optional<LocalDate> tradeDate = tradeInfo.getTradeDate(); if (tradeDate.isPresent()) { ArgChecker.inOrderOrEqual(tradeDate.get(), startDate, "tradeDate", "startDate"); } SwapLeg leg1 = fixedLeg.toLeg(startDate, endDate, PayReceive.ofPay(buySell.isBuy()), notional, fixedRate); SwapLeg leg2 = floatingLeg.toLeg(startDate, endDate, PayReceive.ofPay(buySell.isSell()), notional); return SwapTrade.builder() .info(tradeInfo) .product(Swap.of(leg1, leg2)) .build(); }
.product(Swap.of(payLeg, receiveLeg)) .build() .resolve(REF_DATA);
.product(Swap.of(receiveLeg, payLeg)) .build() .resolve(REF_DATA);
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); }
.product(Swap.of(receiveLeg, payLeg)) .build() .resolve(REF_DATA);
.product(Swap.of(receiveLeg, payLeg)) .build() .resolve(REF_DATA);
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); }
.product(Swap.of(receiveLeg, payLeg)) .build() .resolve(REF_DATA);
public void test_VanillaFixedVsLibor3mSwap() { SwapLeg payLeg = fixedLeg( LocalDate.of(2014, 9, 12), LocalDate.of(2021, 9, 12), P6M, PAY, NOTIONAL, 0.015, null); SwapLeg receiveLeg = iborLeg(LocalDate.of(2014, 9, 12), LocalDate.of(2021, 9, 12), USD_LIBOR_3M, RECEIVE, NOTIONAL, null); ResolvedSwapTrade trade = SwapTrade.builder() .info(TradeInfo.builder().tradeDate(LocalDate.of(2014, 9, 10)).build()) .product(Swap.of(payLeg, receiveLeg)) .build() .resolve(REF_DATA); // test pv DiscountingSwapTradePricer pricer = swapPricer(); CurrencyAmount pv = pricer.presentValue(trade, provider()).getAmount(USD); assertEquals(pv.getAmount(), 7170391.798257509, TOLERANCE_PV); // test par rate double parRate = PRICER_PRODUCT.parRate(trade.getProduct(), provider()); assertEquals(parRate, 0.02589471566819517, TOLERANCE_RATE); // test par rate vs pv ResolvedSwap swapPV0 = Swap.of(fixedLeg(LocalDate.of(2014, 9, 12), LocalDate.of(2021, 9, 12), P6M, PAY, NOTIONAL, parRate, null), receiveLeg) .resolve(REF_DATA); CurrencyAmount pv0 = PRICER_PRODUCT.presentValue(swapPV0, provider()).getAmount(USD); assertEquals(pv0.getAmount(), 0, TOLERANCE_PV); // PV at par rate should be 0 }
@Override public SwapTrade toTrade( TradeInfo tradeInfo, LocalDate startDate, LocalDate endDate, BuySell buySell, double notional, double fixedRate) { Optional<LocalDate> tradeDate = tradeInfo.getTradeDate(); if (tradeDate.isPresent()) { ArgChecker.inOrderOrEqual(tradeDate.get(), startDate, "tradeDate", "startDate"); } SwapLeg leg1 = fixedLeg.toLeg(startDate, endDate, PayReceive.ofPay(buySell.isBuy()), notional, fixedRate); SwapLeg leg2 = floatingLeg.toLeg( startDate, endDate, PayReceive.ofPay(buySell.isSell()), notional); return SwapTrade.builder() .info(tradeInfo) .product(Swap.of(leg1, leg2)) .build(); }
@Override public SwapTrade toTrade( TradeInfo tradeInfo, LocalDate startDate, LocalDate endDate, BuySell buySell, double notional, double spread) { Optional<LocalDate> tradeDate = tradeInfo.getTradeDate(); if (tradeDate.isPresent()) { ArgChecker.inOrderOrEqual(tradeDate.get(), startDate, "tradeDate", "startDate"); } SwapLeg leg1 = spreadLeg.toLeg(startDate, endDate, PayReceive.ofPay(buySell.isBuy()), notional, spread); SwapLeg leg2 = spreadFloatingLeg.toLeg(startDate, endDate, PayReceive.ofPay(buySell.isBuy()), notional); SwapLeg leg3 = flatFloatingLeg.toLeg(startDate, endDate, PayReceive.ofPay(buySell.isSell()), notional); return SwapTrade.builder() .info(tradeInfo) .product(Swap.of(leg1, leg2, leg3)) .build(); }
@Override public SwapTrade toTrade( TradeInfo tradeInfo, LocalDate startDate, LocalDate endDate, BuySell buySell, double notionalSpreadLeg, double notionalFlatLeg, double spread) { Optional<LocalDate> tradeDate = tradeInfo.getTradeDate(); if (tradeDate.isPresent()) { ArgChecker.inOrderOrEqual(tradeDate.get(), startDate, "tradeDate", "startDate"); } SwapLeg leg1 = spreadLeg.toLeg(startDate, endDate, PayReceive.ofPay(buySell.isBuy()), notionalSpreadLeg, spread); SwapLeg leg2 = flatLeg.toLeg(startDate, endDate, PayReceive.ofPay(buySell.isSell()), notionalFlatLeg); return SwapTrade.builder() .info(tradeInfo) .product(Swap.of(leg1, leg2)) .build(); }
@Override public SwapTrade toTrade( TradeInfo tradeInfo, LocalDate startDate, LocalDate endDate, BuySell buySell, double notional, double spread) { Optional<LocalDate> tradeDate = tradeInfo.getTradeDate(); if (tradeDate.isPresent()) { ArgChecker.inOrderOrEqual(tradeDate.get(), startDate, "tradeDate", "startDate"); } SwapLeg leg1 = spreadLeg.toLeg(startDate, endDate, PayReceive.ofPay(buySell.isBuy()), notional, spread); SwapLeg leg2 = flatLeg.toLeg(startDate, endDate, PayReceive.ofPay(buySell.isSell()), notional); return SwapTrade.builder() .info(tradeInfo) .product(Swap.of(leg1, leg2)) .build(); }
@Override public SwapTrade toTrade( TradeInfo tradeInfo, LocalDate startDate, LocalDate endDate, BuySell buySell, double notional, double spread) { Optional<LocalDate> tradeDate = tradeInfo.getTradeDate(); if (tradeDate.isPresent()) { ArgChecker.inOrderOrEqual(tradeDate.get(), startDate, "tradeDate", "startDate"); } SwapLeg leg1 = overnightLeg.toLeg(startDate, endDate, PayReceive.ofPay(buySell.isBuy()), notional, spread); SwapLeg leg2 = iborLeg.toLeg(startDate, endDate, PayReceive.ofPay(buySell.isSell()), notional); return SwapTrade.builder() .info(tradeInfo) .product(Swap.of(leg1, leg2)) .build(); }
@Override public Trade parseTrade(FpmlDocument document, XmlElement tradeEl) { TradeInfoBuilder tradeInfoBuilder = document.parseTradeInfo(tradeEl); Swap swap = parseSwap(document, tradeEl, tradeInfoBuilder); return SwapTrade.builder() .info(tradeInfoBuilder.build()) .product(swap) .build(); }
public void test_serialization() { SwapTrade test = SwapTrade.builder() .info(TRADE_INFO) .product(SWAP1) .build(); assertSerialization(test); }
private static SwapTrade replaceLegs(SwapTrade trade, ImmutableList<SwapLeg> legs) { return trade.toBuilder() .product(trade.getProduct().toBuilder() .legs(legs) .build()) .build(); }