/**
* Tests parSpread curve sensitivity.
*/
public void parSpreadCurveSensitivity() {
final ZonedDateTime referenceDate = TRADE_DATE;
final Cash deposit = DEPOSIT_DEFINITION.toDerivative(referenceDate, CURVES_NAME[0]);
final InterestRateCurveSensitivity pscsMethod = METHOD_DEPOSIT.parSpreadCurveSensitivity(deposit, CURVES);
final List<DoublesPair> sensiPvDisc = pscsMethod.getSensitivities().get(CURVES_NAME[0]);
final double ps = METHOD_DEPOSIT.parSpread(deposit, CURVES);
final YieldAndDiscountCurve curveToBump = CURVES.getCurve(CURVES_NAME[0]);
final double deltaShift = 0.0001;
final int nbNode = 2;
final double[] result = new double[nbNode];
final double[] nodeTimesExtended = new double[nbNode + 1];
nodeTimesExtended[1] = deposit.getStartTime();
nodeTimesExtended[2] = deposit.getEndTime();
final double[] yields = new double[nbNode + 1];
yields[0] = curveToBump.getInterestRate(0.0);
yields[1] = curveToBump.getInterestRate(nodeTimesExtended[1]);
yields[2] = curveToBump.getInterestRate(nodeTimesExtended[2]);
final YieldAndDiscountCurve curveNode = YieldCurve.from(InterpolatedDoublesCurve.fromSorted(nodeTimesExtended, yields, new LinearInterpolator1D()));
for (int loopnode = 0; loopnode < nbNode; loopnode++) {
final YieldAndDiscountCurve curveBumped = curveNode.withSingleShift(nodeTimesExtended[loopnode + 1], deltaShift);
CURVES.replaceCurve(CURVES_NAME[0], curveBumped);
final double psBumped = METHOD_DEPOSIT.parSpread(deposit, CURVES);
result[loopnode] = (psBumped - ps) / deltaShift;
final DoublesPair pairPv = sensiPvDisc.get(loopnode);
assertEquals("Sensitivity par spread to curve: Node " + loopnode, nodeTimesExtended[loopnode + 1], pairPv.getFirst(), TOLERANCE_TIME);
assertEquals("Sensitivity par spread to curve: Node", pairPv.second, result[loopnode], TOLERANCE_PRICE);
}
CURVES.replaceCurve(CURVES_NAME[0], curveToBump);
InterestRateCurveSensitivity prcsCalculator = deposit.accept(PSCSC, CURVES);
prcsCalculator = prcsCalculator.cleaned(0.0, 1.0E-4);
AssertSensivityObjects.assertEquals("DepositZero: par rate curve sensitivity", pscsMethod, prcsCalculator, TOLERANCE_SPREAD_DELTA);
}