/** * Calculates the margin index sensitivity of the bond future product. * <p> * The margin index sensitivity is the sensitivity of the margin index to the underlying curves. * For two consecutive settlement prices C1 and C2, the daily margin is computed as * {@code (marginIndex(future, C2) - marginIndex(future, C1))}. * * @param future the future * @param priceSensitivity the price sensitivity of the product * @return the index sensitivity */ PointSensitivities marginIndexSensitivity(ResolvedBondFuture future, PointSensitivities priceSensitivity) { return priceSensitivity.multipliedBy(future.getNotional()); }
/** * Calculates the margin index sensitivity of the Ibor future product. * <p> * The margin index sensitivity is the sensitivity of the margin index to the underlying curves. * For two consecutive settlement prices C1 and C2, the daily margin is computed as * {@code (marginIndex(future, C2) - marginIndex(future, C1))}. * * @param future the future * @param priceSensitivity the price sensitivity of the product * @return the index sensitivity */ PointSensitivities marginIndexSensitivity(ResolvedIborFuture future, PointSensitivities priceSensitivity) { return priceSensitivity.multipliedBy(future.getNotional() * future.getAccrualFactor()); }
/** * Calculates the margin index sensitivity of the Overnight rate future product. * <p> * The margin index sensitivity is the sensitivity of the margin index to the underlying curves. * For two consecutive settlement prices C1 and C2, the daily margin is computed as * {@code (marginIndex(future, C2) - marginIndex(future, C1))}. * * @param future the future * @param priceSensitivity the price sensitivity of the product * @return the index sensitivity */ PointSensitivities marginIndexSensitivity(ResolvedOvernightFuture future, PointSensitivities priceSensitivity) { return priceSensitivity.multipliedBy(future.getNotional() * future.getAccrualFactor()); }
/** * Calculates the margin index sensitivity of the Ibor future product. * <p> * The margin index sensitivity is the sensitivity of the margin index to the underlying curves. * For two consecutive settlement prices C1 and C2, the daily margin is computed as * {@code (marginIndex(future, C2) - marginIndex(future, C1))}. * * @param future the future * @param priceSensitivity the price sensitivity of the product * @return the index sensitivity */ PointSensitivities marginIndexSensitivity(ResolvedIborFuture future, PointSensitivities priceSensitivity) { return priceSensitivity.multipliedBy(future.getNotional() * future.getAccrualFactor()); }
/** * Calculates the margin index sensitivity of the bond future product. * <p> * For two consecutive settlement prices C1 and C2, the daily margin is computed as * {@code marginIndex(future, C2) - marginIndex(future, C1)}. * The margin index sensitivity if the sensitivity of the margin index to the underlying curves. * * @param option the option product * @param priceSensitivity the price sensitivity of the product * @return the index sensitivity */ PointSensitivities marginIndexSensitivity(ResolvedBondFutureOption option, PointSensitivities priceSensitivity) { double notional = option.getUnderlyingFuture().getNotional(); return priceSensitivity.multipliedBy(notional); }
/** * Calculates the present value sensitivity of the deliverable swap futures trade. * <p> * The present value sensitivity of the trade is the sensitivity of the present value to * the underlying curves. * * @param trade the trade * @param ratesProvider the rates provider * @return the present value curve sensitivity of the trade */ public PointSensitivities presentValueSensitivity(ResolvedDsfTrade trade, RatesProvider ratesProvider) { ResolvedDsf product = trade.getProduct(); PointSensitivities priceSensi = productPricer.priceSensitivity(product, ratesProvider); PointSensitivities marginIndexSensi = productPricer.marginIndexSensitivity(product, priceSensi); return marginIndexSensi.multipliedBy(trade.getQuantity()); }
public void test_multipliedBy() { PointSensitivities test = PointSensitivities.of(Lists.newArrayList(CS3, CS2, CS1)); assertEquals( test.multipliedBy(2d).getSensitivities(), ImmutableList.of(CS3.withSensitivity(64d), CS2.withSensitivity(44d), CS1.withSensitivity(24d))); }
public void test_marginIndexSensitivity() { PointSensitivities point = OPTION_PRICER.priceSensitivityRatesStickyStrike( FUTURE_OPTION_PRODUCT, RATE_PROVIDER, VOLS); PointSensitivities computed = OPTION_PRICER.marginIndexSensitivity(FUTURE_OPTION_PRODUCT, point); assertEquals(computed, point.multipliedBy(FUTURE_OPTION_PRODUCT.getUnderlyingFuture().getNotional())); }
public void test_marginIndexSensitivity() { double notional = FUTURE.getNotional(); double accrualFactor = FUTURE.getAccrualFactor(); PointSensitivities priceSensitivity = PRICER.priceSensitivity(FUTURE, RATES_PROVIDER); PointSensitivities sensiComputed = PRICER.marginIndexSensitivity(FUTURE, priceSensitivity); assertTrue(sensiComputed.equalWithTolerance(priceSensitivity.multipliedBy(accrualFactor * notional), TOL * notional)); }
public void presentValueSensitivity_afterFix() { PointSensitivities ptsCpn = PRICER_CMS.presentValueSensitivity(COUPON, RATES_PROVIDER_AFTER_FIX).build(); PointSensitivities ptsCapletOtm = PRICER_CMS.presentValueSensitivity(CAPLET, RATES_PROVIDER_AFTER_FIX).build(); PointSensitivities ptsCapletItm = PRICER_CMS.presentValueSensitivity(CAPLET_NEGATIVE, RATES_PROVIDER_AFTER_FIX).build(); PointSensitivities ptsFloorletItm = PRICER_CMS.presentValueSensitivity(FLOORLET, RATES_PROVIDER_AFTER_FIX).build(); PointSensitivities ptsFloorletOtm = PRICER_CMS.presentValueSensitivity(FLOORLET_NEGATIVE, RATES_PROVIDER_AFTER_FIX).build(); double factor = NOTIONAL * COUPON.getYearFraction(); ZeroRateSensitivity pts = RATES_PROVIDER_AFTER_FIX.discountFactors(EUR).zeroRatePointSensitivity(PAYMENT); assertTrue(ptsCpn.equalWithTolerance(pts.build().multipliedBy(factor * OBS_INDEX), TOLERANCE_DELTA)); assertTrue(ptsCapletOtm.equalWithTolerance(pts.build().multipliedBy(0d), TOLERANCE_DELTA)); assertTrue(ptsCapletItm.equalWithTolerance(pts.build().multipliedBy(factor * (OBS_INDEX - STRIKE_NEGATIVE)), TOLERANCE_DELTA)); assertTrue(ptsFloorletItm.equalWithTolerance(pts.build().multipliedBy(factor * (STRIKE - OBS_INDEX)), TOLERANCE_DELTA)); assertTrue(ptsFloorletOtm.equalWithTolerance(pts.build().multipliedBy(0d), TOLERANCE_DELTA)); }
public void presentValueSensitivity_onFix_ts() { PointSensitivities ptsCpn = PRICER_CMS.presentValueSensitivity(COUPON, RATES_PROVIDER_ON_FIX_TS).build(); PointSensitivities ptsCapletOtm = PRICER_CMS.presentValueSensitivity(CAPLET, RATES_PROVIDER_ON_FIX_TS).build(); PointSensitivities ptsCapletItm = PRICER_CMS.presentValueSensitivity(CAPLET_NEGATIVE, RATES_PROVIDER_ON_FIX_TS).build(); PointSensitivities ptsFloorletItm = PRICER_CMS.presentValueSensitivity(FLOORLET, RATES_PROVIDER_ON_FIX_TS).build(); PointSensitivities ptsFloorletOtm = PRICER_CMS.presentValueSensitivity(FLOORLET_NEGATIVE, RATES_PROVIDER_ON_FIX_TS).build(); double factor = NOTIONAL * COUPON.getYearFraction(); ZeroRateSensitivity pts = RATES_PROVIDER_ON_FIX_TS.discountFactors(EUR).zeroRatePointSensitivity(PAYMENT); assertTrue(ptsCpn.equalWithTolerance(pts.build().multipliedBy(factor * OBS_INDEX), TOLERANCE_DELTA)); assertTrue(ptsCapletOtm.equalWithTolerance(pts.build().multipliedBy(0d), TOLERANCE_DELTA)); assertTrue(ptsCapletItm.equalWithTolerance(pts.build().multipliedBy(factor * (OBS_INDEX - STRIKE_NEGATIVE)), TOLERANCE_DELTA)); assertTrue(ptsFloorletItm.equalWithTolerance(pts.build().multipliedBy(factor * (STRIKE - OBS_INDEX)), TOLERANCE_DELTA)); assertTrue(ptsFloorletOtm.equalWithTolerance(pts.build().multipliedBy(0d), TOLERANCE_DELTA)); }
public void presentValueSensitivity_from_env() { IborIndexRates mockIbor = mock(IborIndexRates.class); SimpleRatesProvider prov = new SimpleRatesProvider(); prov.setIborRates(mockIbor); when(mockIbor.rate(OPTION.getUnderlyingFuture().getIborRate().getObservation())).thenReturn(RATE); PointSensitivities psProduct = OPTION_PRODUCT_PRICER.priceSensitivityRatesStickyStrike(OPTION, prov, VOL_SIMPLE_MONEY_PRICE); PointSensitivities psExpected = psProduct .multipliedBy(OPTION_PRODUCT_PRICER.marginIndex(OPTION, 1) * OPTION_QUANTITY); PointSensitivities psComputed = OPTION_TRADE_PRICER .presentValueSensitivityRates(FUTURE_OPTION_TRADE, prov, VOL_SIMPLE_MONEY_PRICE); assertTrue(psComputed.equalWithTolerance(psExpected, TOLERANCE_PV_DELTA)); }
public void test_presentValueSensitivity() { IborIndexRates mockIbor = mock(IborIndexRates.class); SimpleRatesProvider prov = new SimpleRatesProvider(); prov.setIborRates(mockIbor); PointSensitivities sensiPrice = PRICER_PRODUCT.priceSensitivity(FUTURE, prov); PointSensitivities sensiPresentValueExpected = sensiPrice.multipliedBy( FUTURE.getNotional() * FUTURE.getAccrualFactor() * FUTURE_TRADE.getQuantity()); PointSensitivities sensiPresentValueComputed = PRICER_TRADE.presentValueSensitivity(FUTURE_TRADE, prov); assertTrue(sensiPresentValueComputed.equalWithTolerance(sensiPresentValueExpected, TOLERANCE_PV_DELTA)); }
public void test_pvsensi_settle_before_val() { PointSensitivities pvsensiComputed = PRICER_TRADE.presentValueSensitivity(BILL_TRADE_SETTLE_BEFORE_VAL, PROVIDER); PointSensitivities pvsensiExpected = PRICER_PRODUCT.presentValueSensitivity(BILL_PRODUCT.resolve(REF_DATA), PROVIDER) .multipliedBy(QUANTITY); assertTrue(pvsensiComputed.equalWithTolerance(pvsensiExpected, TOLERANCE_PVSENSI)); CurrencyParameterSensitivities paramSensiComputed = PROVIDER.parameterSensitivity(pvsensiComputed); CurrencyParameterSensitivities paramSensiExpected = FD_CALC.sensitivity( PROVIDER, p -> PRICER_TRADE.presentValue(BILL_TRADE_SETTLE_BEFORE_VAL, p)); assertTrue(paramSensiComputed.equalWithTolerance(paramSensiExpected, EPS * NOTIONAL_AMOUNT * QUANTITY)); }
public void priceSensitivityStickyStrike_from_future_price() { IborIndexRates mockIbor = mock(IborIndexRates.class); SimpleRatesProvider prov = new SimpleRatesProvider(); prov.setIborRates(mockIbor); when(mockIbor.rate(OPTION.getUnderlyingFuture().getIborRate().getObservation())).thenReturn(RATE); double futurePrice = 0.9875; PointSensitivities futurePriceSensitivity = FUTURE_PRICER.priceSensitivity(OPTION.getUnderlyingFuture(), prov); double delta = OPTION_PRICER.deltaStickyStrike(OPTION, prov, VOL_SIMPLE_MONEY_PRICE, futurePrice); PointSensitivities optionPriceSensitivityExpected = futurePriceSensitivity.multipliedBy(delta); PointSensitivities optionPriceSensitivityComputed = OPTION_PRICER.priceSensitivityRatesStickyStrike(OPTION, prov, VOL_SIMPLE_MONEY_PRICE, futurePrice); assertTrue(optionPriceSensitivityExpected.equalWithTolerance(optionPriceSensitivityComputed, TOLERANCE_PRICE_DELTA)); }
public void test_pvsensiZSpread_settle_before_val() { PointSensitivities pvsensiComputed = PRICER_TRADE .presentValueSensitivityWithZSpread(BILL_TRADE_SETTLE_BEFORE_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); assertTrue(pvsensiComputed.equalWithTolerance(pvsensiExpected, TOLERANCE_PVSENSI)); CurrencyParameterSensitivities paramSensiComputed = PROVIDER.parameterSensitivity(pvsensiComputed); CurrencyParameterSensitivities paramSensiExpected = FD_CALC.sensitivity( PROVIDER, p -> PRICER_TRADE.presentValueWithZSpread(BILL_TRADE_SETTLE_BEFORE_VAL, p, Z_SPREAD, CompoundedRateType.CONTINUOUS, 0)); assertTrue(paramSensiComputed.equalWithTolerance(paramSensiExpected, EPS * NOTIONAL_AMOUNT * QUANTITY)); }
public void test_presentValueSensitivity() { PointSensitivities computed = PRICER_TRADE.presentValueSensitivity(RESOLVED_TRADE, RATES_PROVIDER); PointSensitivities expected = PRICER_PRODUCT.priceSensitivity(RESOLVED_TRADE.getProduct(), RATES_PROVIDER) .multipliedBy(FUTURE.getNotional() * FUTURE.getAccrualFactor() * RESOLVED_TRADE.getQuantity()); assertTrue(computed.equalWithTolerance(expected, NOTIONAL * TOL)); }
public void priceSensitivityStickyStrike_from_env() { IborIndexRates mockIbor = mock(IborIndexRates.class); SimpleRatesProvider prov = new SimpleRatesProvider(); prov.setIborRates(mockIbor); when(mockIbor.rate(OPTION.getUnderlyingFuture().getIborRate().getObservation())).thenReturn(RATE); PointSensitivities futurePriceSensitivity = OPTION_PRICER.getFuturePricer() .priceSensitivity(OPTION.getUnderlyingFuture(), prov); double delta = OPTION_PRICER.deltaStickyStrike(OPTION, prov, VOL_SIMPLE_MONEY_PRICE); PointSensitivities optionPriceSensitivityExpected = futurePriceSensitivity.multipliedBy(delta); PointSensitivities optionPriceSensitivityComputed = OPTION_PRICER.priceSensitivityRatesStickyStrike(OPTION, prov, VOL_SIMPLE_MONEY_PRICE); assertTrue(optionPriceSensitivityExpected.equalWithTolerance(optionPriceSensitivityComputed, TOLERANCE_PRICE_DELTA)); }
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)); }