/**
* Tests the par rate curve sensitivity when the valuation date is on trade date.
*/
public void parRateCurveSensitivityTrade() {
final ZonedDateTime referenceDate = DateUtils.getUTCDate(2011, 12, 12);
final DepositZero deposit = DEPOSIT_DEFINITION.toDerivative(referenceDate, CURVES_NAME[0]);
final InterestRateCurveSensitivity prcsMethod = METHOD_DEPOSIT.parRateCurveSensitivity(deposit, CURVES);
final List<DoublesPair> sensiPvDisc = prcsMethod.getSensitivities().get(CURVES_NAME[0]);
final double pr = METHOD_DEPOSIT.parRate(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 prBumped = METHOD_DEPOSIT.parRate(deposit, CURVES);
result[loopnode] = (prBumped - pr) / deltaShift;
final DoublesPair pairPv = sensiPvDisc.get(loopnode);
assertEquals("Sensitivity coupon pv to forward curve: Node " + loopnode, nodeTimesExtended[loopnode + 1], pairPv.getFirst(), TOLERANCE_TIME);
assertEquals("Sensitivity finite difference method: node sensitivity", pairPv.second, result[loopnode], TOLERANCE_PRICE);
}
CURVES.replaceCurve(CURVES_NAME[0], curveToBump);
InterestRateCurveSensitivity prcsCalculator = new InterestRateCurveSensitivity(deposit.accept(PRCSC, CURVES));
prcsCalculator = prcsCalculator.cleaned(0.0, 1.0E-4);
AssertSensivityObjects.assertEquals("DepositZero: par rate curve sensitivity", prcsMethod, prcsCalculator, TOLERANCE_RATE);
}