*/
public InterestRateCurveSensitivity presentValueCurveSensitivity(final SwaptionPhysicalFixedIbor swaption, final HullWhiteOneFactorPiecewiseConstantDataBundle hwData) {
ArgumentChecker.notNull(swaption, "swaption");
ArgumentChecker.notNull(hwData, "Hull-White data");
final int nbSigma = hwData.getHullWhiteParameter().getVolatility().length;
final AnnuityPaymentFixed cfe = swaption.getUnderlyingSwap().accept(CFEC, hwData);
//Forward sweep
final double expiryTime = swaption.getTimeToExpiry();
final double[] alpha = new double[cfe.getNumberOfPayments()];
final double[][] alphaDerivatives = new double[cfe.getNumberOfPayments()][nbSigma];
final double[] df = new double[cfe.getNumberOfPayments()];
final double[] discountedCashFlow = new double[cfe.getNumberOfPayments()];
for (int loopcf = 0; loopcf < cfe.getNumberOfPayments(); loopcf++) {
alpha[loopcf] = MODEL.alpha(hwData.getHullWhiteParameter(), 0.0, expiryTime, expiryTime, cfe.getNthPayment(loopcf).getPaymentTime(), alphaDerivatives[loopcf]);
df[loopcf] = hwData.getCurve(cfe.getDiscountCurve()).getDiscountFactor(cfe.getNthPayment(loopcf).getPaymentTime());
discountedCashFlow[loopcf] = df[loopcf] * cfe.getNthPayment(loopcf).getAmount();
}
final double kappa = MODEL.kappa(discountedCashFlow, alpha);
final double omega = (swaption.getUnderlyingSwap().getFixedLeg().isPayer() ? -1.0 : 1.0);
final double[] ncdf = new double[cfe.getNumberOfPayments()];
for (int loopcf = 0; loopcf < cfe.getNumberOfPayments(); loopcf++) {
ncdf[loopcf] = NORMAL.getCDF(omega * (kappa + alpha[loopcf]));
}
//Backward sweep
final double pvBar = 1.0;
final double[] discountedCashFlowBar = new double[cfe.getNumberOfPayments()];
final double[] dfBar = new double[cfe.getNumberOfPayments()];
final double[] cfeAmountBar = new double[cfe.getNumberOfPayments()];
final List<DoublesPair> listDfSensi = new ArrayList<>();
for (int loopcf = 0; loopcf < cfe.getNumberOfPayments(); loopcf++) {
discountedCashFlowBar[loopcf] = ncdf[loopcf] * pvBar;
dfBar[loopcf] = cfe.getNthPayment(loopcf).getAmount() * discountedCashFlowBar[loopcf];
cfeAmountBar[loopcf] = df[loopcf] * discountedCashFlowBar[loopcf];
final DoublesPair dfSensi = new DoublesPair(cfe.getNthPayment(loopcf).getPaymentTime(), -cfe.getNthPayment(loopcf).getPaymentTime() * df[loopcf] * dfBar[loopcf]);
listDfSensi.add(dfSensi);
}
final Map<String, List<DoublesPair>> pvsDF = new HashMap<>();
pvsDF.put(cfe.getDiscountCurve(), listDfSensi);
InterestRateCurveSensitivity sensitivity = new InterestRateCurveSensitivity(pvsDF);
final Map<Double, InterestRateCurveSensitivity> cfeCurveSensi = swaption.getUnderlyingSwap().accept(CFECSC, hwData);
for (int loopcf = 0; loopcf < cfe.getNumberOfPayments(); loopcf++) {
final InterestRateCurveSensitivity sensiCfe = cfeCurveSensi.get(cfe.getNthPayment(loopcf).getPaymentTime());
if (!(sensiCfe == null)) { // There is some sensitivity to that cfe.
sensitivity = sensitivity.plus(sensiCfe.multipliedBy(cfeAmountBar[loopcf]));
}
}
return sensitivity;