// ------------------------------------------------------------------------- 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() { PointSensitivities point = FUTURE_PRICER.priceSensitivity(FUTURE_PRODUCT, PROVIDER); CurrencyParameterSensitivities computed = PROVIDER.parameterSensitivity(point); CurrencyParameterSensitivities expected = FD_CAL.sensitivity( PROVIDER, (p) -> CurrencyAmount.of(USD, FUTURE_PRICER.price(FUTURE_PRODUCT, (p)))); assertTrue(computed.equalWithTolerance(expected, EPS * 10.0)); }
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)); }
// ------------------------------------------------------------------------- // regression to 2.x public void regression() { double price = FUTURE_PRICER.price(FUTURE_PRODUCT, PROVIDER); assertEquals(price, 1.2106928633440506, TOL); PointSensitivities point = FUTURE_PRICER.priceSensitivity(FUTURE_PRODUCT, PROVIDER); CurrencyParameterSensitivities test = PROVIDER.parameterSensitivity(point); DoubleArray expectedIssuer = DoubleArray.of( -3.940585873921608E-4, -0.004161527192990392, -0.014331606019672717, -1.0229665443857998, -4.220553063715371, 0); DoubleArray actualIssuer = test.getSensitivity(METADATA_ISSUER.getCurveName(), USD).getSensitivity(); assertTrue(actualIssuer.equalWithTolerance(expectedIssuer, TOL)); DoubleArray expectedRepo = DoubleArray.of(0.14752541809405412, 0.20907575809356016, 0.0, 0.0, 0.0, 0.0); DoubleArray actualRepo = test.getSensitivity(METADATA_REPO.getCurveName(), USD).getSensitivity(); assertTrue(actualRepo.equalWithTolerance(expectedRepo, TOL)); }