class 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);
  }

  public  DeltaGammaCovarianceMatrixStandardDeviationCalculator(final MatrixAlgebra algebra);

}