ArgumentChecker.notNull(swaption, "swaption");
ArgumentChecker.notNull(sabrData, "SARB data");
final AnnuityCouponFixed annuityFixed = swaption.getUnderlyingSwap().getFixedLeg();
final double forward = swaption.getUnderlyingSwap().accept(PRC, sabrData);
// Derivative of the forward with respect to the rates.
final InterestRateCurveSensitivity forwardDr = new InterestRateCurveSensitivity(swaption.getUnderlyingSwap().accept(PRSC, sabrData));
final double pvbp = METHOD_SWAP.getAnnuityCash(swaption.getUnderlyingSwap(), forward);
// Derivative of the cash annuity with respect to the forward.
final double pvbpDf = METHOD_SWAP.getAnnuityCashDerivative(swaption.getUnderlyingSwap(), forward);
// Implementation note: strictly speaking, the strike equivalent is curve dependent; that dependency is ignored.
final double maturity = annuityFixed.getNthPayment(annuityFixed.getNumberOfPayments() - 1).getPaymentTime() - swaption.getSettlementTime();
final BlackPriceFunction blackFunction = new BlackPriceFunction();
final double[] volatilityAdjoint = sabrData.getSABRParameter().getVolatilityAdjoint(swaption.getTimeToExpiry(), maturity, swaption.getStrike(), forward);
final double discountFactorSettle = sabrData.getCurve(annuityFixed.getNthPayment(0).getFundingCurveName()).getDiscountFactor(swaption.getSettlementTime());
final BlackFunctionData dataBlack = new BlackFunctionData(forward, 1.0, volatilityAdjoint[0]);
final double[] bsAdjoint = blackFunction.getPriceAdjoint(swaption, dataBlack);
final double sensiDF = -swaption.getSettlementTime() * discountFactorSettle * pvbp * bsAdjoint[0];
final List<DoublesPair> list = new ArrayList<>();
list.add(new DoublesPair(swaption.getSettlementTime(), sensiDF));
final Map<String, List<DoublesPair>> resultMap = new HashMap<>();
resultMap.put(annuityFixed.getNthPayment(0).getFundingCurveName(), list);
InterestRateCurveSensitivity result = new InterestRateCurveSensitivity(resultMap);
result = result.plus(forwardDr.multipliedBy(discountFactorSettle * (pvbpDf * bsAdjoint[0] + pvbp * (bsAdjoint[1] + bsAdjoint[2] * volatilityAdjoint[1]))));
if (!swaption.isLong()) {
result = result.multipliedBy(-1);
}
return result;
}