SABRSensitivityNodeCalculator { public static PresentValueSABRSensitivityDataBundle calculateNodeSensitivities(final PresentValueSABRSensitivityDataBundle sensitivities, final SABRInterestRateParameters parameters) { final Map<Double, Interpolator1DDataBundle> alphaData = (Map<Double, Interpolator1DDataBundle>) parameters.getAlphaSurface().getInterpolatorData(); SurfaceValue alphaNode = new SurfaceValue(); for (final Entry<DoublesPair, Double> entry : sensitivities.getAlpha().getMap().entrySet()) { final Map<DoublesPair, Double> weight = parameters.getAlphaSurface().getInterpolator().getNodeSensitivitiesForValue(alphaData, entry.getKey()); alphaNode = SurfaceValue.plus(alphaNode, SurfaceValue.multiplyBy(SurfaceValue.from(weight), entry.getValue())); } final Map<Double, Interpolator1DDataBundle> betaData = (Map<Double, Interpolator1DDataBundle>) parameters.getBetaSurface().getInterpolatorData(); SurfaceValue betaNode = new SurfaceValue(); for (final Entry<DoublesPair, Double> entry : sensitivities.getBeta().getMap().entrySet()) { final Map<DoublesPair, Double> weight = parameters.getBetaSurface().getInterpolator().getNodeSensitivitiesForValue(betaData, entry.getKey()); betaNode = SurfaceValue.plus(betaNode, SurfaceValue.multiplyBy(SurfaceValue.from(weight), entry.getValue())); } final Map<Double, Interpolator1DDataBundle> rhoData = (Map<Double, Interpolator1DDataBundle>) parameters.getRhoSurface().getInterpolatorData(); SurfaceValue rhoNode = new SurfaceValue(); for (final Entry<DoublesPair, Double> entry : sensitivities.getRho().getMap().entrySet()) { final Map<DoublesPair, Double> weight = parameters.getRhoSurface().getInterpolator().getNodeSensitivitiesForValue(rhoData, entry.getKey()); rhoNode = SurfaceValue.plus(rhoNode, SurfaceValue.multiplyBy(SurfaceValue.from(weight), entry.getValue())); } final Map<Double, Interpolator1DDataBundle> nuData = (Map<Double, Interpolator1DDataBundle>) parameters.getNuSurface().getInterpolatorData(); SurfaceValue nuNode = new SurfaceValue(); for (final Entry<DoublesPair, Double> entry : sensitivities.getNu().getMap().entrySet()) { final Map<DoublesPair, Double> weight = parameters.getNuSurface().getInterpolator().getNodeSensitivitiesForValue(nuData, entry.getKey()); nuNode = SurfaceValue.plus(nuNode, SurfaceValue.multiplyBy(SurfaceValue.from(weight), entry.getValue())); } return new PresentValueSABRSensitivityDataBundle(alphaNode, betaNode, rhoNode, nuNode); }  static PresentValueSABRSensitivityDataBundle calculateNodeSensitivities(final PresentValueSABRSensitivityDataBundle sensitivities,
      final SABRInterestRateParameters parameters);  }
@Test public void onePoint() { final DoublesPair point = DoublesPair.of(1.25, 4.0); final double alphaValue = 12345.0; final SurfaceValue alpha = SurfaceValue.from(point, alphaValue); final double betaValue = 4321.0; final SurfaceValue beta = SurfaceValue.from(point, betaValue); final double rhoValue = 2345.0; final SurfaceValue rho = SurfaceValue.from(point, 2345.0); final double nuValue = 345.0; final SurfaceValue nu = SurfaceValue.from(point, 345.0); final PresentValueSABRSensitivityDataBundle onePoint = new PresentValueSABRSensitivityDataBundle(alpha, beta, rho, nu); final PresentValueSABRSensitivityDataBundle node = SABRSensitivityNodeCalculator.calculateNodeSensitivities(onePoint, SABR_PARAMETERS); final DoublesPair[] nodeExpected = new DoublesPair[4]; nodeExpected[0] = DoublesPair.of(1.0, 2.0); nodeExpected[1] = DoublesPair.of(1.0, 5.0); nodeExpected[2] = DoublesPair.of(5.0, 2.0); nodeExpected[3] = DoublesPair.of(5.0, 5.0); for (int loopnode = 0; loopnode < 4; loopnode++) { assertTrue("SABR Node calculator " + loopnode, node.getAlpha().getMap().get(nodeExpected[loopnode]) != null); assertTrue("SABR Node calculator", Math.abs(node.getAlpha().getMap().get(nodeExpected[loopnode])) > TOLERANCE); } final Map<Double, Interpolator1DDataBundle> alphaData = (Map<Double, Interpolator1DDataBundle>) SABR_PARAMETERS.getAlphaSurface().getInterpolatorData(); final Map<DoublesPair, Double> weight = SABR_PARAMETERS.getAlphaSurface().getInterpolator().getNodeSensitivitiesForValue(alphaData, point); for (int loopnode = 0; loopnode < 4; loopnode++) { assertEquals("SABR Node calculator " + loopnode, node.getAlpha().getMap().get(nodeExpected[loopnode]), weight.get(nodeExpected[loopnode]) * alphaValue, TOLERANCE); assertEquals("SABR Node calculator " + loopnode, node.getRho().getMap().get(nodeExpected[loopnode]), weight.get(nodeExpected[loopnode]) * rhoValue, TOLERANCE); assertEquals("SABR Node calculator " + loopnode, node.getNu().getMap().get(nodeExpected[loopnode]), weight.get(nodeExpected[loopnode]) * nuValue, TOLERANCE); } }
@Test public void onePointBorder() { final DoublesPair point = DoublesPair.of(1.25, 1.5); final double alphaValue = 12345.0; final SurfaceValue alpha = SurfaceValue.from(point, alphaValue); final double betaValue = 4321.0; final SurfaceValue beta = SurfaceValue.from(point, betaValue); final double rhoValue = 2345.6; final SurfaceValue rho = SurfaceValue.from(point, rhoValue); final double nuValue = 345.67; final SurfaceValue nu = SurfaceValue.from(point, nuValue); final PresentValueSABRSensitivityDataBundle onePoint = new PresentValueSABRSensitivityDataBundle(alpha, beta, rho, nu); final PresentValueSABRSensitivityDataBundle node = SABRSensitivityNodeCalculator.calculateNodeSensitivities(onePoint, SABR_PARAMETERS); final DoublesPair[] nodeExpected = new DoublesPair[4]; nodeExpected[0] = DoublesPair.of(1.0, 1.0); nodeExpected[1] = DoublesPair.of(1.0, 2.0); nodeExpected[2] = DoublesPair.of(5.0, 2.0); for (int loopnode = 0; loopnode < 3; loopnode++) { assertTrue("SABR Node calculator " + loopnode, node.getAlpha().getMap().get(nodeExpected[loopnode]) != null); assertTrue("SABR Node calculator", Math.abs(node.getAlpha().getMap().get(nodeExpected[loopnode])) > TOLERANCE); } final Map<Double, Interpolator1DDataBundle> alphaData = (Map<Double, Interpolator1DDataBundle>) SABR_PARAMETERS.getAlphaSurface().getInterpolatorData(); final Map<DoublesPair, Double> weight = SABR_PARAMETERS.getAlphaSurface().getInterpolator().getNodeSensitivitiesForValue(alphaData, point); for (int loopnode = 0; loopnode < 3; loopnode++) { assertEquals("SABR Node calculator " + loopnode, node.getAlpha().getMap().get(nodeExpected[loopnode]), weight.get(nodeExpected[loopnode]) * alphaValue, TOLERANCE); assertEquals("SABR Node calculator " + loopnode, node.getRho().getMap().get(nodeExpected[loopnode]), weight.get(nodeExpected[loopnode]) * rhoValue, TOLERANCE); assertEquals("SABR Node calculator " + loopnode, node.getNu().getMap().get(nodeExpected[loopnode]), weight.get(nodeExpected[loopnode]) * nuValue, TOLERANCE); } }
@Test public void twoPoints() { final DoublesPair point1 = DoublesPair.of(1.25, 4.0); final SurfaceValue alpha1 = SurfaceValue.from(point1, 12345.0); final SurfaceValue beta1 = SurfaceValue.from(point1, 4321.0); final SurfaceValue rho1 = SurfaceValue.from(point1, 2345.6); final SurfaceValue nu1 = SurfaceValue.from(point1, 345.67); final DoublesPair point2 = DoublesPair.of(5.5, 9.0); final SurfaceValue alpha2 = SurfaceValue.from(point2, 2345.0); final SurfaceValue beta2 = SurfaceValue.from(point2, 5432.0); final SurfaceValue rho2 = SurfaceValue.from(point2, 345.6); final SurfaceValue nu2 = SurfaceValue.from(point2, 45.67); final PresentValueSABRSensitivityDataBundle onePoint1 = new PresentValueSABRSensitivityDataBundle(alpha1, beta1, rho1, nu1); final PresentValueSABRSensitivityDataBundle onePoint2 = new PresentValueSABRSensitivityDataBundle(alpha2, beta2, rho2, nu2); final PresentValueSABRSensitivityDataBundle twoPoints = onePoint1.plus(onePoint2); final PresentValueSABRSensitivityDataBundle node1 = SABRSensitivityNodeCalculator.calculateNodeSensitivities(onePoint1, SABR_PARAMETERS); final PresentValueSABRSensitivityDataBundle node2 = SABRSensitivityNodeCalculator.calculateNodeSensitivities(onePoint2, SABR_PARAMETERS); final PresentValueSABRSensitivityDataBundle nodeSum = SABRSensitivityNodeCalculator.calculateNodeSensitivities(twoPoints, SABR_PARAMETERS); assertEquals("SABR Node calculator", node1.plus(node2), nodeSum); }