SwaptionPhysicalFixedIborBlackMethod { public MultipleCurrencyMulticurveSensitivity presentValueCurveSensitivity(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 MulticurveSensitivity pvbpModifiedDr = METHOD_SWAP.presentValueBasisPointCurveSensitivity(swaption.getUnderlyingSwap(), dayCountModification, calendar, multicurves); final MulticurveSensitivity forwardModifiedDr = PRCSDC.visitFixedCouponSwap(swaption.getUnderlyingSwap(), dayCountModification, multicurves); final EuropeanVanillaOption option = new EuropeanVanillaOption(strikeModified, swaption.getTimeToExpiry(), swaption.isCall()); final BlackPriceFunction blackFunction = new BlackPriceFunction(); final double volatility = blackMulticurves.getBlackParameters().getVolatility(swaption.getTimeToExpiry(), maturity); final BlackFunctionData dataBlack = new BlackFunctionData(forwardModified, 1.0, volatility); final double[] bsAdjoint = blackFunction.getPriceAdjoint(option, dataBlack); MulticurveSensitivity result = pvbpModifiedDr.multipliedBy(bsAdjoint[0]); result = result.plus(forwardModifiedDr.multipliedBy(pvbpModified * bsAdjoint[1])); if (!swaption.isLong()) { result = result.multipliedBy(-1); } return MultipleCurrencyMulticurveSensitivity.of(swaption.getCurrency(), result); } 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 presentValueCurveSensitivity() { final MultipleCurrencyParameterSensitivity pvpsExact = PS_BS_C.calculateSensitivity(SWAPTION_LONG_REC, BLACK_MULTICURVES, BLACK_MULTICURVES.getMulticurveProvider().getAllNames()); final MultipleCurrencyParameterSensitivity pvpsFD = PS_BS_FDC.calculateSensitivity(SWAPTION_LONG_REC, BLACK_MULTICURVES); AssertSensitivityObjects.assertEquals("Swaption Black method: presentValueCurveSensitivity ", pvpsExact, pvpsFD, TOLERANCE_PV_DELTA); }
@Test public void presentValueCurveSensitivityMethodVsCalculator() { final MultipleCurrencyMulticurveSensitivity pvcsMethod = METHOD_BLACK.presentValueCurveSensitivity(SWAPTION_LONG_REC, BLACK_MULTICURVES); final MultipleCurrencyMulticurveSensitivity pvcsCalculator = SWAPTION_LONG_REC.accept(PVCSBSC, BLACK_MULTICURVES); AssertSensitivityObjects.assertEquals("Swaption Black method: present value", pvcsMethod, pvcsCalculator, TOLERANCE_PV_DELTA); }