// ------------------------------------------------------------------------- public void test_priceSensitivity() { PointSensitivities point = OPTION_PRICER.priceSensitivityStickyStrike( FUTURE_OPTION_PRODUCT, RATE_PROVIDER, VOL_PROVIDER); CurveCurrencyParameterSensitivities computed = RATE_PROVIDER.curveParameterSensitivity(point); CurveCurrencyParameterSensitivities expected = FD_CAL.sensitivity( RATE_PROVIDER, (p) -> CurrencyAmount.of( EUR, OPTION_PRICER.price(FUTURE_OPTION_PRODUCT, (p), VOL_PROVIDER))); double futurePrice = FUTURE_PRICER.price(FUTURE_OPTION_PRODUCT.getUnderlying(), RATE_PROVIDER); double strike = FUTURE_OPTION_PRODUCT.getStrikePrice(); double expiryTime = ACT_365F.relativeYearFraction(VALUATION_DATE, FUTURE_OPTION_PRODUCT.getExpiryDate()); double logMoneyness = Math.log(strike / futurePrice); double logMoneynessUp = Math.log(strike / (futurePrice + EPS)); double logMoneynessDw = Math.log(strike / (futurePrice - EPS)); double vol = SURFACE.zValue(expiryTime, logMoneyness); double volUp = SURFACE.zValue(expiryTime, logMoneynessUp); double volDw = SURFACE.zValue(expiryTime, logMoneynessDw); double volSensi = 0.5 * (volUp - volDw) / EPS; double vega = BlackFormulaRepository.vega(futurePrice, strike, expiryTime, vol); CurveCurrencyParameterSensitivities sensiVol = RATE_PROVIDER .curveParameterSensitivity( FUTURE_PRICER.priceSensitivity( FUTURE_OPTION_PRODUCT.getUnderlying(), RATE_PROVIDER)) .multipliedBy(-vega * volSensi); expected = expected.combinedWith(sensiVol); assertTrue(computed.equalWithTolerance(expected, 30d * EPS)); }
public void test_priceSensitivity_from_future_price() { double futurePrice = 1.1d; PointSensitivities point = OPTION_PRICER.priceSensitivityStickyStrike( FUTURE_OPTION_PRODUCT, RATE_PROVIDER, VOL_PROVIDER, futurePrice); CurveCurrencyParameterSensitivities computed = RATE_PROVIDER.curveParameterSensitivity(point); double delta = OPTION_PRICER.deltaStickyStrike( FUTURE_OPTION_PRODUCT, RATE_PROVIDER, VOL_PROVIDER, futurePrice); CurveCurrencyParameterSensitivities expected = RATE_PROVIDER .curveParameterSensitivity( FUTURE_PRICER.priceSensitivity( FUTURE_OPTION_PRODUCT.getUnderlying(), RATE_PROVIDER)) .multipliedBy(delta); assertTrue(computed.equalWithTolerance(expected, TOL)); }
public void test_presentValueProductSensitivity_noExcoupon() { PointSensitivityBuilder point = PRICER.presentValueSensitivity(PRODUCT_NO_EXCOUPON, PROVIDER); CurveCurrencyParameterSensitivities computed = PROVIDER.curveParameterSensitivity(point.build()); CurveCurrencyParameterSensitivities expected = FD_CAL.sensitivity(PROVIDER, (p) -> PRICER.presentValue(PRODUCT_NO_EXCOUPON, (p))); assertTrue(computed.equalWithTolerance(expected, 30d * NOTIONAL * EPS)); }
public void test_dirtyPriceSensitivity() { PointSensitivityBuilder point = PRICER.dirtyPriceSensitivity(BOND_SECURITY, PROVIDER); CurveCurrencyParameterSensitivities computed = PROVIDER.curveParameterSensitivity(point.build()); CurveCurrencyParameterSensitivities expected = FD_CAL.sensitivity( PROVIDER, (p) -> CurrencyAmount.of(EUR, PRICER.dirtyPriceFromCurves(BOND_SECURITY, (p)))); assertTrue(computed.equalWithTolerance(expected, NOTIONAL * EPS)); }
public void test_presentValueSensitivityWithZSpread_continuous() { PointSensitivityBuilder point = PRICER.presentValueSensitivityWithZSpread(PRODUCT, PROVIDER, Z_SPREAD, CONTINUOUS, 0); CurveCurrencyParameterSensitivities computed = PROVIDER.curveParameterSensitivity(point.build()); CurveCurrencyParameterSensitivities expected = FD_CAL.sensitivity( PROVIDER, (p) -> PRICER.presentValueWithZSpread(PRODUCT, (p), Z_SPREAD, CONTINUOUS, 0)); assertTrue(computed.equalWithTolerance(expected, 20d * NOTIONAL * EPS)); }
public void test_presentValueSensitivityWithZSpread_periodic_noExcoupon() { PointSensitivityBuilder point = PRICER.presentValueSensitivityWithZSpread( PRODUCT_NO_EXCOUPON, PROVIDER, Z_SPREAD, PERIODIC, PERIOD_PER_YEAR); CurveCurrencyParameterSensitivities computed = PROVIDER.curveParameterSensitivity(point.build()); CurveCurrencyParameterSensitivities expected = FD_CAL.sensitivity( PROVIDER, (p) -> PRICER.presentValueWithZSpread( PRODUCT_NO_EXCOUPON, (p), Z_SPREAD, PERIODIC, PERIOD_PER_YEAR)); assertTrue(computed.equalWithTolerance(expected, 20d * NOTIONAL * EPS)); }
public void test_dirtyPriceSensitivityWithZspread_continuous() { PointSensitivityBuilder point = PRICER.dirtyPriceSensitivityWithZspread(BOND_SECURITY, PROVIDER, Z_SPREAD, CONTINUOUS, 0); CurveCurrencyParameterSensitivities computed = PROVIDER.curveParameterSensitivity(point.build()); CurveCurrencyParameterSensitivities expected = FD_CAL.sensitivity( PROVIDER, (p) -> CurrencyAmount.of( EUR, PRICER.dirtyPriceFromCurvesWithZSpread( BOND_SECURITY, (p), Z_SPREAD, CONTINUOUS, 0))); assertTrue(computed.equalWithTolerance(expected, NOTIONAL * EPS)); }