ParameterSensitivityWeightMatrixCalculator { public DoubleMatrix2D projectCurveNodes(final MulticurveProviderDiscount curves, final LinkedHashSet<Pair<String, Integer>> order, final double[] objNodes) { ArgumentChecker.notNull(curves, "curves"); ArgumentChecker.notNull(order, "order"); ArgumentChecker.notNull(objNodes, "objNodes"); int nCurves = order.size(); ArgumentChecker.isTrue(nCurves > 0, "order should not be empty"); Iterator<Pair<String, Integer>> it = order.iterator(); DoubleMatrix2D[] resArray = new DoubleMatrix2D[nCurves]; int nRowsTotal = 0; int nColsTotal = 0; for (int i = 0; i < nCurves; ++i) { resArray[i] = projectSingleCurveNodes(curves, it.next(), objNodes); nRowsTotal += resArray[i].getNumberOfRows(); nColsTotal += resArray[i].getNumberOfColumns(); } double[][] res = new double[nRowsTotal][nColsTotal]; int offsetRow = 0; int offsetCol = 0; for (int i = 0; i < nCurves; ++i) { int nRows = resArray[i].getNumberOfRows(); int nCols = resArray[i].getNumberOfColumns(); for (int j = 0; j < nRows; ++j) { for (int k = 0; k < nCols; ++k) { res[j + offsetRow][k + offsetCol] = resArray[i].getData()[j][k]; } } offsetRow += nRows; offsetCol += nCols; } return new DoubleMatrix2D(res); }  DoubleMatrix2D projectCurveNodes(final MulticurveProviderDiscount curves, final LinkedHashSet<Pair<String, Integer>> order, final double[] objNodes); DoubleMatrix2D projectCurvesAndNodes(final MulticurveProviderDiscount curves, final LinkedHashSet<Pair<String, Integer>> order, final double[] objNodes); DoubleMatrix2D reduceCurveNodes(final MulticurveProviderDiscount curves, final LinkedHashSet<Pair<String, Integer>> order, final double[] objNodes); DoubleMatrix2D reduceCurveNodes(final YieldAndDiscountCurve[] curves, final double[] objNodes); DoubleMatrix2D reduceCurveNodes(final double[] totalNodes, final double[] objNodes);  }
@Test public void singleNodeTest() { ParameterSensitivityWeightMatrixCalculator calc = new ParameterSensitivityWeightMatrixCalculator(); Interpolator1D linearFlat = CombinedInterpolatorExtrapolatorFactory.getInterpolator(Interpolator1DFactory.LINEAR, Interpolator1DFactory.FLAT_EXTRAPOLATOR, Interpolator1DFactory.FLAT_EXTRAPOLATOR); double[] time = new double[] {5.0 }; double[] rate = new double[] {0.0140 }; String name = "USD Dsc"; YieldAndDiscountCurve usdDisc = new YieldCurve(name, new InterpolatedDoublesCurve(time, rate, linearFlat, true, name)); MulticurveProviderDiscount singleCurve = new MulticurveProviderDiscount(); singleCurve.setCurve(Currency.USD, usdDisc); double[] objNodes = new double[] {5.0 }; LinkedHashSet<Pair<String, Integer>> order = new LinkedHashSet<>(); order.add(Pairs.of(name, MULTICURVES.getNumberOfParameters(name))); DoubleMatrix2D matrix = calc.projectCurveNodes(singleCurve, order, objNodes); assertEquals(1, matrix.getNumberOfElements()); assertEquals(1.0, matrix.getData()[0][0]); objNodes = new double[] {5.0, 10.0 }; matrix = calc.projectCurveNodes(singleCurve, order, objNodes); assertEquals(1, matrix.getNumberOfElements()); assertEquals(1.0, matrix.getData()[0][0]); String name1 = MULTICURVES.getName(Currency.USD); String name2 = MULTICURVES.getName(USDLIBOR3M); LinkedHashSet<Pair<String, Integer>> orderMulti = new LinkedHashSet<>(); orderMulti.add(Pairs.of(name1, MULTICURVES.getNumberOfParameters(name1))); orderMulti.add(Pairs.of(name2, MULTICURVES.getNumberOfParameters(name2))); YieldCurve curve1 = (YieldCurve) MULTICURVES.getCurve(name1); YieldCurve curve2 = (YieldCurve) MULTICURVES.getCurve(name2); Double[] nodes1 = curve1.getCurve().getXData(); Double[] nodes2 = curve2.getCurve().getXData(); objNodes = new double[] {nodes1[4] }; matrix = calc.projectCurveNodes(MULTICURVES, orderMulti, objNodes); assertEquals(nodes1.length + nodes2.length, matrix.getNumberOfColumns()); assertEquals(2, matrix.getNumberOfRows()); for (int i = 0; i < nodes1.length; ++i) { assertEquals(1.0, matrix.getData()[0][i]); assertEquals(0.0, matrix.getData()[1][i]); } for (int i = nodes1.length; i < nodes1.length + nodes2.length; ++i) { assertEquals(0.0, matrix.getData()[0][i]); assertEquals(1.0, matrix.getData()[1][i]); } }