@Test
/**
* Tests parSpread curve sensitivity.
*/
public void parSpreadCurveSensitivity() {
final ForexSwap fxSwap = (ForexSwap) FX_SWAP;
InterestRateCurveSensitivity pscsMethod = METHOD_FX_SWAP.parSpreadCurveSensitivity(fxSwap, CURVES_FX);
pscsMethod = pscsMethod.cleaned(0.0, 1.0E-8);
final double ps = METHOD_FX_SWAP.parSpread(fxSwap, CURVES_FX);
final double deltaShift = 0.000001;
final int nbNode = 2;
final double[] result = new double[nbNode];
final double[] nodeTimesExtended = new double[nbNode + 1];
nodeTimesExtended[1] = fxSwap.getNearLeg().getPaymentTime();
nodeTimesExtended[2] = fxSwap.getFarLeg().getPaymentTime();
final double[] yields = new double[nbNode + 1];
YieldAndDiscountCurve curveToBump;
YieldAndDiscountCurve curveNode;
// EUR Dsc
final List<DoublesPair> sensi1 = pscsMethod.getSensitivities().get(CURVES_NAME[0]);
curveToBump = CURVES.getCurve(CURVES_NAME[0]);
yields[0] = curveToBump.getInterestRate(0.0);
yields[1] = curveToBump.getInterestRate(nodeTimesExtended[1]);
yields[2] = curveToBump.getInterestRate(nodeTimesExtended[2]);
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_FX.replaceCurve(CURVES_NAME[0], curveBumped);
final double psBumped = METHOD_FX_SWAP.parSpread(fxSwap, CURVES_FX);
result[loopnode] = (psBumped - ps) / deltaShift;
final DoublesPair pairPv = sensi1.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_SPREAD_DELTA);
}
CURVES_FX.replaceCurve(CURVES_NAME[0], curveToBump);
// USD Dsc
final List<DoublesPair> sensi2 = pscsMethod.getSensitivities().get(CURVES_NAME[0]);
curveToBump = CURVES.getCurve(CURVES_NAME[1]);
yields[0] = curveToBump.getInterestRate(0.0);
yields[1] = curveToBump.getInterestRate(nodeTimesExtended[1]);
yields[2] = curveToBump.getInterestRate(nodeTimesExtended[2]);
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_FX.replaceCurve(CURVES_NAME[1], curveBumped);
final double psBumped = METHOD_FX_SWAP.parSpread(fxSwap, CURVES_FX);
result[loopnode] = (psBumped - ps) / deltaShift;
final DoublesPair pairPv = sensi2.get(loopnode);
assertEquals("Sensitivity par spread to curve: Node " + loopnode, nodeTimesExtended[loopnode + 1], pairPv.getFirst(), TOLERANCE_TIME);
}
CURVES_FX.replaceCurve(CURVES_NAME[1], curveToBump);
InterestRateCurveSensitivity prcsCalculator = fxSwap.accept(PSCSC, CURVES_FX);
prcsCalculator = prcsCalculator.cleaned(0.0, 1.0E-4);
AssertSensivityObjects.assertEquals("Forex swap: par rate curve sensitivity", pscsMethod, prcsCalculator, TOLERANCE_SPREAD_DELTA);
}