public void test_of() { ResolvedSwap test = ResolvedSwap.of(LEG1, LEG2); assertEquals(test.getLegs(), ImmutableSet.of(LEG1, LEG2)); assertEquals(test.getLegs(SwapLegType.FIXED), ImmutableList.of(LEG1)); assertEquals(test.getLegs(SwapLegType.IBOR), ImmutableList.of(LEG2)); assertEquals(test.getLeg(PayReceive.PAY), Optional.of(LEG1)); assertEquals(test.getLeg(PayReceive.RECEIVE), Optional.of(LEG2)); assertEquals(test.getPayLeg(), Optional.of(LEG1)); assertEquals(test.getReceiveLeg(), Optional.of(LEG2)); assertEquals(test.getStartDate(), LEG1.getStartDate()); assertEquals(test.getEndDate(), LEG1.getEndDate()); assertEquals(test.isCrossCurrency(), true); assertEquals(test.allPaymentCurrencies(), ImmutableSet.of(GBP, USD)); assertEquals(test.allIndices(), ImmutableSet.of(GBP_LIBOR_3M)); }
@Test(dataProvider = "stubOn") public void test_stub_overnight(OvernightIborSwapConvention convention, Tenor tenor) { LocalDate tradeDate = LocalDate.of(2015, 10, 20); SwapTrade swap = convention.createTrade(tradeDate, tenor, BuySell.BUY, 1, 0.01, REF_DATA); ResolvedSwap swapResolved = swap.getProduct().resolve(REF_DATA); LocalDate endDate = swapResolved.getLeg(PayReceive.PAY).get().getEndDate(); assertTrue(endDate.isAfter(tradeDate.plus(tenor).minusDays(7))); assertTrue(endDate.isBefore(tradeDate.plus(tenor).plusDays(7))); }
public void test_builder() { ResolvedSwapLeg test = ResolvedSwapLeg.builder() .type(IBOR) .payReceive(RECEIVE) .paymentPeriods(RPP1) .paymentEvents(NOTIONAL_EXCHANGE) .build(); assertEquals(test.getType(), IBOR); assertEquals(test.getPayReceive(), RECEIVE); assertEquals(test.getStartDate(), DATE_2014_06_30); assertEquals(test.getEndDate(), DATE_2014_09_30); assertEquals(test.getCurrency(), GBP); assertEquals(test.getPaymentPeriods(), ImmutableList.of(RPP1)); assertEquals(test.getPaymentEvents(), ImmutableList.of(NOTIONAL_EXCHANGE)); }
@Test(dataProvider = "stubIbor") public void test_stub_ibor(ThreeLegBasisSwapConvention convention, Tenor tenor) { LocalDate tradeDate = LocalDate.of(2015, 10, 20); SwapTrade swap = convention.createTrade(tradeDate, tenor, BuySell.BUY, 1, 0.01, REF_DATA); ResolvedSwap swapResolved = swap.getProduct().resolve(REF_DATA); LocalDate endDate = swapResolved.getLeg(PayReceive.PAY).get().getEndDate(); assertTrue(endDate.isAfter(tradeDate.plus(tenor).minusMonths(1))); assertTrue(endDate.isBefore(tradeDate.plus(tenor).plusMonths(1))); }
@Test(dataProvider = "stubOn") public void test_stub_overnight(FixedOvernightSwapConvention convention, Tenor tenor) { LocalDate tradeDate = LocalDate.of(2015, 10, 20); SwapTrade swap = convention.createTrade(tradeDate, tenor, BuySell.BUY, 1, 0.01, REF_DATA); ResolvedSwap swapResolved = swap.getProduct().resolve(REF_DATA); LocalDate endDate = swapResolved.getLeg(PayReceive.PAY).get().getEndDate(); assertTrue(endDate.isAfter(tradeDate.plus(tenor).minusMonths(1))); assertTrue(endDate.isBefore(tradeDate.plus(tenor).plusMonths(1))); }
@Test(dataProvider = "stubIbor") public void test_stub_ibor(IborIborSwapConvention convention, Tenor tenor) { LocalDate tradeDate = LocalDate.of(2015, 10, 20); SwapTrade swap = convention.createTrade(tradeDate, tenor, BuySell.BUY, 1, 0.01, REF_DATA); ResolvedSwap swapResolved = swap.getProduct().resolve(REF_DATA); LocalDate endDate = swapResolved.getLeg(PayReceive.PAY).get().getEndDate(); assertTrue(endDate.isAfter(tradeDate.plus(tenor).minusMonths(1))); assertTrue(endDate.isBefore(tradeDate.plus(tenor).plusMonths(1))); }
@Test(dataProvider = "stubIbor") public void test_stub_ibor(FixedIborSwapConvention convention, Tenor tenor) { LocalDate tradeDate = LocalDate.of(2015, 10, 20); SwapTrade swap = convention.createTrade(tradeDate, tenor, BuySell.BUY, 1, 0.01, REF_DATA); ResolvedSwap swapResolved = swap.getProduct().resolve(REF_DATA); LocalDate endDate = swapResolved.getLeg(PayReceive.PAY).get().getEndDate(); assertTrue(endDate.isAfter(tradeDate.plus(tenor).minusMonths(1))); assertTrue(endDate.isBefore(tradeDate.plus(tenor).plusMonths(1))); }
/** * Computes the implied volatility of the swaption. * * @param swaption the swaption * @param ratesProvider the rates provider * @param swaptionVolatilities the volatilities * @return the implied volatility associated with the swaption */ public double impliedVolatility( ResolvedSwaption swaption, RatesProvider ratesProvider, SwaptionVolatilities swaptionVolatilities) { validate(swaption, ratesProvider, swaptionVolatilities); double expiry = swaptionVolatilities.relativeTime(swaption.getExpiry()); ResolvedSwap underlying = swaption.getUnderlying(); ResolvedSwapLeg fixedLeg = fixedLeg(underlying); ArgChecker.isTrue(expiry >= 0d, "Option must be before expiry to compute an implied volatility"); double forward = getSwapPricer().parRate(underlying, ratesProvider); double strike = calculateStrike(fixedLeg); double tenor = swaptionVolatilities.tenor(fixedLeg.getStartDate(), fixedLeg.getEndDate()); return swaptionVolatilities.volatility(expiry, tenor, strike, forward); }
/** * Computes the implied volatility of the swaption. * * @param swaption the swaption * @param ratesProvider the rates provider * @param swaptionVolatilities the volatilities * @return the implied volatility associated with the swaption */ public double impliedVolatility( ResolvedSwaption swaption, RatesProvider ratesProvider, SwaptionVolatilities swaptionVolatilities) { validate(swaption, ratesProvider, swaptionVolatilities); double expiry = swaptionVolatilities.relativeTime(swaption.getExpiry()); ResolvedSwap underlying = swaption.getUnderlying(); ResolvedSwapLeg fixedLeg = fixedLeg(underlying); ArgChecker.isTrue(expiry >= 0d, "Option must be before expiry to compute an implied volatility"); double forward = getSwapPricer().parRate(underlying, ratesProvider); double pvbp = getSwapPricer().getLegPricer().pvbp(fixedLeg, ratesProvider); double strike = getSwapPricer().getLegPricer().couponEquivalent(fixedLeg, ratesProvider, pvbp); double tenor = swaptionVolatilities.tenor(fixedLeg.getStartDate(), fixedLeg.getEndDate()); return swaptionVolatilities.volatility(expiry, tenor, strike, forward); }
/** * Calculates the present value of the swaption. * <p> * The result is expressed using the currency of the swaption. * * @param swaption the swaption * @param ratesProvider the rates provider * @param swaptionVolatilities the volatilities * @return the present value */ public CurrencyAmount presentValue( ResolvedSwaption swaption, RatesProvider ratesProvider, SwaptionVolatilities swaptionVolatilities) { validate(swaption, ratesProvider, swaptionVolatilities); double expiry = swaptionVolatilities.relativeTime(swaption.getExpiry()); ResolvedSwap underlying = swaption.getUnderlying(); ResolvedSwapLeg fixedLeg = fixedLeg(underlying); if (expiry < 0d) { // Option has expired already return CurrencyAmount.of(fixedLeg.getCurrency(), 0d); } double forward = swapPricer.parRate(underlying, ratesProvider); double pvbp = swapPricer.getLegPricer().pvbp(fixedLeg, ratesProvider); double strike = swapPricer.getLegPricer().couponEquivalent(fixedLeg, ratesProvider, pvbp); double tenor = swaptionVolatilities.tenor(fixedLeg.getStartDate(), fixedLeg.getEndDate()); double volatility = swaptionVolatilities.volatility(expiry, tenor, strike, forward); PutCall putCall = PutCall.ofPut(fixedLeg.getPayReceive().isReceive()); double price = Math.abs(pvbp) * swaptionVolatilities.price(expiry, tenor, putCall, strike, forward, volatility); return CurrencyAmount.of(fixedLeg.getCurrency(), price * swaption.getLongShort().sign()); }
double numeraire = Math.abs(pvbp); double strike = getSwapPricer().getLegPricer().couponEquivalent(fixedLeg, ratesProvider, pvbp); double tenor = swaptionVolatilities.tenor(fixedLeg.getStartDate(), fixedLeg.getEndDate()); double volatility = swaptionVolatilities.volatility(expiry, tenor, strike, forward); PutCall putCall = PutCall.ofPut(fixedLeg.getPayReceive().isReceive());
double numeraire = Math.abs(pvbp); double strike = getSwapPricer().getLegPricer().couponEquivalent(fixedLeg, ratesProvider, pvbp); double tenor = swaptionVolatilities.tenor(fixedLeg.getStartDate(), fixedLeg.getEndDate()); double volatility = swaptionVolatilities.volatility(expiry, tenor, strike, forward); PutCall putCall = PutCall.ofPut(fixedLeg.getPayReceive().isReceive());
double pvbp = getSwapPricer().getLegPricer().pvbp(fixedLeg, ratesProvider); double strike = getSwapPricer().getLegPricer().couponEquivalent(fixedLeg, ratesProvider, pvbp); double tenor = swaptionVolatilities.tenor(fixedLeg.getStartDate(), fixedLeg.getEndDate()); double shift = swaptionVolatilities.shift(expiry, tenor); ValueDerivatives volatilityAdj = swaptionVolatilities.volatilityAdjoint(expiry, tenor, strike, forward);
ResolvedSwap underlying = swaption.getUnderlying(); ResolvedSwapLeg fixedLeg = fixedLeg(underlying); double tenor = swaptionVolatilities.tenor(fixedLeg.getStartDate(), fixedLeg.getEndDate()); double pvbp = getSwapPricer().getLegPricer().pvbp(fixedLeg, ratesProvider); double strike = getSwapPricer().getLegPricer().couponEquivalent(fixedLeg, ratesProvider, pvbp);
/** * Calculates the present value of the swaption. * <p> * The result is expressed using the currency of the swaption. * * @param swaption the swaption * @param ratesProvider the rates provider * @param swaptionVolatilities the volatilities * @return the present value */ public CurrencyAmount presentValue( ResolvedSwaption swaption, RatesProvider ratesProvider, SwaptionVolatilities swaptionVolatilities) { validate(swaption, ratesProvider, swaptionVolatilities); double expiry = swaptionVolatilities.relativeTime(swaption.getExpiry()); ResolvedSwap underlying = swaption.getUnderlying(); ResolvedSwapLeg fixedLeg = fixedLeg(underlying); if (expiry < 0d) { // Option has expired already return CurrencyAmount.of(fixedLeg.getCurrency(), 0d); } double forward = swapPricer.parRate(underlying, ratesProvider); double numeraire = calculateNumeraire(swaption, fixedLeg, forward, ratesProvider); double strike = calculateStrike(fixedLeg); double tenor = swaptionVolatilities.tenor(fixedLeg.getStartDate(), fixedLeg.getEndDate()); double volatility = swaptionVolatilities.volatility(expiry, tenor, strike, forward); PutCall putCall = PutCall.ofPut(fixedLeg.getPayReceive().isReceive()); double price = numeraire * swaptionVolatilities.price(expiry, tenor, putCall, strike, forward, volatility); return CurrencyAmount.of(fixedLeg.getCurrency(), price * swaption.getLongShort().sign()); }
double numeraire = calculateNumeraire(swaption, fixedLeg, forward, ratesProvider); double strike = calculateStrike(fixedLeg); double tenor = swaptionVolatilities.tenor(fixedLeg.getStartDate(), fixedLeg.getEndDate()); double volatility = swaptionVolatilities.volatility(expiry, tenor, strike, forward); PutCall putCall = PutCall.ofPut(fixedLeg.getPayReceive().isReceive());
double numeraire = calculateNumeraire(swaption, fixedLeg, forward, ratesProvider); double strike = calculateStrike(fixedLeg); double tenor = swaptionVolatilities.tenor(fixedLeg.getStartDate(), fixedLeg.getEndDate()); double volatility = swaptionVolatilities.volatility(expiry, tenor, strike, forward); PutCall putCall = PutCall.ofPut(fixedLeg.getPayReceive().isReceive());
double numeraire = calculateNumeraire(swaption, fixedLeg, forward, ratesProvider); double strike = calculateStrike(fixedLeg); double tenor = swaptionVolatilities.tenor(fixedLeg.getStartDate(), fixedLeg.getEndDate()); double volatility = swaptionVolatilities.volatility(expiry, tenor, strike, forward); PutCall putCall = PutCall.ofPut(fixedLeg.getPayReceive().isReceive());
ResolvedSwap underlying = swaption.getUnderlying(); ResolvedSwapLeg fixedLeg = fixedLeg(underlying); double tenor = swaptionVolatilities.tenor(fixedLeg.getStartDate(), fixedLeg.getEndDate()); double strike = calculateStrike(fixedLeg); if (expiry < 0d) { // Option has expired already
ResolvedSwap underlying = swaption.getUnderlying(); ResolvedSwapLeg fixedLeg = fixedLeg(underlying); double tenor = swaptionVolatilities.tenor(fixedLeg.getStartDate(), fixedLeg.getEndDate()); double shift = swaptionVolatilities.shift(expiry, tenor); double strike = calculateStrike(fixedLeg);