public virtual 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 virtual void present_value_formula() { double forward = PRICER_SWAP.parRate(RSWAP_REC, MULTI_USD); double pvbp = PRICER_SWAP.LegPricer.pvbp(RSWAP_REC.getLegs(SwapLegType.FIXED).get(0), MULTI_USD); double volatility = BLACK_VOLS_USD_STD.volatility(SWAPTION_LONG_REC.Expiry, SWAP_TENOR_YEAR, STRIKE, forward); double expiry = BLACK_VOLS_USD_STD.relativeTime(SWAPTION_LONG_REC.Expiry); double pvExpected = Math.Abs(pvbp) * BlackFormulaRepository.price(forward, STRIKE, expiry, volatility, false); CurrencyAmount pvComputed = PRICER_SWAPTION_BLACK.presentValue(SWAPTION_LONG_REC, MULTI_USD, BLACK_VOLS_USD_STD); assertEquals(pvComputed.Currency, USD); assertEquals(pvComputed.Amount, pvExpected, TOLERANCE_PV); }
//------------------------------------------------------------------------- public virtual 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.Convention, VAL_DATE.atStartOfDay(ZoneOffset.UTC), surfaceUp)); CurrencyAmount pvM = PRICER_SWAPTION_BLACK.presentValue(SWAPTION_LONG_PAY, MULTI_USD, BlackSwaptionExpiryTenorVolatilities.of(BLACK_VOLS_CST_USD.Convention, VAL_DATE.atStartOfDay(ZoneOffset.UTC), surfaceDw)); double pvnvsFd = (pvP.Amount - pvM.Amount) / (2 * shiftVol); SwaptionSensitivity pvnvsAd = PRICER_SWAPTION_BLACK.presentValueSensitivityModelParamsVolatility(SWAPTION_LONG_PAY, MULTI_USD, BLACK_VOLS_CST_USD); assertEquals(pvnvsAd.Currency, USD); assertEquals(pvnvsAd.Sensitivity, pvnvsFd, TOLERANCE_PV_VEGA); assertEquals(pvnvsAd.VolatilitiesName, BLACK_VOLS_CST_USD.Name); assertEquals(pvnvsAd.Expiry, BLACK_VOLS_CST_USD.relativeTime(SWAPTION_LONG_PAY.Expiry)); assertEquals(pvnvsAd.Tenor, SWAP_TENOR_YEAR, TOLERANCE_RATE); assertEquals(pvnvsAd.Strike, STRIKE, TOLERANCE_RATE); double forward = PRICER_SWAP.parRate(RSWAP_REC, MULTI_USD); assertEquals(pvnvsAd.Forward, forward, TOLERANCE_RATE); }
public virtual 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.LegPricer.annuityCash(RFIXED_LEG_REC, forward); double expiry = VOLS.relativeTime(SWAPTION_REC_LONG.Expiry); 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.Currency, EUR); assertEquals(computedRec.Amount, expectedRec, NOTIONAL * TOL); assertEquals(computedPay.Currency, EUR); assertEquals(computedPay.Amount, expectedPay, NOTIONAL * TOL); }