@Override protected Object propertyGet(Bean bean, String propertyName, boolean quiet) { switch (propertyName.hashCode()) { case 2039569265: // convention return ((BlackSwaptionExpiryTenorVolatilities) bean).getConvention(); case -949589828: // valuationDateTime return ((BlackSwaptionExpiryTenorVolatilities) bean).getValuationDateTime(); case -1853231955: // surface return ((BlackSwaptionExpiryTenorVolatilities) bean).getSurface(); } return super.propertyGet(bean, propertyName, quiet); }
@Override public BlackSwaptionExpiryTenorVolatilities build() { return new BlackSwaptionExpiryTenorVolatilities( convention, valuationDateTime, surface); }
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, TEST_TENOR[i]); double volComputed = VOLS.volatility( TEST_OPTION_EXPIRY[i], TEST_TENOR[i], TEST_STRIKE, TEST_FORWARD); assertEquals(volComputed, volExpected, TOLERANCE_VOL); } }
public void test_volatility_sensitivity() { double eps = 1.0e-6; int nData = TIME.size(); for (int i = 0; i < NB_TEST; i++) { double expiryTime = VOLS.relativeTime(TEST_OPTION_EXPIRY[i]); SwaptionSensitivity point = SwaptionSensitivity.of( VOLS.getName(), expiryTime, TEST_TENOR[i], TEST_STRIKE, TEST_FORWARD, GBP, TEST_SENSITIVITY[i]); CurrencyParameterSensitivities sensActual = VOLS.parameterSensitivity(point); DoubleArray computed = sensActual.getSensitivity(SURFACE.getName(), GBP).getSensitivity(); 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, TENOR, volDataUp, INTERPOLATOR_2D); InterpolatedNodalSurface paramDw = InterpolatedNodalSurface.of(METADATA, TIME, TENOR, volDataDw, INTERPOLATOR_2D); BlackSwaptionExpiryTenorVolatilities provUp = BlackSwaptionExpiryTenorVolatilities.of(CONVENTION, VAL_DATE_TIME, paramUp); BlackSwaptionExpiryTenorVolatilities provDw = BlackSwaptionExpiryTenorVolatilities.of(CONVENTION, VAL_DATE_TIME, paramDw); double volUp = provUp.volatility( TEST_OPTION_EXPIRY[i], TEST_TENOR[i], TEST_STRIKE, TEST_FORWARD); double volDw = provDw.volatility( TEST_OPTION_EXPIRY[i], TEST_TENOR[i], TEST_STRIKE, TEST_FORWARD); double fd = 0.5 * (volUp - volDw) / eps; assertEquals(computed.get(j), fd * TEST_SENSITIVITY[i], eps); } } }
public void present_value_sensitivityBlackVolatility_FD() { double shiftVol = 1.0E-4; Surface surfaceUp = ConstantSurface.of( SwaptionBlackVolatilityDataSets.META_DATA, SwaptionBlackVolatilityDataSets.VOLATILITY + shiftVol); Surface surfaceDw = ConstantSurface.of( SwaptionBlackVolatilityDataSets.META_DATA, SwaptionBlackVolatilityDataSets.VOLATILITY - shiftVol); CurrencyAmount pvP = PRICER_SWAPTION_BLACK.presentValue(SWAPTION_LONG_PAY, MULTI_USD, BlackSwaptionExpiryTenorVolatilities.of( BLACK_VOLS_CST_USD.getConvention(), VAL_DATE.atStartOfDay(ZoneOffset.UTC), surfaceUp)); CurrencyAmount pvM = PRICER_SWAPTION_BLACK.presentValue(SWAPTION_LONG_PAY, MULTI_USD, BlackSwaptionExpiryTenorVolatilities.of( BLACK_VOLS_CST_USD.getConvention(), VAL_DATE.atStartOfDay(ZoneOffset.UTC), surfaceDw)); double pvnvsFd = (pvP.getAmount() - pvM.getAmount()) / (2 * shiftVol); SwaptionSensitivity pvnvsAd = PRICER_SWAPTION_BLACK .presentValueSensitivityModelParamsVolatility(SWAPTION_LONG_PAY, MULTI_USD, BLACK_VOLS_CST_USD); assertEquals(pvnvsAd.getCurrency(), USD); assertEquals(pvnvsAd.getSensitivity(), pvnvsFd, TOLERANCE_PV_VEGA); assertEquals(pvnvsAd.getVolatilitiesName(), BLACK_VOLS_CST_USD.getName()); assertEquals(pvnvsAd.getExpiry(), BLACK_VOLS_CST_USD.relativeTime(SWAPTION_LONG_PAY.getExpiry())); assertEquals(pvnvsAd.getTenor(), SWAP_TENOR_YEAR, TOLERANCE_RATE); assertEquals(pvnvsAd.getStrike(), STRIKE, TOLERANCE_RATE); double forward = PRICER_SWAP.parRate(RSWAP_REC, MULTI_USD); assertEquals(pvnvsAd.getForward(), forward, TOLERANCE_RATE); }
@Override public CurrencyParameterSensitivities parameterSensitivity(PointSensitivities pointSensitivities) { CurrencyParameterSensitivities sens = CurrencyParameterSensitivities.empty(); for (PointSensitivity point : pointSensitivities.getSensitivities()) { if (point instanceof SwaptionSensitivity) { SwaptionSensitivity pt = (SwaptionSensitivity) point; if (pt.getVolatilitiesName().equals(getName())) { sens = sens.combinedWith(parameterSensitivity(pt)); } } } return sens; }
public void test_impliedVolatility() { double computedRec = PRICER.impliedVolatility(SWAPTION_REC_LONG, RATE_PROVIDER, VOLS); double computedPay = PRICER.impliedVolatility(SWAPTION_PAY_SHORT, RATE_PROVIDER, VOLS); double expiry = VOLS.relativeTime(SWAPTION_REC_LONG.getExpiry()); double tenor = VOLS.tenor(SETTLE, END); double expected = SURFACE.zValue(expiry, tenor); assertEquals(computedRec, expected); assertEquals(computedPay, expected); }
public void test_presentValueSensitivityBlackVolatility() { SwaptionSensitivity sensiRec = PRICER.presentValueSensitivityModelParamsVolatility(SWAPTION_REC_LONG, RATE_PROVIDER, VOLS); SwaptionSensitivity sensiPay = PRICER.presentValueSensitivityModelParamsVolatility(SWAPTION_PAY_SHORT, RATE_PROVIDER, VOLS); double forward = SWAP_PRICER.parRate(RSWAP_REC, RATE_PROVIDER); double annuityCash = SWAP_PRICER.getLegPricer().annuityCash(RFIXED_LEG_REC, forward); double expiry = VOLS.relativeTime(SWAPTION_REC_LONG.getExpiry()); double tenor = VOLS.tenor(SETTLE, END); double volatility = SURFACE.zValue(expiry, tenor); double settle = ACT_ACT_ISDA.relativeYearFraction(VAL_DATE, SETTLE); double df = Math.exp(-DSC_CURVE.yValue(settle) * settle); double expectedRec = df * annuityCash * BlackFormulaRepository.vega(forward, RATE, expiry, volatility); double expectedPay = -df * annuityCash * BlackFormulaRepository.vega(forward, RATE, expiry, volatility); assertEquals(sensiRec.getCurrency(), EUR); assertEquals(sensiRec.getSensitivity(), expectedRec, NOTIONAL * TOL); assertEquals(sensiRec.getVolatilitiesName(), VOLS.getName()); assertEquals(sensiRec.getExpiry(), expiry); assertEquals(sensiRec.getTenor(), 5.0); assertEquals(sensiRec.getStrike(), RATE); assertEquals(sensiRec.getForward(), forward, TOL); assertEquals(sensiPay.getCurrency(), EUR); assertEquals(sensiPay.getSensitivity(), expectedPay, NOTIONAL * TOL); assertEquals(sensiRec.getVolatilitiesName(), VOLS.getName()); assertEquals(sensiPay.getExpiry(), expiry); assertEquals(sensiPay.getTenor(), 5.0); assertEquals(sensiPay.getStrike(), RATE); assertEquals(sensiPay.getForward(), forward, TOL); }
public void test_valuationDate() { assertEquals(VOLS.getValuationDateTime(), VAL_DATE_TIME); }
public void test_swapConvention() { assertEquals(VOLS.getConvention(), CONVENTION); }
public void coverage() { BlackSwaptionExpiryTenorVolatilities test1 = BlackSwaptionExpiryTenorVolatilities.of(CONVENTION, VAL_DATE_TIME, SURFACE); coverImmutableBean(test1); BlackSwaptionExpiryTenorVolatilities test2 = BlackSwaptionExpiryTenorVolatilities.of(CONVENTION, VAL_DATE.atStartOfDay(ZoneOffset.UTC), SURFACE); coverBeanEquals(test1, test2); }
public void test_relativeTime() { double test1 = VOLS.relativeTime(VAL_DATE_TIME); assertEquals(test1, 0d); double test2 = VOLS.relativeTime(date(2018, 2, 17).atStartOfDay(LONDON_ZONE)); double test3 = VOLS.relativeTime(date(2012, 2, 17).atStartOfDay(LONDON_ZONE)); assertEquals(test2, -test3); // consistency checked }
public void test_presentValueTheta() { CurrencyAmount computedRec = PRICER.presentValueTheta(SWAPTION_REC_LONG, RATE_PROVIDER, VOLS); CurrencyAmount computedPay = PRICER.presentValueTheta(SWAPTION_PAY_SHORT, RATE_PROVIDER, VOLS); double forward = SWAP_PRICER.parRate(RSWAP_REC, RATE_PROVIDER); double annuityCash = SWAP_PRICER.getLegPricer().annuityCash(RFIXED_LEG_REC, forward); double expiry = VOLS.relativeTime(SWAPTION_REC_LONG.getExpiry()); double tenor = VOLS.tenor(SETTLE, END); double volatility = SURFACE.zValue(expiry, tenor); double settle = ACT_ACT_ISDA.relativeYearFraction(VAL_DATE, SETTLE); double df = Math.exp(-DSC_CURVE.yValue(settle) * settle); double expectedRec = df * annuityCash * BlackFormulaRepository.driftlessTheta(forward, RATE, expiry, volatility); double expectedPay = -df * annuityCash * BlackFormulaRepository.driftlessTheta(forward, RATE, expiry, volatility); assertEquals(computedRec.getCurrency(), EUR); assertEquals(computedRec.getAmount(), expectedRec, NOTIONAL * TOL); assertEquals(computedPay.getCurrency(), EUR); assertEquals(computedPay.getAmount(), expectedPay, NOTIONAL * TOL); }
public void test_presentValueSensitivityRatesStickyStrike() { SwaptionVolatilities volSabr = SwaptionSabrRateVolatilityDataSet.getVolatilitiesEur(VAL_DATE_TIME.toLocalDate(), false); double impliedVol = PRICER.impliedVolatility(SWAPTION_REC_LONG, RATE_PROVIDER, volSabr); SurfaceMetadata blackMeta = Surfaces.blackVolatilityByExpiryTenor("CST", VOLS.getDayCount()); SwaptionVolatilities volCst = BlackSwaptionExpiryTenorVolatilities.of( VOLS.getConvention(), VOLS.getValuationDateTime(), ConstantSurface.of(blackMeta, impliedVol)); // To obtain a constant volatility surface which create a sticky strike sensitivity PointSensitivityBuilder pointRec = PRICER.presentValueSensitivityRatesStickyStrike(SWAPTION_REC_LONG, RATE_PROVIDER, volSabr); CurrencyParameterSensitivities computedRec = RATE_PROVIDER.parameterSensitivity(pointRec.build()); CurrencyParameterSensitivities expectedRec = FD_CAL.sensitivity(RATE_PROVIDER, (p) -> PRICER.presentValue(SWAPTION_REC_LONG, (p), volCst)); assertTrue(computedRec.equalWithTolerance(expectedRec, NOTIONAL * FD_EPS * 300d)); PointSensitivityBuilder pointPay = PRICER.presentValueSensitivityRatesStickyStrike(SWAPTION_PAY_SHORT, RATE_PROVIDER, volSabr); CurrencyParameterSensitivities computedPay = RATE_PROVIDER.parameterSensitivity(pointPay.build()); CurrencyParameterSensitivities expectedPay = FD_CAL.sensitivity(RATE_PROVIDER, (p) -> PRICER.presentValue(SWAPTION_PAY_SHORT, (p), volCst)); assertTrue(computedPay.equalWithTolerance(expectedPay, NOTIONAL * FD_EPS * 300d)); }
public void test_impliedVolatility_atMaturity() { double computedRec = PRICER.impliedVolatility(SWAPTION_REC_LONG, RATES_PROVIDER_AT_MATURITY, VOLS_AT_MATURITY); double computedPay = PRICER.impliedVolatility(SWAPTION_PAY_SHORT, RATES_PROVIDER_AT_MATURITY, VOLS_AT_MATURITY); double expiry = 0d; double tenor = VOLS.tenor(SETTLE, END); double expected = SURFACE.zValue(expiry, tenor); assertEquals(computedRec, expected); assertEquals(computedPay, expected); }
public void present_value_gamma_formula() { double forward = PRICER_SWAP.parRate(RSWAP_REC, MULTI_USD); double pvbp = PRICER_SWAP.getLegPricer().pvbp(RSWAP_REC.getLegs(SwapLegType.FIXED).get(0), MULTI_USD); double volatility = BLACK_VOLS_USD_STD.volatility(SWAPTION_LONG_REC.getExpiry(), SWAP_TENOR_YEAR, STRIKE, forward); double expiry = BLACK_VOLS_USD_STD.relativeTime(SWAPTION_LONG_REC.getExpiry()); double pvGammaExpected = BlackFormulaRepository.gamma(forward, STRIKE, expiry, volatility) * Math.abs(pvbp); CurrencyAmount pvGammaComputed = PRICER_SWAPTION_BLACK.presentValueGamma(SWAPTION_LONG_REC, MULTI_USD, BLACK_VOLS_USD_STD); assertEquals(pvGammaComputed.getCurrency(), USD); assertEquals(pvGammaComputed.getAmount(), pvGammaExpected, TOLERANCE_PV); }
public void test_presentValue() { CurrencyAmount computedRec = PRICER.presentValue(SWAPTION_REC_LONG, RATE_PROVIDER, VOLS); CurrencyAmount computedPay = PRICER.presentValue(SWAPTION_PAY_SHORT, RATE_PROVIDER, VOLS); double forward = SWAP_PRICER.parRate(RSWAP_REC, RATE_PROVIDER); double annuityCash = SWAP_PRICER.getLegPricer().annuityCash(RFIXED_LEG_REC, forward); double expiry = VOLS.relativeTime(SWAPTION_REC_LONG.getExpiry()); double tenor = VOLS.tenor(SETTLE, END); double volatility = SURFACE.zValue(expiry, tenor); double settle = ACT_ACT_ISDA.relativeYearFraction(VAL_DATE, SETTLE); double df = Math.exp(-DSC_CURVE.yValue(settle) * settle); double expectedRec = df * annuityCash * BlackFormulaRepository.price(forward, RATE, expiry, volatility, false); double expectedPay = -df * annuityCash * BlackFormulaRepository.price(forward, RATE, expiry, volatility, true); assertEquals(computedRec.getCurrency(), EUR); assertEquals(computedRec.getAmount(), expectedRec, NOTIONAL * TOL); assertEquals(computedPay.getCurrency(), EUR); assertEquals(computedPay.getAmount(), expectedPay, NOTIONAL * TOL); }
private Object readResolve() { return new BlackSwaptionExpiryTenorVolatilities(convention, valuationDateTime, surface); }