final String definitionName = desiredValue.getConstraint(SurfaceAndCubePropertyNames.PROPERTY_CUBE_DEFINITION);
final String specificationName = desiredValue.getConstraint(SurfaceAndCubePropertyNames.PROPERTY_CUBE_SPECIFICATION);
final Currency currency = target.getValue(PrimitiveComputationTargetType.CURRENCY);
final String fullSpecificationName = specificationName + "_" + currency.getCode();
final String fullDefinitionName = definitionName + "_" + currency.getCode();
final SwaptionVolatilityCubeSpecification specification = specificationSource.getSpecification(fullSpecificationName);
if (specification == null) {
throw new OpenGammaRuntimeException("Could not get swaption volatility cube specification named " + fullSpecificationName);
}
final VolatilityCubeDefinition definition = definitionSource.getDefinition(currency, fullDefinitionName);
if (definition == null) {
throw new OpenGammaRuntimeException("Could not get swaption volatility cube definition named " + fullDefinitionName);
}
final CubeInstrumentProvider<Tenor, Tenor, Double> provider = (CubeInstrumentProvider<Tenor, Tenor, Double>) specification.getCubeInstrumentProvider();
final Map<VolatilityPoint, Double> data = new HashMap<VolatilityPoint, Double>();
final Map<VolatilityPoint, ExternalIdBundle> ids = new HashMap<VolatilityPoint, ExternalIdBundle>();
for (final Tenor x : definition.getSwapTenors()) {
for (final Tenor y : definition.getOptionExpiries()) {
for (final Double z : definition.getRelativeStrikes()) {
final ExternalId id = provider.getInstrument(x, y, z);
final ValueRequirement requirement = new ValueRequirement(provider.getDataFieldName(), ComputationTargetType.PRIMITIVE, id);
final Object volatilityObject = inputs.getValue(requirement);
if (volatilityObject != null) {
final Double volatility = (Double) volatilityObject;
final VolatilityPoint coordinate = new VolatilityPoint(x, y, z);
data.put(coordinate, volatility);
ids.put(coordinate, id.toBundle());
}
}
}
}
final VolatilityCubeData volatilityCubeData = new VolatilityCubeData();
volatilityCubeData.setDataPoints(data);
volatilityCubeData.setDataIds(ids);
final ValueProperties properties = createValueProperties()
.with(ValuePropertyNames.CUBE, cubeName)
.with(SurfaceAndCubePropertyNames.PROPERTY_CUBE_DEFINITION, definitionName)
.with(SurfaceAndCubePropertyNames.PROPERTY_CUBE_SPECIFICATION, specificationName)
.with(SurfaceAndCubePropertyNames.PROPERTY_CUBE_QUOTE_TYPE, specification.getCubeQuoteType())
.with(SurfaceAndCubePropertyNames.PROPERTY_CUBE_UNITS, specification.getQuoteUnits()).get();
return Collections.singleton(new ComputedValue(new ValueSpecification(ValueRequirementNames.VOLATILITY_CUBE_MARKET_DATA, target.toSpecification(), properties), volatilityCubeData));
}
@Override
public boolean canHandleMissingInputs() {