private void testPriceSensitivityBlackVolatility(CurrencyParameterSensitivities computed, System.Func <BlackBondFutureVolatilities, double> valueFn) { IList <ParameterMetadata> list = computed.Sensitivities.get(0).ParameterMetadata; int nVol = VOL.size(); assertEquals(list.Count, nVol); for (int i = 0; i < nVol; ++i) { double[] volUp = Arrays.copyOf(VOL.toArray(), nVol); double[] volDw = Arrays.copyOf(VOL.toArray(), nVol); volUp[i] += EPS; volDw[i] -= EPS; InterpolatedNodalSurface sfUp = InterpolatedNodalSurface.of(METADATA, TIME, MONEYNESS, DoubleArray.copyOf(volUp), INTERPOLATOR_2D); InterpolatedNodalSurface sfDw = InterpolatedNodalSurface.of(METADATA, TIME, MONEYNESS, DoubleArray.copyOf(volDw), INTERPOLATOR_2D); BlackBondFutureExpiryLogMoneynessVolatilities provUp = BlackBondFutureExpiryLogMoneynessVolatilities.of(VAL_DATE_TIME, sfUp); BlackBondFutureExpiryLogMoneynessVolatilities provDw = BlackBondFutureExpiryLogMoneynessVolatilities.of(VAL_DATE_TIME, sfDw); double expected = 0.5 * (valueFn(provUp) - valueFn(provDw)) / EPS; int index = -1; for (int j = 0; j < nVol; ++j) { GenericVolatilitySurfaceYearFractionParameterMetadata meta = (GenericVolatilitySurfaceYearFractionParameterMetadata)list[j]; if (meta.YearFraction == TIME.get(i) && meta.Strike.Value == MONEYNESS.get(i)) { index = j; continue; } } assertEquals(computed.Sensitivities.get(0).Sensitivity.get(index), expected, EPS); } }
public virtual void test_volatility_sensitivity() { double eps = 1.0e-6; int nData = TIME.size(); for (int i = 0; i < NB_TEST; i++) { double expiry = VOLS.relativeTime(TEST_OPTION_EXPIRY[i]); BondFutureOptionSensitivity point = BondFutureOptionSensitivity.of(VOLS.Name, expiry, TEST_FUTURE_EXPIRY[i], TEST_STRIKE_PRICE[i], TEST_FUTURE_PRICE[i], USD, TEST_SENSITIVITY[i]); CurrencyParameterSensitivity sensActual = VOLS.parameterSensitivity(point).Sensitivities.get(0); double[] computed = sensActual.Sensitivity.toArray(); for (int j = 0; j < nData; j++) { DoubleArray volDataUp = VOL.with(j, VOL.get(j) + eps); DoubleArray volDataDw = VOL.with(j, VOL.get(j) - eps); InterpolatedNodalSurface paramUp = InterpolatedNodalSurface.of(METADATA, TIME, MONEYNESS, volDataUp, INTERPOLATOR_2D); InterpolatedNodalSurface paramDw = InterpolatedNodalSurface.of(METADATA, TIME, MONEYNESS, volDataDw, INTERPOLATOR_2D); BlackBondFutureExpiryLogMoneynessVolatilities provUp = BlackBondFutureExpiryLogMoneynessVolatilities.of(VAL_DATE_TIME, paramUp); BlackBondFutureExpiryLogMoneynessVolatilities provDw = BlackBondFutureExpiryLogMoneynessVolatilities.of(VAL_DATE_TIME, paramDw); double volUp = provUp.volatility(expiry, TEST_FUTURE_EXPIRY[i], TEST_STRIKE_PRICE[i], TEST_FUTURE_PRICE[i]); double volDw = provDw.volatility(expiry, TEST_FUTURE_EXPIRY[i], TEST_STRIKE_PRICE[i], TEST_FUTURE_PRICE[i]); double fd = 0.5 * (volUp - volDw) / eps; assertEquals(computed[j], fd, eps); } } }
public virtual void test_priceSensitivity_from_generic_provider() { BondFutureVolatilities volProvider = BlackBondFutureExpiryLogMoneynessVolatilities.of(VAL_DATE_TIME, SURFACE); PointSensitivities expected = OPTION_PRICER.priceSensitivityRatesStickyStrike(FUTURE_OPTION_PRODUCT, RATE_PROVIDER, VOLS); PointSensitivities computed = OPTION_PRICER.priceSensitivity(FUTURE_OPTION_PRODUCT, RATE_PROVIDER, volProvider); assertEquals(computed, expected); }
public virtual void test_price_from_generic_provider() { BondFutureVolatilities vols = BlackBondFutureExpiryLogMoneynessVolatilities.of(VAL_DATE_TIME, SURFACE); double computed = OPTION_PRICER.price(FUTURE_OPTION_PRODUCT, RATE_PROVIDER, vols); double expected = OPTION_PRICER.price(FUTURE_OPTION_PRODUCT, RATE_PROVIDER, VOLS); assertEquals(computed, expected, TOL); }
//------------------------------------------------------------------------- public virtual void coverage() { BlackBondFutureExpiryLogMoneynessVolatilities test1 = BlackBondFutureExpiryLogMoneynessVolatilities.of(VAL_DATE_TIME, SURFACE); coverImmutableBean(test1); BlackBondFutureExpiryLogMoneynessVolatilities test2 = BlackBondFutureExpiryLogMoneynessVolatilities.of(VAL_DATE_TIME.plusDays(1), SURFACE.withParameter(0, 1d)); coverBeanEquals(test1, test2); }