DeltaGammaCovarianceMatrixStandardDeviationCalculator extends Function1D<Map<Integer, ParametricVaRDataBundle>, Double> { @Override public Double evaluate(final Map<Integer, ParametricVaRDataBundle> data) { Validate.notNull(data); final ParametricVaRDataBundle firstOrderData = data.get(1); final ParametricVaRDataBundle secondOrderData = data.get(2); double deltaStd = 0; double gammaStd = 0; if (firstOrderData != null) { final DoubleMatrix1D delta = (DoubleMatrix1D) firstOrderData.getSensitivities(); final DoubleMatrix2D deltaCovariance = firstOrderData.getCovarianceMatrix(); deltaStd = _algebra.getInnerProduct(delta, _algebra.multiply(deltaCovariance, delta)); } if (secondOrderData != null) { final Matrix<?> gamma = secondOrderData.getSensitivities(); final DoubleMatrix2D gammaCovariance = secondOrderData.getCovarianceMatrix(); gammaStd = 0.5 * _algebra.getTrace(_algebra.getPower(_algebra.multiply(gamma, gammaCovariance), 2)); } return Math.sqrt(deltaStd + gammaStd); } DeltaGammaCovarianceMatrixStandardDeviationCalculator(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); Map<Integer, ParametricVaRDataBundle> m = new HashMap<>(); m.put(1, deltaData); assertEquals(F.evaluate(m), Math.sqrt(0.0376), 1e-4); m.put(2, gammaData); assertEquals(F.evaluate(m), 0.256, 1e-3); m = new HashMap<>(); m.put(2, gammaData); assertEquals(F.evaluate(m), Math.sqrt(0.065536 - 0.0376), 1e-3); }