@SuppressWarnings({"synthetic-access" })
@Override
public Set<ComputedValue> execute(final FunctionExecutionContext executionContext, final FunctionInputs inputs, final ComputationTarget target,
final Set<ValueRequirement> desiredValues) {
final ValueRequirement desiredValue = Iterables.getOnlyElement(desiredValues);
final String surfaceName = desiredValue.getConstraint(ValuePropertyNames.SURFACE);
final String instrumentType = desiredValue.getConstraint(InstrumentTypeProperties.PROPERTY_SURFACE_INSTRUMENT_TYPE);
final Object definitionObject = inputs.getValue(ValueRequirementNames.VOLATILITY_SURFACE_DEFINITION);
if (definitionObject == null) {
throw new OpenGammaRuntimeException("Could not get volatility surface definition");
}
final Object specificationObject = inputs.getValue(ValueRequirementNames.VOLATILITY_SURFACE_SPEC);
if (specificationObject == null) {
throw new OpenGammaRuntimeException("Could not get volatility surface specification");
}
@SuppressWarnings("unchecked")
final VolatilitySurfaceDefinition<Object, Object> definition = (VolatilitySurfaceDefinition<Object, Object>) definitionObject;
final VolatilitySurfaceSpecification specification = (VolatilitySurfaceSpecification) specificationObject;
final LocalDate valuationDate = LocalDate.now(executionContext.getValuationClock());
final SurfaceInstrumentProvider<Object, Object> provider = (SurfaceInstrumentProvider<Object, Object>) specification.getSurfaceInstrumentProvider();
final Map<Pair<Object, Object>, Double> volatilityValues = new HashMap<>();
final ObjectArrayList<Object> xList = new ObjectArrayList<>();
final ObjectArrayList<Object> yList = new ObjectArrayList<>();
for (final Object x : definition.getXs()) {
for (final Object y : definition.getYs()) {
final ExternalId identifier = provider.getInstrument(x, y, valuationDate);
final ValueRequirement requirement = new ValueRequirement(provider.getDataFieldName(), ComputationTargetType.PRIMITIVE, identifier);
final Double volatility = (Double) inputs.getValue(requirement);
if (volatility != null) {
xList.add(x);
yList.add(y);
volatilityValues.put(Pair.of(x, y), volatility);