/** * Restricted copy constructor. * @param beanToCopy the bean to copy from, not null */ private Builder(BlackBondFutureExpiryLogMoneynessVolatilities beanToCopy) { this.valuationDateTime = beanToCopy.getValuationDateTime(); this.surface = beanToCopy.getSurface(); }
@Override public BlackBondFutureExpiryLogMoneynessVolatilities build() { return new BlackBondFutureExpiryLogMoneynessVolatilities( valuationDateTime, surface); }
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.getName(), expiry, TEST_FUTURE_EXPIRY[i], TEST_FUTURE_PRICE[i], USD, TEST_SENSITIVITY[i]); CurrencyParameterSensitivity sensActual = VOLS.parameterSensitivity(point).getSensitivities().get(0); double[] computed = sensActual.getSensitivity().toArray(); for (int j = 0; j < nData; j++) { 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;
@Override public CurrencyParameterSensitivities parameterSensitivity(PointSensitivities pointSensitivities) { CurrencyParameterSensitivities sens = CurrencyParameterSensitivities.empty(); for (PointSensitivity point : pointSensitivities.getSensitivities()) { if (point instanceof BondFutureOptionSensitivity) { BondFutureOptionSensitivity pt = (BondFutureOptionSensitivity) point; if (pt.getVolatilitiesName().equals(getName())) { sens = sens.combinedWith(parameterSensitivity(pt)); } } } return sens; }
public void test_priceSensitivityBlackVolatility_from_future_price() { double futurePrice = 1.1d; BondFutureOptionSensitivity sensi = OPTION_PRICER.priceSensitivityModelParamsVolatility( FUTURE_OPTION_PRODUCT, RATE_PROVIDER, VOLS, futurePrice); testPriceSensitivityBlackVolatility( VOLS.parameterSensitivity(sensi), (p) -> OPTION_PRICER.price(FUTURE_OPTION_PRODUCT, RATE_PROVIDER, (p), futurePrice)); }
public void test_valuationDate() { assertEquals(VOLS.getValuationDateTime(), VAL_DATE_TIME); }
public void test_volatility() { for (int i = 0; i < NB_TEST; i++) { double expiryTime = VOLS.relativeTime(TEST_OPTION_EXPIRY[i]); double volExpected = SURFACE.zValue(expiryTime, Math.log(TEST_STRIKE_PRICE[i] / TEST_FUTURE_PRICE[i])); double volComputed = VOLS.volatility( TEST_OPTION_EXPIRY[i], TEST_FUTURE_EXPIRY[i], TEST_STRIKE_PRICE[i], TEST_FUTURE_PRICE[i]); assertEquals(volComputed, volExpected, TOLERANCE_VOL); } }
public 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 void test_priceSensitivityBlackVolatility() { BondFutureOptionSensitivity sensi = OPTION_PRICER.priceSensitivityModelParamsVolatility( FUTURE_OPTION_PRODUCT, RATE_PROVIDER, VOLS); testPriceSensitivityBlackVolatility( VOLS.parameterSensitivity(sensi), (p) -> OPTION_PRICER.price(FUTURE_OPTION_PRODUCT, RATE_PROVIDER, (p))); }
public 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); }
@Override protected Object propertyGet(Bean bean, String propertyName, boolean quiet) { switch (propertyName.hashCode()) { case -949589828: // valuationDateTime return ((BlackBondFutureExpiryLogMoneynessVolatilities) bean).getValuationDateTime(); case -1853231955: // surface return ((BlackBondFutureExpiryLogMoneynessVolatilities) bean).getSurface(); } return super.propertyGet(bean, propertyName, quiet); }
public void test_presentValueSensitivityBlackVolatility_from_future_price() { double futurePrice = 0.975d; BondFutureOptionSensitivity sensi = OPTION_TRADE_PRICER.presentValueSensitivityModelParamsVolatility( OPTION_TRADE, RATE_PROVIDER, VOLS, futurePrice); testPriceSensitivityBlackVolatility(VOLS.parameterSensitivity(sensi), (p) -> OPTION_TRADE_PRICER.presentValue(OPTION_TRADE, RATE_PROVIDER, (p), futurePrice, REFERENCE_PRICE).getAmount()); }
private Object readResolve() { return new BlackBondFutureExpiryLogMoneynessVolatilities(valuationDateTime, surface); }
public 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); }
public void test_presentValueSensitivityBlackVolatility() { BondFutureOptionSensitivity sensi = OPTION_TRADE_PRICER.presentValueSensitivityModelParamsVolatility( OPTION_TRADE, RATE_PROVIDER, VOLS); testPriceSensitivityBlackVolatility(VOLS.parameterSensitivity(sensi), (p) -> OPTION_TRADE_PRICER.presentValue(OPTION_TRADE, RATE_PROVIDER, (p), REFERENCE_PRICE).getAmount()); }
/** * Obtains an instance from the implied volatility surface and the date-time for which it is valid. * <p> * The surface is specified by an instance of {@link Surface}, such as {@link InterpolatedNodalSurface}. * The surface must contain the correct metadata: * <ul> * <li>The x-value type must be {@link ValueType#YEAR_FRACTION} * <li>The y-value type must be {@link ValueType#LOG_MONEYNESS} * <li>The z-value type must be {@link ValueType#BLACK_VOLATILITY} * <li>The day count must be set in the additional information using {@link SurfaceInfoType#DAY_COUNT} * </ul> * Suitable surface metadata can be created using * {@link Surfaces#blackVolatilityByExpiryLogMoneyness(String, DayCount)}. * * @param valuationDateTime the valuation date-time * @param surface the implied volatility surface * @return the volatilities */ public static BlackBondFutureExpiryLogMoneynessVolatilities of( ZonedDateTime valuationDateTime, InterpolatedNodalSurface surface) { return new BlackBondFutureExpiryLogMoneynessVolatilities(valuationDateTime, surface); }
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.apply(provUp) - valueFn.apply(provDw)) / EPS; int index = -1;
@Override public BlackBondFutureExpiryLogMoneynessVolatilities withParameter(int parameterIndex, double newValue) { return new BlackBondFutureExpiryLogMoneynessVolatilities( valuationDateTime, surface.withParameter(parameterIndex, newValue)); }
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.apply(provUp) - valueFn.apply(provDw)) / EPS; int index = -1;
@Override public BlackBondFutureExpiryLogMoneynessVolatilities withPerturbation(ParameterPerturbation perturbation) { return new BlackBondFutureExpiryLogMoneynessVolatilities( valuationDateTime, surface.withPerturbation(perturbation)); }