public void present_value_long_short_parity() { CurrencyAmount pvLong = PRICER_SWAPTION_NORMAL.presentValue(SWAPTION_LONG_REC, MULTI_USD, NORMAL_VOLS_USD_STD); CurrencyAmount pvShort = PRICER_SWAPTION_NORMAL.presentValue(SWAPTION_SHORT_REC, MULTI_USD, NORMAL_VOLS_USD_STD); assertEquals(pvLong.getAmount(), -pvShort.getAmount(), TOLERANCE_PV); }
public void present_value_sensitivityNormalVolatility_long_short_parity() { SwaptionSensitivity pvptLongPay = PRICER_SWAPTION_NORMAL .presentValueSensitivityModelParamsVolatility(SWAPTION_LONG_REC, MULTI_USD, NORMAL_VOLS_USD_STD); SwaptionSensitivity pvptShortRec = PRICER_SWAPTION_NORMAL .presentValueSensitivityModelParamsVolatility(SWAPTION_SHORT_REC, MULTI_USD, NORMAL_VOLS_USD_STD); assertEquals(pvptLongPay.getSensitivity(), -pvptShortRec.getSensitivity(), TOLERANCE_PV_VEGA); }
public void present_value_sensitivity_after_expiry() { PointSensitivityBuilder pvpts = PRICER_SWAPTION_NORMAL .presentValueSensitivityRatesStickyStrike(SWAPTION_PAST, MULTI_USD, NORMAL_VOLS_USD_STD); assertEquals(pvpts, PointSensitivityBuilder.none()); }
public void implied_volatility_round_trip() { // Compute pv and then implied vol from PV and compare with direct implied vol CurrencyAmount pvLongRec = PRICER_SWAPTION_NORMAL.presentValue(SWAPTION_LONG_REC, MULTI_USD, NORMAL_VOLS_USD_STD); double impliedLongRecComputed = PRICER_SWAPTION_NORMAL.impliedVolatilityFromPresentValue( SWAPTION_LONG_REC, MULTI_USD, ACT_365F, pvLongRec.getAmount()); double impliedLongRecInterpolated = PRICER_SWAPTION_NORMAL.impliedVolatility(SWAPTION_LONG_REC, MULTI_USD, NORMAL_VOLS_USD_STD); assertEquals(impliedLongRecComputed, impliedLongRecInterpolated, TOLERANCE_RATE); CurrencyAmount pvShortRec = PRICER_SWAPTION_NORMAL.presentValue(SWAPTION_SHORT_REC, MULTI_USD, NORMAL_VOLS_USD_STD); double impliedShortRecComputed = PRICER_SWAPTION_NORMAL.impliedVolatilityFromPresentValue( SWAPTION_SHORT_REC, MULTI_USD, ACT_365F, pvShortRec.getAmount()); double impliedShortRecInterpolated = PRICER_SWAPTION_NORMAL.impliedVolatility(SWAPTION_SHORT_REC, MULTI_USD, NORMAL_VOLS_USD_STD); assertEquals(impliedShortRecComputed, impliedShortRecInterpolated, TOLERANCE_RATE); CurrencyAmount pvLongPay = PRICER_SWAPTION_NORMAL.presentValue(SWAPTION_LONG_PAY, MULTI_USD, NORMAL_VOLS_USD_STD); double impliedLongPayComputed = PRICER_SWAPTION_NORMAL.impliedVolatilityFromPresentValue( SWAPTION_LONG_PAY, MULTI_USD, ACT_365F, pvLongPay.getAmount()); double impliedLongPayInterpolated = PRICER_SWAPTION_NORMAL.impliedVolatility(SWAPTION_LONG_PAY, MULTI_USD, NORMAL_VOLS_USD_STD); assertEquals(impliedLongPayComputed, impliedLongPayInterpolated, TOLERANCE_RATE); }
public void implied_volatility_wrong_sign() { CurrencyAmount pvLongRec = PRICER_SWAPTION_NORMAL.presentValue(SWAPTION_LONG_REC, MULTI_USD, NORMAL_VOLS_USD_STD); assertThrowsIllegalArg(() -> PRICER_SWAPTION_NORMAL.impliedVolatilityFromPresentValue( SWAPTION_LONG_REC, MULTI_USD, ACT_365F, -pvLongRec.getAmount())); }
public void currency_exposure() { CurrencyAmount pv = PRICER_SWAPTION_NORMAL.presentValue(SWAPTION_LONG_PAY, MULTI_USD, NORMAL_VOLS_USD_STD); MultiCurrencyAmount ce = PRICER_SWAPTION_NORMAL.currencyExposure(SWAPTION_LONG_PAY, MULTI_USD, NORMAL_VOLS_USD_STD); assertEquals(pv.getAmount(), ce.getAmount(USD).getAmount(), TOLERANCE_PV); }
public void present_value_sensitivity_FD() { PointSensitivities pvpt = PRICER_SWAPTION_NORMAL .presentValueSensitivityRatesStickyStrike(SWAPTION_SHORT_REC, MULTI_USD, NORMAL_VOLS_USD_FLAT).build(); CurrencyParameterSensitivities pvpsAd = MULTI_USD.parameterSensitivity(pvpt); CurrencyParameterSensitivities pvpsFd = FINITE_DIFFERENCE_CALCULATOR.sensitivity(MULTI_USD, (p) -> PRICER_SWAPTION_NORMAL.presentValue(SWAPTION_SHORT_REC, p, NORMAL_VOLS_USD_FLAT)); assertTrue(pvpsAd.equalWithTolerance(pvpsFd, TOLERANCE_PV_DELTA)); }
public void present_value_sensitivityNormalVolatility_FD() { double shiftVol = 1.0E-4; CurrencyAmount pvP = PRICER_SWAPTION_NORMAL.presentValue(SWAPTION_LONG_PAY, MULTI_USD, SwaptionNormalVolatilityDataSets.normalVolSwaptionProviderUsdStsShifted(shiftVol)); CurrencyAmount pvM = PRICER_SWAPTION_NORMAL.presentValue(SWAPTION_LONG_PAY, MULTI_USD, SwaptionNormalVolatilityDataSets.normalVolSwaptionProviderUsdStsShifted(-shiftVol)); double pvnvsFd = (pvP.getAmount() - pvM.getAmount()) / (2 * shiftVol); SwaptionSensitivity pvnvsAd = PRICER_SWAPTION_NORMAL .presentValueSensitivityModelParamsVolatility(SWAPTION_LONG_PAY, MULTI_USD, NORMAL_VOLS_USD_STD); assertEquals(pvnvsAd.getCurrency(), USD); assertEquals(pvnvsAd.getSensitivity(), pvnvsFd, TOLERANCE_PV_VEGA); assertEquals(pvnvsAd.getVolatilitiesName(), NORMAL_VOLS_USD_STD.getName()); assertEquals(pvnvsAd.getExpiry(), NORMAL_VOLS_USD_STD.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); }
validateSwaption(swaption); LocalDate valuationDate = ratesProvider.getValuationDate(); LocalDate expiryDate = swaption.getExpiryDate(); double expiry = dayCount.yearFraction(valuationDate, expiryDate); ResolvedSwap underlying = swaption.getUnderlying(); ResolvedSwapLeg fixedLeg = fixedLeg(underlying); double forward = getSwapPricer().parRate(underlying, ratesProvider); double pvbp = getSwapPricer().getLegPricer().pvbp(fixedLeg, ratesProvider); double numeraire = Math.abs(pvbp); double strike = getSwapPricer().getLegPricer().couponEquivalent(fixedLeg, ratesProvider, pvbp); PutCall putCall = PutCall.ofPut(fixedLeg.getPayReceive().isReceive()); return NormalFormulaRepository.impliedVolatility(
public void present_value_delta_long_short_parity() { CurrencyAmount pvDeltaLong = PRICER_SWAPTION_NORMAL.presentValueDelta(SWAPTION_LONG_REC, MULTI_USD, NORMAL_VOLS_USD_STD); CurrencyAmount pvDeltaShort = PRICER_SWAPTION_NORMAL.presentValueDelta(SWAPTION_SHORT_REC, MULTI_USD, NORMAL_VOLS_USD_STD); assertEquals(pvDeltaLong.getAmount(), -pvDeltaShort.getAmount(), TOLERANCE_PV); }
public void present_value_gamma_after_expiry() { CurrencyAmount pvGamma = PRICER_SWAPTION_NORMAL.presentValueGamma(SWAPTION_PAST, MULTI_USD, NORMAL_VOLS_USD_STD); assertEquals(pvGamma.getAmount(), 0d, TOLERANCE_PV); }
public void test_implied_volatility_after_expiry() { assertThrowsIllegalArg(() -> PRICER_SWAPTION_NORMAL.impliedVolatility(SWAPTION_PAST, MULTI_USD, NORMAL_VOLS_USD_STD)); }
public void present_value_delta_after_expiry() { CurrencyAmount pvDelta = PRICER_SWAPTION_NORMAL.presentValueDelta(SWAPTION_PAST, MULTI_USD, NORMAL_VOLS_USD_STD); assertEquals(pvDelta.getAmount(), 0d, TOLERANCE_PV); }
public void present_value_gamma_long_short_parity() { CurrencyAmount pvGammaLong = PRICER_SWAPTION_NORMAL.presentValueGamma(SWAPTION_LONG_REC, MULTI_USD, NORMAL_VOLS_USD_STD); CurrencyAmount pvGammaShort = PRICER_SWAPTION_NORMAL.presentValueGamma(SWAPTION_SHORT_REC, MULTI_USD, NORMAL_VOLS_USD_STD); assertEquals(pvGammaLong.getAmount(), -pvGammaShort.getAmount(), TOLERANCE_PV); }
public void test_implied_volatility() { double forward = PRICER_SWAP.parRate(RSWAP_REC, MULTI_USD); double volExpected = NORMAL_VOLS_USD_STD.volatility(SWAPTION_LONG_REC.getExpiry(), SWAP_TENOR_YEAR, STRIKE, forward); double volComputed = PRICER_SWAPTION_NORMAL .impliedVolatility(SWAPTION_LONG_PAY, MULTI_USD, NORMAL_VOLS_USD_STD); assertEquals(volComputed, volExpected, TOLERANCE_RATE); }
public void present_value_after_expiry() { CurrencyAmount pv = PRICER_SWAPTION_NORMAL.presentValue(SWAPTION_PAST, MULTI_USD, NORMAL_VOLS_USD_STD); assertEquals(pv.getAmount(), 0.0d, TOLERANCE_PV); }
public void present_value_sensitivity_long_short_parity() { PointSensitivities pvptLong = PRICER_SWAPTION_NORMAL .presentValueSensitivityRatesStickyStrike(SWAPTION_LONG_REC, MULTI_USD, NORMAL_VOLS_USD_STD).build(); PointSensitivities pvptShort = PRICER_SWAPTION_NORMAL .presentValueSensitivityRatesStickyStrike(SWAPTION_SHORT_REC, MULTI_USD, NORMAL_VOLS_USD_STD).build(); CurrencyParameterSensitivities pvpsLong = MULTI_USD.parameterSensitivity(pvptLong); CurrencyParameterSensitivities pvpsShort = MULTI_USD.parameterSensitivity(pvptShort); assertTrue(pvpsLong.equalWithTolerance(pvpsShort.multipliedBy(-1.0), TOLERANCE_PV_DELTA)); }
public void present_value_sensitivityBlackVolatility_at_expiry() { SwaptionSensitivity sensiRec = PRICER_SWAPTION_NORMAL.presentValueSensitivityModelParamsVolatility( SWAPTION_REC_AT_EXPIRY, MULTI_USD, NORMAL_VOLS_USD_STD); assertEquals(sensiRec.getSensitivity(), 0d, TOLERANCE_PV); SwaptionSensitivity sensiPay = PRICER_SWAPTION_NORMAL.presentValueSensitivityModelParamsVolatility( SWAPTION_PAY_AT_EXPIRY, MULTI_USD, NORMAL_VOLS_USD_STD); assertEquals(sensiPay.getSensitivity(), 0d, TOLERANCE_PV); }
public void present_value_delta_at_expiry() { CurrencyAmount pvDeltaRec = PRICER_SWAPTION_NORMAL.presentValueDelta(SWAPTION_REC_AT_EXPIRY, MULTI_USD, NORMAL_VOLS_USD_STD); assertEquals(pvDeltaRec.getAmount(), 0d, TOLERANCE_PV); CurrencyAmount pvDeltaPay = PRICER_SWAPTION_NORMAL.presentValueDelta(SWAPTION_PAY_AT_EXPIRY, MULTI_USD, NORMAL_VOLS_USD_STD); double pvbp = PRICER_SWAP.getLegPricer().pvbp(RSWAP_REC.getLegs(SwapLegType.FIXED).get(0), MULTI_USD); assertEquals(pvDeltaPay.getAmount(), Math.abs(pvbp), TOLERANCE_PV); }
public void present_value_gamma_payer_receiver_parity() { CurrencyAmount pvGammaLongPay = PRICER_SWAPTION_NORMAL.presentValueGamma(SWAPTION_LONG_PAY, MULTI_USD, NORMAL_VOLS_USD_STD); CurrencyAmount pvGammaShortRec = PRICER_SWAPTION_NORMAL.presentValueGamma(SWAPTION_SHORT_REC, MULTI_USD, NORMAL_VOLS_USD_STD); assertEquals(pvGammaLongPay.getAmount() + pvGammaShortRec.getAmount(), 0d, TOLERANCE_PV); }