ArgumentChecker.notNull(sabr, "SABR cap provider");
final MulticurveProviderInterface multicurve = sabr.getMulticurveProvider();
final EuropeanVanillaOption option = new EuropeanVanillaOption(cap.getStrike(), cap.getFixingTime(), cap.isCap());
final double forward = multicurve.getForwardRate(cap.getIndex(), cap.getFixingPeriodStartTime(), cap.getFixingPeriodEndTime(), cap.getFixingAccrualFactor());
final double df = multicurve.getDiscountFactor(cap.getCurrency(), cap.getPaymentTime());
final MulticurveSensitivity forwardDr = MulticurveSensitivity.ofForward(sabr.getMulticurveProvider().getName(cap.getIndex()),
new ForwardSensitivity(cap.getFixingPeriodStartTime(), cap.getFixingPeriodEndTime(), cap.getFixingAccrualFactor(), 1.0));
final double dfDr = -cap.getPaymentTime() * df;
final double maturity = cap.getFixingPeriodEndTime() - cap.getFixingPeriodStartTime();
final List<DoublesPair> list = new ArrayList<>();
list.add(new DoublesPair(cap.getPaymentTime(), dfDr));
final Map<String, List<DoublesPair>> resultMap = new HashMap<>();
resultMap.put(multicurve.getName(cap.getCurrency()), list);
MulticurveSensitivity result = MulticurveSensitivity.ofYieldDiscounting(resultMap);
double bsPrice;
double bsDforward;
if (cap.getStrike() <= _cutOffStrike) { // No extrapolation
final double[] volatilityAdjoint = sabr.getSABRParameter().getVolatilityAdjoint(cap.getFixingTime(), maturity, cap.getStrike(), forward);
final BlackFunctionData dataBlack = new BlackFunctionData(forward, 1.0, volatilityAdjoint[0]);
final double[] bsAdjoint = BLACK_FUNCTION.getPriceAdjoint(option, dataBlack);
bsPrice = bsAdjoint[0];
bsDforward = df * (bsAdjoint[1] + bsAdjoint[2] * volatilityAdjoint[1]);
} else { // With extrapolation
final DoublesPair expiryMaturity = new DoublesPair(cap.getFixingTime(), maturity);
final double alpha = sabr.getSABRParameter().getAlpha(expiryMaturity);
final double beta = sabr.getSABRParameter().getBeta(expiryMaturity);
final double rho = sabr.getSABRParameter().getRho(expiryMaturity);
final double nu = sabr.getSABRParameter().getNu(expiryMaturity);
final SABRFormulaData sabrParam = new SABRFormulaData(alpha, beta, rho, nu);
final SABRExtrapolationRightFunction sabrExtrapolation = new SABRExtrapolationRightFunction(forward, sabrParam, _cutOffStrike, cap.getFixingTime(), _mu);
bsPrice = sabrExtrapolation.price(option);
bsDforward = sabrExtrapolation.priceDerivativeForward(option);
}
result = result.multipliedBy(bsPrice);
result = result.plus(forwardDr.multipliedBy(bsDforward));
result = result.multipliedBy(cap.getNotional() * cap.getPaymentYearFraction());
return MultipleCurrencyMulticurveSensitivity.of(cap.getCurrency(), result);
}