DeltaGammaCovarianceMatrixMeanCalculator extends Function1D<Map<Integer, ParametricVaRDataBundle>, Double> { @Override public Double evaluate(final Map<Integer, ParametricVaRDataBundle> data) { Validate.notNull(data, "data"); final ParametricVaRDataBundle firstOrderData = data.get(1); Validate.notNull(firstOrderData, "first order data"); final ParametricVaRDataBundle secondOrderData = data.get(2); if (secondOrderData == null) { return 0.; } final Matrix<?> gamma = secondOrderData.getSensitivities(); if (gamma == null || gamma.getNumberOfElements() == 0) { return 0.; } final DoubleMatrix2D covariance = firstOrderData.getCovarianceMatrix(); return 0.5 * _algebra.getTrace(_algebra.multiply(gamma, covariance)); } DeltaGammaCovarianceMatrixMeanCalculator(final MatrixAlgebra algebra); @Override Double evaluate(final Map<Integer, ParametricVaRDataBundle> data); @Override int hashCode(); @Override boolean equals(final Object obj);  }
@Test(expectedExceptions = IllegalArgumentException.class) public void testNullData() { F.evaluate((Map<Integer, ParametricVaRDataBundle>) null); }
@Test public void test() { final ParametricVaRDataBundle deltaData = new ParametricVaRDataBundle(DELTA_VECTOR, COVARIANCE_MATRIX, 1); final ParametricVaRDataBundle gammaData = new ParametricVaRDataBundle(GAMMA_MATRIX, COVARIANCE_MATRIX, 2); final Map<Integer, ParametricVaRDataBundle> m = new HashMap<>(); m.put(1, deltaData); assertEquals(F.evaluate(m), 0, 0); m.put(2, new ParametricVaRDataBundle(new DoubleMatrix2D(new double[0][0]), new DoubleMatrix2D(new double[0][0]), 2)); assertEquals(F.evaluate(m), 0, 0); m.put(2, gammaData); assertEquals(F.evaluate(m), 0.1495, 1e-4); }