public void test_combinedWith() { PointSensitivities test = PointSensitivities.of(Lists.newArrayList(CS2, CS1)); PointSensitivities test2 = PointSensitivities.of(Lists.newArrayList(CS3)); assertEquals(test.combinedWith(test2).getSensitivities(), ImmutableList.of(CS2, CS1, CS3)); }
/** * Calculates the present value sensitivity of the FX swap product. * <p> * The present value sensitivity of the product is the sensitivity of the present value to * the underlying curves. * * @param swap the product * @param provider the rates provider * @return the present value sensitivity */ public PointSensitivities presentValueSensitivity(ResolvedFxSwap swap, RatesProvider provider) { PointSensitivities nearSens = fxPricer.presentValueSensitivity(swap.getNearLeg(), provider); PointSensitivities farSens = fxPricer.presentValueSensitivity(swap.getFarLeg(), provider); return nearSens.combinedWith(farSens); }
public void test_presentValueSensitivity() { PointSensitivities pvSensiTrade = PRICER_TRADE.presentValueSensitivityRatesStickyStrike( OPTION_TRADE, RATES_PROVIDER, VOLS); PointSensitivities pvSensiProduct = PRICER_PRODUCT.presentValueSensitivityRatesStickyStrike( OPTION_PRODUCT, RATES_PROVIDER, VOLS); PointSensitivities pvSensiPremium = PRICER_PAYMENT.presentValueSensitivity(PREMIUM, RATES_PROVIDER).build(); assertEquals(pvSensiTrade, pvSensiProduct.combinedWith(pvSensiPremium)); }
/** * Calculates the present value sensitivity of the FX vanilla option trade. * <p> * The present value sensitivity of the trade is the sensitivity of the present value to * the underlying curves. * <p> * The volatility is fixed in this sensitivity computation. * * @param trade the option trade * @param ratesProvider the rates provider * @param volatilities the Black volatility provider * @return the present value curve sensitivity of the trade */ public PointSensitivities presentValueSensitivityRatesStickyStrike( ResolvedFxVanillaOptionTrade trade, RatesProvider ratesProvider, BlackFxOptionVolatilities volatilities) { ResolvedFxVanillaOption product = trade.getProduct(); PointSensitivities pvcsProduct = productPricer.presentValueSensitivityRatesStickyStrike(product, ratesProvider, volatilities); Payment premium = trade.getPremium(); PointSensitivities pvcsPremium = paymentPricer.presentValueSensitivity(premium, ratesProvider).build(); return pvcsProduct.combinedWith(pvcsPremium); }
public void test_presentValueSensitivity() { PointSensitivities pvSensiTrade = PRICER_TRADE.presentValueSensitivityRatesStickyStrike(OPTION_TRADE, RATES_PROVIDER, VOLS); PointSensitivities pvSensiProduct = PRICER_PRODUCT.presentValueSensitivityRatesStickyStrike(OPTION_PRODUCT, RATES_PROVIDER, VOLS).build(); PointSensitivities pvSensiPremium = PRICER_PAYMENT.presentValueSensitivity(PREMIUM, RATES_PROVIDER).build(); assertEquals(pvSensiTrade, pvSensiProduct.combinedWith(pvSensiPremium)); }
/** * Calculates the present value sensitivity of the FX vanilla option trade. * <p> * The present value sensitivity of the trade is the sensitivity of the present value to * the underlying curves. * <p> * The volatility is fixed in this sensitivity computation. * * @param trade the option trade * @param ratesProvider the rates provider * @param volatilities the Black volatility provider * @return the present value curve sensitivity of the trade */ public PointSensitivities presentValueSensitivityRatesStickyStrike( ResolvedFxVanillaOptionTrade trade, RatesProvider ratesProvider, BlackFxOptionSmileVolatilities volatilities) { ResolvedFxVanillaOption product = trade.getProduct(); PointSensitivities pvcsProduct = productPricer.presentValueSensitivityRatesStickyStrike(product, ratesProvider, volatilities).build(); Payment premium = trade.getPremium(); PointSensitivities pvcsPremium = paymentPricer.presentValueSensitivity(premium, ratesProvider).build(); return pvcsProduct.combinedWith(pvcsPremium); }
public void test_presentValueSensitivity() { PointSensitivities computedWithPayLeg = PRICER.presentValueSensitivityRates(TRADE_PAYLEG, RATES, VOLS); PointSensitivities computedWithPremium = PRICER.presentValueSensitivityRates(TRADE_PREMIUM, RATES, VOLS); PointSensitivities pvOneLeg = PRICER_PRODUCT.presentValueSensitivityRates(CAP_ONE_LEG, RATES, VOLS).build(); PointSensitivities pvTwoLegs = PRICER_PRODUCT.presentValueSensitivityRates(CAP_TWO_LEGS, RATES, VOLS).build(); PointSensitivities pvPrem = PRICER_PREMIUM.presentValueSensitivity(PREMIUM, RATES).build(); assertEquals(computedWithPayLeg, pvTwoLegs); assertEquals(computedWithPremium, pvOneLeg.combinedWith(pvPrem)); }
public void test_presentValueSensitivityRatesStickyModel() { PointSensitivities computedWithPayLeg = PRICER.presentValueSensitivityRatesStickyModel(TRADE_PAYLEG, RATES, VOLS); PointSensitivities computedWithPremium = PRICER.presentValueSensitivityRatesStickyModel(TRADE_PREMIUM, RATES, VOLS); PointSensitivities pvOneLeg = PRICER_PRODUCT.presentValueSensitivityRatesStickyModel(CAP_ONE_LEG, RATES, VOLS).build(); PointSensitivities pvTwoLegs = PRICER_PRODUCT.presentValueSensitivityRatesStickyModel(CAP_TWO_LEGS, RATES, VOLS).build(); PointSensitivities pvPrem = PRICER_PREMIUM.presentValueSensitivity(PREMIUM, RATES).build(); assertEquals(computedWithPayLeg, pvTwoLegs); assertEquals(computedWithPremium, pvOneLeg.combinedWith(pvPrem)); }
public void test_presentValueSensitivity() { PointSensitivities computedWithPayLeg = PRICER.presentValueSensitivityRates(TRADE_PAYLEG, RATES, VOLS); PointSensitivities computedWithPremium = PRICER.presentValueSensitivityRates(TRADE_PREMIUM, RATES, VOLS); PointSensitivities pvOneLeg = PRICER_PRODUCT.presentValueSensitivityRates(CAP_ONE_LEG, RATES, VOLS).build(); PointSensitivities pvTwoLegs = PRICER_PRODUCT.presentValueSensitivityRates(CAP_TWO_LEGS, RATES, VOLS).build(); PointSensitivities pvPrem = PRICER_PREMIUM.presentValueSensitivity(PREMIUM, RATES).build(); assertEquals(computedWithPayLeg, pvTwoLegs); assertEquals(computedWithPremium, pvOneLeg.combinedWith(pvPrem)); }
public void test_presentValueSensitivity() { ResolvedSwapLeg expSwapLeg = IBOR_SWAP_LEG_REC_GBP; Currency ccy = GBP_LIBOR_3M.getCurrency(); IborRateSensitivity fwdSense = IborRateSensitivity.of(IBOR_RATE_COMP.getObservation(), 140.0); ZeroRateSensitivity dscSense = ZeroRateSensitivity.of(ccy, 3d, -162.0); PointSensitivityBuilder sensiPeriod = fwdSense.combinedWith(dscSense); PointSensitivityBuilder sensiEvent = ZeroRateSensitivity.of(ccy, 4d, -134.0); PointSensitivities expected = sensiPeriod.build().combinedWith(sensiEvent.build()); SwapPaymentPeriodPricer<SwapPaymentPeriod> mockPeriod = mock(SwapPaymentPeriodPricer.class); SwapPaymentEventPricer<SwapPaymentEvent> mockEvent = mock(SwapPaymentEventPricer.class); when(mockPeriod.presentValueSensitivity(expSwapLeg.getPaymentPeriods().get(0), MOCK_PROV)) .thenReturn(sensiPeriod); when(mockEvent.presentValueSensitivity(expSwapLeg.getPaymentEvents().get(0), MOCK_PROV)) .thenReturn(sensiEvent); DiscountingSwapLegPricer test = new DiscountingSwapLegPricer(mockPeriod, mockEvent); PointSensitivities res = test.presentValueSensitivity(expSwapLeg, MOCK_PROV).build(); assertTrue(res.equalWithTolerance(expected, TOLERANCE)); }
/** * Calculates the present value sensitivity of a bill trade. * <p> * If the settlement details are provided, the sensitivity is the sum of the underlying product's sensitivity * multiplied by the quantity and the sensitivity of the settlement payment if still due at the valuation date. * If not it is the underlying product's sensitivity multiplied by the quantity. * * @param trade the trade * @param provider the discounting provider * @return the present value sensitivity */ public PointSensitivities presentValueSensitivity(ResolvedBillTrade trade, LegalEntityDiscountingProvider provider) { if (provider.getValuationDate().isAfter(trade.getProduct().getNotional().getDate())) { return PointSensitivities.empty(); } PointSensitivities sensiProduct = productPricer.presentValueSensitivity(trade.getProduct(), provider) .multipliedBy(trade.getQuantity()); if (!trade.getSettlement().isPresent()) { return sensiProduct; } Payment settlement = trade.getSettlement().get(); RepoCurveDiscountFactors repoDf = DiscountingBillProductPricer.repoCurveDf(trade.getProduct(), provider); PointSensitivities sensiSettle = presentValueSensitivitySettlement(settlement, repoDf); return sensiProduct.combinedWith(sensiSettle); }
PointSensitivityBuilder sensiEvent = ZeroRateSensitivity.of(ccy, 4d, -134.0); PointSensitivities expected = sensiFloating.build() .combinedWith(sensiEvent.build()) .combinedWith(sensiFixed.build()) .combinedWith(sensiEvent.build());
public void test_pvsensi_settle_on_val() { PointSensitivities pvsensiComputed = PRICER_TRADE.presentValueSensitivity(BILL_TRADE_SETTLE_ON_VAL, PROVIDER); PointSensitivities pvsensiExpected = PRICER_PRODUCT.presentValueSensitivity(BILL_PRODUCT.resolve(REF_DATA), PROVIDER) .multipliedBy(QUANTITY) .combinedWith(RepoCurveZeroRateSensitivity.of( (ZeroRateSensitivity) PRICER_PAYMENT.presentValueSensitivity( BILL_TRADE_SETTLE_ON_VAL.getSettlement().get(), PROVIDER.repoCurveDiscountFactors( BILL_PRODUCT.getSecurityId(), BILL_PRODUCT.getLegalEntityId(), BILL_PRODUCT.getCurrency()) .getDiscountFactors()), GROUP_REPO).build()); assertTrue(pvsensiComputed.equalWithTolerance(pvsensiExpected, TOLERANCE_PVSENSI)); CurrencyParameterSensitivities paramSensiComputed = PROVIDER.parameterSensitivity(pvsensiComputed); CurrencyParameterSensitivities paramSensiExpected = FD_CALC.sensitivity( PROVIDER, p -> PRICER_TRADE.presentValue(BILL_TRADE_SETTLE_ON_VAL, p)); assertTrue(paramSensiComputed.equalWithTolerance(paramSensiExpected, EPS * NOTIONAL_AMOUNT * QUANTITY)); }
public void test_pvsensi_settle_after_val() { PointSensitivities pvsensiComputed = PRICER_TRADE.presentValueSensitivity(BILL_TRADE_SETTLE_AFTER_VAL, PROVIDER); PointSensitivities pvsensiExpected = PRICER_PRODUCT.presentValueSensitivity(BILL_PRODUCT.resolve(REF_DATA), PROVIDER) .multipliedBy(QUANTITY) .combinedWith(RepoCurveZeroRateSensitivity.of( (ZeroRateSensitivity) PRICER_PAYMENT.presentValueSensitivity( BILL_TRADE_SETTLE_AFTER_VAL.getSettlement().get(), PROVIDER.repoCurveDiscountFactors( BILL_PRODUCT.getSecurityId(), BILL_PRODUCT.getLegalEntityId(), BILL_PRODUCT.getCurrency()) .getDiscountFactors()), GROUP_REPO).build()); assertTrue(pvsensiComputed.equalWithTolerance(pvsensiExpected, TOLERANCE_PVSENSI)); CurrencyParameterSensitivities paramSensiComputed = PROVIDER.parameterSensitivity(pvsensiComputed); CurrencyParameterSensitivities paramSensiExpected = FD_CALC.sensitivity( PROVIDER, p -> PRICER_TRADE.presentValue(BILL_TRADE_SETTLE_AFTER_VAL, p)); assertTrue(paramSensiComputed.equalWithTolerance(paramSensiExpected, EPS * NOTIONAL_AMOUNT * QUANTITY)); }
public void presentValueSensitivity_beforeFixing_coupon() { PointSensitivities pv = PRICER_CMS.presentValueSensitivity(COUPON, RATES_PROVIDER).build(); double df = RATES_PROVIDER.discountFactor(EUR, PAYMENT); ZeroRateSensitivity dfdr = RATES_PROVIDER.discountFactors(EUR).zeroRatePointSensitivity(PAYMENT); double forward = PRICER_SWAP.parRate(COUPON.getUnderlyingSwap(), RATES_PROVIDER); PointSensitivities forwarddr = PRICER_SWAP.parRateSensitivity(COUPON.getUnderlyingSwap(), RATES_PROVIDER).build(); PointSensitivities expected = forwarddr.multipliedBy(df).combinedWith(dfdr.multipliedBy(forward).build()) .multipliedBy(NOTIONAL * ACC_FACTOR); assertTrue(pv.equalWithTolerance(expected, TOLERANCE_DELTA)); }
public void presentValueSensitivity_onFix_nots() { PointSensitivities pv = PRICER_CMS.presentValueSensitivity(COUPON, RATES_PROVIDER_ON_FIX).build(); double df = RATES_PROVIDER_ON_FIX.discountFactor(EUR, PAYMENT); ZeroRateSensitivity dfdr = RATES_PROVIDER_ON_FIX.discountFactors(EUR).zeroRatePointSensitivity(PAYMENT); double forward = PRICER_SWAP.parRate(COUPON.getUnderlyingSwap(), RATES_PROVIDER_ON_FIX); PointSensitivities forwarddr = PRICER_SWAP.parRateSensitivity(COUPON.getUnderlyingSwap(), RATES_PROVIDER_ON_FIX).build(); PointSensitivities expected = forwarddr.multipliedBy(df).combinedWith(dfdr.multipliedBy(forward).build()) .multipliedBy(NOTIONAL * ACC_FACTOR); assertTrue(pv.equalWithTolerance(expected, TOLERANCE_DELTA)); }
public void test_pvsensiZSpread_settle_on_val() { PointSensitivities pvsensiComputed = PRICER_TRADE .presentValueSensitivityWithZSpread(BILL_TRADE_SETTLE_ON_VAL, PROVIDER, Z_SPREAD, CompoundedRateType.CONTINUOUS, 0); PointSensitivities pvsensiExpected = PRICER_PRODUCT .presentValueSensitivityWithZSpread(BILL_PRODUCT.resolve(REF_DATA), PROVIDER, Z_SPREAD, CompoundedRateType.CONTINUOUS, 0) .multipliedBy(QUANTITY) .combinedWith(RepoCurveZeroRateSensitivity.of( (ZeroRateSensitivity) PRICER_PAYMENT.presentValueSensitivity( BILL_TRADE_SETTLE_ON_VAL.getSettlement().get(), PROVIDER.repoCurveDiscountFactors( BILL_PRODUCT.getSecurityId(), BILL_PRODUCT.getLegalEntityId(), BILL_PRODUCT.getCurrency()) .getDiscountFactors()), GROUP_REPO).build()); assertTrue(pvsensiComputed.equalWithTolerance(pvsensiExpected, TOLERANCE_PVSENSI)); CurrencyParameterSensitivities paramSensiComputed = PROVIDER.parameterSensitivity(pvsensiComputed); CurrencyParameterSensitivities paramSensiExpected = FD_CALC.sensitivity( PROVIDER, p -> PRICER_TRADE.presentValueWithZSpread(BILL_TRADE_SETTLE_ON_VAL, p, Z_SPREAD, CompoundedRateType.CONTINUOUS, 0)); assertTrue(paramSensiComputed.equalWithTolerance(paramSensiExpected, EPS * NOTIONAL_AMOUNT * QUANTITY)); }
public void test_pvsensiZSpread_settle_after_val() { PointSensitivities pvsensiComputed = PRICER_TRADE .presentValueSensitivityWithZSpread(BILL_TRADE_SETTLE_AFTER_VAL, PROVIDER, Z_SPREAD, CompoundedRateType.CONTINUOUS, 0); PointSensitivities pvsensiExpected = PRICER_PRODUCT .presentValueSensitivityWithZSpread(BILL_PRODUCT.resolve(REF_DATA), PROVIDER, Z_SPREAD, CompoundedRateType.CONTINUOUS, 0) .multipliedBy(QUANTITY) .combinedWith(RepoCurveZeroRateSensitivity.of( (ZeroRateSensitivity) PRICER_PAYMENT.presentValueSensitivity( BILL_TRADE_SETTLE_AFTER_VAL.getSettlement().get(), PROVIDER.repoCurveDiscountFactors( BILL_PRODUCT.getSecurityId(), BILL_PRODUCT.getLegalEntityId(), BILL_PRODUCT.getCurrency()) .getDiscountFactors()), GROUP_REPO).build()); assertTrue(pvsensiComputed.equalWithTolerance(pvsensiExpected, TOLERANCE_PVSENSI)); CurrencyParameterSensitivities paramSensiComputed = PROVIDER.parameterSensitivity(pvsensiComputed); CurrencyParameterSensitivities paramSensiExpected = FD_CALC.sensitivity( PROVIDER, p -> PRICER_TRADE.presentValueWithZSpread(BILL_TRADE_SETTLE_AFTER_VAL, p, Z_SPREAD, CompoundedRateType.CONTINUOUS, 0)); assertTrue(paramSensiComputed.equalWithTolerance(paramSensiExpected, EPS * NOTIONAL_AMOUNT * QUANTITY)); }
/** * Calculates the par spread sensitivity to the curves. * <p> * The sensitivity is reported in the counter currency of the product, but is actually dimensionless. * * @param swap the product * @param provider the rates provider * @return the spread curve sensitivity */ public PointSensitivities parSpreadSensitivity(ResolvedFxSwap swap, RatesProvider provider) { Payment counterPaymentNear = swap.getNearLeg().getCounterCurrencyPayment(); MultiCurrencyAmount pv = presentValue(swap, provider); double pvCounterCcy = pv.convertedTo(counterPaymentNear.getCurrency(), provider).getAmount(); double dfEnd = provider.discountFactor(counterPaymentNear.getCurrency(), swap.getFarLeg().getPaymentDate()); double notionalBaseCcy = swap.getNearLeg().getBaseCurrencyPayment().getAmount(); double ps = -pvCounterCcy / (notionalBaseCcy * dfEnd); // backward sweep double psBar = 1d; double pvCounterCcyBar = -1d / (notionalBaseCcy * dfEnd) * psBar; double dfEndBar = -ps / dfEnd * psBar; ZeroRateSensitivity ddfEnddr = provider.discountFactors(counterPaymentNear.getCurrency()) .zeroRatePointSensitivity(swap.getFarLeg().getPaymentDate()); PointSensitivities result = ddfEnddr.multipliedBy(dfEndBar).build(); PointSensitivities dpvdr = presentValueSensitivity(swap, provider); PointSensitivities dpvdrConverted = dpvdr.convertedTo(counterPaymentNear.getCurrency(), provider); return result.combinedWith(dpvdrConverted.multipliedBy(pvCounterCcyBar)); }
public void test_presentValueSensitivity_dateLogic_noExcoupon() { ResolvedFixedCouponBondTrade tradeAfter = ResolvedFixedCouponBondTrade.builder() .product(PRODUCT_NO_EXCOUPON) .quantity(QUANTITY) .settlement(ResolvedFixedCouponBondSettlement.of(SETTLEMENT, CLEAN_PRICE)) .build(); PointSensitivities computedTradeAfter = TRADE_PRICER_NO_UPFRONT.presentValueSensitivity(tradeAfter, PROVIDER_BEFORE); // settle before coupon date ResolvedFixedCouponBondTrade tradeBefore = ResolvedFixedCouponBondTrade.builder() .product(PRODUCT_NO_EXCOUPON) .quantity(QUANTITY) .settlement(ResolvedFixedCouponBondSettlement.of(SETTLE_BEFORE, CLEAN_PRICE)) .build(); PointSensitivities computedTradeBefore = TRADE_PRICER_NO_UPFRONT.presentValueSensitivity(tradeBefore, PROVIDER_BEFORE); FixedCouponBondPaymentPeriod periodExtra = findPeriod(PRODUCT_NO_EXCOUPON, SETTLE_BEFORE, SETTLEMENT); PointSensitivities sensiExtra = COUPON_PRICER .presentValueSensitivity(periodExtra, PROVIDER_BEFORE.issuerCurveDiscountFactors(ISSUER_ID, EUR)).build(); assertTrue(computedTradeBefore.normalized().equalWithTolerance( computedTradeAfter.combinedWith(sensiExtra.multipliedBy(QUANTITY)).normalized(), NOTIONAL * QUANTITY * TOL)); // settle on coupon date ResolvedFixedCouponBondTrade tradeOnCoupon = ResolvedFixedCouponBondTrade.builder() .product(PRODUCT_NO_EXCOUPON) .quantity(QUANTITY) .settlement(ResolvedFixedCouponBondSettlement.of(SETTLE_ON_COUPON, CLEAN_PRICE)) .build(); PointSensitivities computedTradeOnCoupon = TRADE_PRICER_NO_UPFRONT.presentValueSensitivity(tradeOnCoupon, PROVIDER_BEFORE); assertTrue(computedTradeOnCoupon.equalWithTolerance(computedTradeAfter, NOTIONAL * QUANTITY * TOL)); }