final double deltaShift = 1.0E-7;
pvsCapLong = pvsCapLong.cleaned();
// 1. Forward curve sensitivity
final String bumpedCurveName = "Bumped Curve";
final String[] bumpedCurvesForwardName = {FUNDING_CURVE_NAME, bumpedCurveName };
final CapFloorIbor capBumpedForward = (CapFloorIbor) CAP_LONG_DEFINITION.toDerivative(REFERENCE_DATE, bumpedCurvesForwardName);
final YieldAndDiscountCurve curveForward = curves.getCurve(FORWARD_CURVE_NAME);
final Set<Double> timeForwardSet = new TreeSet<>();
timeForwardSet.add(CAP_LONG.getFixingPeriodStartTime());
timeForwardSet.add(CAP_LONG.getFixingPeriodEndTime());
final int nbForwardDate = timeForwardSet.size();
final List<Double> timeForwardList = new ArrayList<>(timeForwardSet);
Double[] timeForwardArray = new Double[nbForwardDate];
timeForwardArray = timeForwardList.toArray(timeForwardArray);
final double[] yieldsForward = new double[nbForwardDate + 1];
final double[] nodeTimesForward = new double[nbForwardDate + 1];
yieldsForward[0] = curveForward.getInterestRate(0.0);
for (int i = 0; i < nbForwardDate; i++) {
nodeTimesForward[i + 1] = timeForwardArray[i];
yieldsForward[i + 1] = curveForward.getInterestRate(nodeTimesForward[i + 1]);
}
final YieldAndDiscountCurve tempCurveForward = YieldCurve.from(InterpolatedDoublesCurve.fromSorted(nodeTimesForward, yieldsForward, new LinearInterpolator1D()));
final List<DoublesPair> tempForward = pvsCapLong.getSensitivities().get(FORWARD_CURVE_NAME);
final double[] resFwd = new double[nbForwardDate];
for (int i = 0; i < nbForwardDate; i++) {
final YieldAndDiscountCurve bumpedCurveForward = tempCurveForward.withSingleShift(nodeTimesForward[i + 1], deltaShift);
final YieldCurveBundle curvesBumpedForward = new YieldCurveBundle();
curvesBumpedForward.addAll(curves);
curvesBumpedForward.setCurve("Bumped Curve", bumpedCurveForward);
final SABRInterestRateDataBundle sabrBundleBumped = new SABRInterestRateDataBundle(sabrParameter, curvesBumpedForward);
final double bumpedpv = METHOD.presentValue(capBumpedForward, sabrBundleBumped).getAmount();
resFwd[i] = (bumpedpv - pv) / deltaShift;
final DoublesPair pair = tempForward.get(i);
assertEquals("Sensitivity to forward curve: Node " + i, nodeTimesForward[i + 1], pair.getFirst(), 1E-8);
assertEquals("Sensitivity to forward curve: Node " + i, resFwd[i], pair.getSecond(), deltaTolerance);
}
// 2. Funding curve sensitivity
final String[] bumpedCurvesFundingName = {bumpedCurveName, FORWARD_CURVE_NAME };
final CapFloorIbor capBumpedFunding = (CapFloorIbor) CAP_LONG_DEFINITION.toDerivative(REFERENCE_DATE, bumpedCurvesFundingName);
final int nbPayDate = 1;
final YieldAndDiscountCurve curveFunding = curves.getCurve(FUNDING_CURVE_NAME);
final double[] yieldsFunding = new double[nbPayDate + 1];
final double[] nodeTimesFunding = new double[nbPayDate + 1];
yieldsFunding[0] = curveFunding.getInterestRate(0.0);