SwaptionPhysicalFixedIborBlackMethod { public PresentValueSwaptionSurfaceSensitivity presentValueBlackSensitivity(final SwaptionPhysicalFixedIbor swaption, final BlackSwaptionFlatProviderInterface blackMulticurves) { ArgumentChecker.notNull(swaption, "Swaption"); ArgumentChecker.notNull(blackMulticurves, "Black volatility for swaption and multicurve"); final GeneratorInstrument<GeneratorAttributeIR> generatorSwap = blackMulticurves.getBlackParameters().getGeneratorSwap(); Calendar calendar; DayCount dayCountModification; if (generatorSwap instanceof GeneratorSwapFixedIbor) { final GeneratorSwapFixedIbor fixedIborGenerator = (GeneratorSwapFixedIbor) generatorSwap; calendar = fixedIborGenerator.getCalendar(); dayCountModification = fixedIborGenerator.getFixedLegDayCount(); } else if (generatorSwap instanceof GeneratorSwapFixedON) { final GeneratorSwapFixedON fixedONGenerator = (GeneratorSwapFixedON) generatorSwap; calendar = fixedONGenerator.getOvernightCalendar(); dayCountModification = fixedONGenerator.getFixedLegDayCount(); } else if (generatorSwap instanceof GeneratorSwapFixedCompoundedONCompounded) { final GeneratorSwapFixedCompoundedONCompounded fixedCompoundedON = (GeneratorSwapFixedCompoundedONCompounded) generatorSwap; calendar = fixedCompoundedON.getOvernightCalendar(); dayCountModification = fixedCompoundedON.getFixedLegDayCount(); } else { throw new IllegalArgumentException("Cannot handle swap with underlying generator of type " + generatorSwap.getClass()); } final MulticurveProviderInterface multicurves = blackMulticurves.getMulticurveProvider(); final double pvbpModified = METHOD_SWAP.presentValueBasisPoint(swaption.getUnderlyingSwap(), dayCountModification, calendar, multicurves); final double forwardModified = PRDC.visitFixedCouponSwap(swaption.getUnderlyingSwap(), dayCountModification, multicurves); final double strikeModified = METHOD_SWAP.couponEquivalent(swaption.getUnderlyingSwap(), pvbpModified, multicurves); final double maturity = swaption.getMaturityTime(); final EuropeanVanillaOption option = new EuropeanVanillaOption(strikeModified, swaption.getTimeToExpiry(), swaption.isCall()); final DoublesPair point = DoublesPair.of(swaption.getTimeToExpiry(), maturity); final BlackPriceFunction blackFunction = new BlackPriceFunction(); final double volatility = blackMulticurves.getBlackParameters().getVolatility(point); final BlackFunctionData dataBlack = new BlackFunctionData(forwardModified, 1.0, volatility); final double[] bsAdjoint = blackFunction.getPriceAdjoint(option, dataBlack); final Map<DoublesPair, Double> sensitivity = new HashMap<>(); sensitivity.put(point, bsAdjoint[2] * pvbpModified * (swaption.isLong() ? 1.0 : -1.0)); return new PresentValueSwaptionSurfaceSensitivity(sensitivity, blackMulticurves.getBlackParameters().getGeneratorSwap()); } private  SwaptionPhysicalFixedIborBlackMethod(); static SwaptionPhysicalFixedIborBlackMethod getInstance(); MultipleCurrencyAmount presentValue(final SwaptionPhysicalFixedIbor swaption, final BlackSwaptionFlatProviderInterface blackMulticurves); double impliedVolatility(final SwaptionPhysicalFixedIbor swaption, final BlackSwaptionFlatProviderInterface blackMulticurves); MultipleCurrencyMulticurveSensitivity presentValueCurveSensitivity(final SwaptionPhysicalFixedIbor swaption, final BlackSwaptionFlatProviderInterface blackMulticurves); MultipleCurrencyMulticurveSensitivity presentValueSecondOrderCurveSensitivity(final SwaptionPhysicalFixedIbor swaption, final BlackSwaptionFlatProviderInterface blackMulticurves); PresentValueSwaptionSurfaceSensitivity presentValueBlackSensitivity(final SwaptionPhysicalFixedIbor swaption, final BlackSwaptionFlatProviderInterface blackMulticurves);  }
@Test public void presentValueBlackSensitivity() { final double shift = 1.0E-6; final PresentValueSwaptionSurfaceSensitivity pvbvs = METHOD_BLACK.presentValueBlackSensitivity(SWAPTION_LONG_REC, BLACK_MULTICURVES); final BlackFlatSwaptionParameters BlackP = BlackDataSets.createBlackSwaptionEUR6Shift(shift); final BlackSwaptionFlatProviderDiscount curvesBlackP = new BlackSwaptionFlatProviderDiscount(MULTICURVES, BlackP); final MultipleCurrencyAmount pvP = METHOD_BLACK.presentValue(SWAPTION_LONG_REC, curvesBlackP); final BlackFlatSwaptionParameters BlackM = BlackDataSets.createBlackSwaptionEUR6Shift(-shift); final BlackSwaptionFlatProviderDiscount curvesBlackM = new BlackSwaptionFlatProviderDiscount(MULTICURVES, BlackM); final MultipleCurrencyAmount pvM = METHOD_BLACK.presentValue(SWAPTION_LONG_REC, curvesBlackM); final DoublesPair point = DoublesPair.of(SWAPTION_LONG_REC.getTimeToExpiry(), SWAPTION_LONG_REC.getMaturityTime()); assertEquals("Swaption Black method: present value volatility sensitivity", (pvP.getAmount(EUR) - pvM.getAmount(EUR)) / (2 * shift), pvbvs.getSensitivity().getMap().get(point), TOLERANCE_PV_DELTA); }
@Test public void presentValueBlackSensitivityMethodVsCalculator() { final PresentValueSwaptionSurfaceSensitivity pvbsMethod = METHOD_BLACK.presentValueBlackSensitivity(SWAPTION_LONG_REC, BLACK_MULTICURVES); final PresentValueSwaptionSurfaceSensitivity pvbsCalculator = SWAPTION_LONG_REC.accept(PVBSSBSC, BLACK_MULTICURVES); assertEquals("Swaption Black method: present value", pvbsMethod, pvbsCalculator); }