// FunctionInvoker
@Override
public Set<ComputedValue> execute(final FunctionExecutionContext context, final FunctionInputs inputs, final ComputationTarget target, final Set<ValueRequirement> desiredValues) {
final ValueRequirement desiredValue = desiredValues.iterator().next();
final DoubleLabelledMatrix2D input = (DoubleLabelledMatrix2D) inputs.getValue(ValueRequirementNames.COVARIANCE_MATRIX);
final DoubleLabelledMatrix2D output = new DoubleLabelledMatrix2D(input.getXKeys(), input.getXLabels(), input.getYKeys(), input.getYLabels(), input.getValues());
// TODO: This is a really dumb way to do this. There should be something in OG-Analytics or OG-Maths that will do this faster. This is a crude mechanism to
// transform the covariance matrix to something that is more easily displayed
final double[][] values = output.getValues();
final double[] stddev = new double[values.length];
for (int i = 0; i < values.length; i++) {
stddev[i] = Math.sqrt(values[i][i]);
}
for (int i = 0; i < values.length; i++) {
final double[] v = values[i];
final double a = stddev[i];
for (int j = 0; j < v.length; j++) {
v[j] /= a * stddev[j];
}
}
return Collections.singleton(new ComputedValue(new ValueSpecification(ValueRequirementNames.CORRELATION_MATRIX, target.toSpecification(), desiredValue.getConstraints()), output));
}