public Set<ComputedValue> execute(final FunctionExecutionContext executionContext, final FunctionInputs inputs, final ComputationTarget target,
final Set<ValueRequirement> desiredValues) {
final ValueRequirement desiredValue = desiredValues.iterator().next();
final String surfaceName = desiredValue.getConstraint(ValuePropertyNames.SURFACE);
final String instrumentType = desiredValue.getConstraint(InstrumentTypeProperties.PROPERTY_SURFACE_INSTRUMENT_TYPE);
VolatilitySurfaceSpecification specification = null;
if (instrumentType.equals(InstrumentTypeProperties.FOREX)) {
final UnorderedCurrencyPair pair = UnorderedCurrencyPair.of(target.getUniqueId());
String name = pair.getFirstCurrency().getCode() + pair.getSecondCurrency().getCode();
String fullSpecificationName = surfaceName + "_" + name;
specification = source.getSpecification(fullSpecificationName, instrumentType);
if (specification == null) {
name = pair.getSecondCurrency().getCode() + pair.getFirstCurrency().getCode();
fullSpecificationName = surfaceName + "_" + name;
specification = source.getSpecification(fullSpecificationName, instrumentType);
if (specification == null) {
throw new OpenGammaRuntimeException("Could not get volatility surface specification named " + fullSpecificationName);
}
}
} else if (instrumentType.equals(InstrumentTypeProperties.EQUITY_OPTION) || instrumentType.equals(InstrumentTypeProperties.EQUITY_FUTURE_OPTION)) {
final String fullSpecificationName = surfaceName + "_" + EquitySecurityUtils.getTrimmedTarget(UniqueId.parse(target.getValue().toString()));
specification = source.getSpecification(fullSpecificationName, instrumentType);
if (specification == null) {
throw new OpenGammaRuntimeException("Could not get volatility surface specification named " + fullSpecificationName + " for instrument type " + instrumentType);
}
} else {
final String fullSpecificationName = surfaceName + "_" + target.getUniqueId().getValue();
specification = source.getSpecification(fullSpecificationName, instrumentType);
if (specification == null) {
throw new OpenGammaRuntimeException("Could not get volatility surface specification named " + fullSpecificationName + " for instrument type " + instrumentType);
}
}
@SuppressWarnings("synthetic-access")
final ValueSpecification spec = new ValueSpecification(ValueRequirementNames.VOLATILITY_SURFACE_SPEC, target.toSpecification(),
createValueProperties()
.with(ValuePropertyNames.SURFACE, surfaceName)
.with(InstrumentTypeProperties.PROPERTY_SURFACE_INSTRUMENT_TYPE, instrumentType)
.with(SurfaceAndCubePropertyNames.PROPERTY_SURFACE_QUOTE_TYPE, specification.getSurfaceQuoteType())
.with(SurfaceAndCubePropertyNames.PROPERTY_SURFACE_UNITS, specification.getQuoteUnits()).get());
return Collections.singleton(new ComputedValue(spec, specification));
}
@Override
public ComputationTargetType getTargetType() {