public void test_build() { ZeroRateSensitivity base = ZeroRateSensitivity.of(GBP, YEARFRAC, 32d); PointSensitivities test = base.build(); assertEquals(test.getSensitivities(), ImmutableList.of(base)); }
public void presentValueSensitivity_onFix_ts() { PointSensitivities ptsCpn = PRICER_CMS.presentValueSensitivity(COUPON, RATES_PROVIDER_ON_FIX_TS).build(); PointSensitivities ptsCapletOtm = PRICER_CMS.presentValueSensitivity(CAPLET, RATES_PROVIDER_ON_FIX_TS).build(); PointSensitivities ptsCapletItm = PRICER_CMS.presentValueSensitivity(CAPLET_NEGATIVE, RATES_PROVIDER_ON_FIX_TS).build(); PointSensitivities ptsFloorletItm = PRICER_CMS.presentValueSensitivity(FLOORLET, RATES_PROVIDER_ON_FIX_TS).build(); PointSensitivities ptsFloorletOtm = PRICER_CMS.presentValueSensitivity(FLOORLET_NEGATIVE, RATES_PROVIDER_ON_FIX_TS).build(); double factor = NOTIONAL * COUPON.getYearFraction(); ZeroRateSensitivity pts = RATES_PROVIDER_ON_FIX_TS.discountFactors(EUR).zeroRatePointSensitivity(PAYMENT); assertTrue(ptsCpn.equalWithTolerance(pts.build().multipliedBy(factor * OBS_INDEX), TOLERANCE_DELTA)); assertTrue(ptsCapletOtm.equalWithTolerance(pts.build().multipliedBy(0d), TOLERANCE_DELTA)); assertTrue(ptsCapletItm.equalWithTolerance(pts.build().multipliedBy(factor * (OBS_INDEX - STRIKE_NEGATIVE)), TOLERANCE_DELTA)); assertTrue(ptsFloorletItm.equalWithTolerance(pts.build().multipliedBy(factor * (STRIKE - OBS_INDEX)), TOLERANCE_DELTA)); assertTrue(ptsFloorletOtm.equalWithTolerance(pts.build().multipliedBy(0d), TOLERANCE_DELTA)); }
public void presentValueSensitivity_afterFix() { PointSensitivities ptsCpn = PRICER_CMS.presentValueSensitivity(COUPON, RATES_PROVIDER_AFTER_FIX).build(); PointSensitivities ptsCapletOtm = PRICER_CMS.presentValueSensitivity(CAPLET, RATES_PROVIDER_AFTER_FIX).build(); PointSensitivities ptsCapletItm = PRICER_CMS.presentValueSensitivity(CAPLET_NEGATIVE, RATES_PROVIDER_AFTER_FIX).build(); PointSensitivities ptsFloorletItm = PRICER_CMS.presentValueSensitivity(FLOORLET, RATES_PROVIDER_AFTER_FIX).build(); PointSensitivities ptsFloorletOtm = PRICER_CMS.presentValueSensitivity(FLOORLET_NEGATIVE, RATES_PROVIDER_AFTER_FIX).build(); double factor = NOTIONAL * COUPON.getYearFraction(); ZeroRateSensitivity pts = RATES_PROVIDER_AFTER_FIX.discountFactors(EUR).zeroRatePointSensitivity(PAYMENT); assertTrue(ptsCpn.equalWithTolerance(pts.build().multipliedBy(factor * OBS_INDEX), TOLERANCE_DELTA)); assertTrue(ptsCapletOtm.equalWithTolerance(pts.build().multipliedBy(0d), TOLERANCE_DELTA)); assertTrue(ptsCapletItm.equalWithTolerance(pts.build().multipliedBy(factor * (OBS_INDEX - STRIKE_NEGATIVE)), TOLERANCE_DELTA)); assertTrue(ptsFloorletItm.equalWithTolerance(pts.build().multipliedBy(factor * (STRIKE - OBS_INDEX)), TOLERANCE_DELTA)); assertTrue(ptsFloorletOtm.equalWithTolerance(pts.build().multipliedBy(0d), TOLERANCE_DELTA)); }
public void test_curveParameterSensitivity_noSensi() { ImmutableLegalEntityDiscountingProvider test = ImmutableLegalEntityDiscountingProvider.builder() .issuerCurves(ImmutableMap.of(Pair.of(GROUP_ISSUER, GBP), DSC_FACTORS_ISSUER)) .issuerCurveGroups(ImmutableMap.of(ID_ISSUER, GROUP_ISSUER)) .repoCurves(ImmutableMap.of(Pair.of(GROUP_REPO_ISSUER, GBP), DSC_FACTORS_REPO)) .repoCurveGroups(ImmutableMap.of(ID_ISSUER, GROUP_REPO_ISSUER)) .valuationDate(DATE) .build(); ZeroRateSensitivity sensi = ZeroRateSensitivity.of(USD, DSC_FACTORS_ISSUER.relativeYearFraction(date(2018, 11, 24)), 25d); CurrencyParameterSensitivities computed = test.parameterSensitivity(sensi.build()); assertEquals(computed, CurrencyParameterSensitivities.empty()); }
public void presentValueSensitivity_onFix_nots() { PointSensitivities pv = PRICER_CMS.presentValueSensitivity(COUPON, RATES_PROVIDER_ON_FIX).build(); double df = RATES_PROVIDER_ON_FIX.discountFactor(EUR, PAYMENT); ZeroRateSensitivity dfdr = RATES_PROVIDER_ON_FIX.discountFactors(EUR).zeroRatePointSensitivity(PAYMENT); double forward = PRICER_SWAP.parRate(COUPON.getUnderlyingSwap(), RATES_PROVIDER_ON_FIX); PointSensitivities forwarddr = PRICER_SWAP.parRateSensitivity(COUPON.getUnderlyingSwap(), RATES_PROVIDER_ON_FIX).build(); PointSensitivities expected = forwarddr.multipliedBy(df).combinedWith(dfdr.multipliedBy(forward).build()) .multipliedBy(NOTIONAL * ACC_FACTOR); assertTrue(pv.equalWithTolerance(expected, TOLERANCE_DELTA)); }
public void presentValueSensitivity_beforeFixing_coupon() { PointSensitivities pv = PRICER_CMS.presentValueSensitivity(COUPON, RATES_PROVIDER).build(); double df = RATES_PROVIDER.discountFactor(EUR, PAYMENT); ZeroRateSensitivity dfdr = RATES_PROVIDER.discountFactors(EUR).zeroRatePointSensitivity(PAYMENT); double forward = PRICER_SWAP.parRate(COUPON.getUnderlyingSwap(), RATES_PROVIDER); PointSensitivities forwarddr = PRICER_SWAP.parRateSensitivity(COUPON.getUnderlyingSwap(), RATES_PROVIDER).build(); PointSensitivities expected = forwarddr.multipliedBy(df).combinedWith(dfdr.multipliedBy(forward).build()) .multipliedBy(NOTIONAL * ACC_FACTOR); assertTrue(pv.equalWithTolerance(expected, TOLERANCE_DELTA)); }
/** * Calculates the par spread sensitivity to the curves. * <p> * The sensitivity is reported in the counter currency of the product, but is actually dimensionless. * * @param swap the product * @param provider the rates provider * @return the spread curve sensitivity */ public PointSensitivities parSpreadSensitivity(ResolvedFxSwap swap, RatesProvider provider) { Payment counterPaymentNear = swap.getNearLeg().getCounterCurrencyPayment(); MultiCurrencyAmount pv = presentValue(swap, provider); double pvCounterCcy = pv.convertedTo(counterPaymentNear.getCurrency(), provider).getAmount(); double dfEnd = provider.discountFactor(counterPaymentNear.getCurrency(), swap.getFarLeg().getPaymentDate()); double notionalBaseCcy = swap.getNearLeg().getBaseCurrencyPayment().getAmount(); double ps = -pvCounterCcy / (notionalBaseCcy * dfEnd); // backward sweep double psBar = 1d; double pvCounterCcyBar = -1d / (notionalBaseCcy * dfEnd) * psBar; double dfEndBar = -ps / dfEnd * psBar; ZeroRateSensitivity ddfEnddr = provider.discountFactors(counterPaymentNear.getCurrency()) .zeroRatePointSensitivity(swap.getFarLeg().getPaymentDate()); PointSensitivities result = ddfEnddr.multipliedBy(dfEndBar).build(); PointSensitivities dpvdr = presentValueSensitivity(swap, provider); PointSensitivities dpvdrConverted = dpvdr.convertedTo(counterPaymentNear.getCurrency(), provider); return result.combinedWith(dpvdrConverted.multipliedBy(pvCounterCcyBar)); }