s_logger.error("Asked for FX forward curve market data, but did not supply a single FX forward curve name. The property Curve must be set.");
return null;
}
final UnorderedCurrencyPair currencyPair = UnorderedCurrencyPair.of(target.getUniqueId());
final String curveName = curveNames.iterator().next();
final FXForwardCurveDefinition definition = curveDefinitionSource.getDefinition(curveName, currencyPair.toString());
if (definition == null) {
s_logger.error("Couldn't find FX forward curve definition called " + curveName + " with target " + target);
return null;
}
final FXForwardCurveSpecification specification = curveSpecificationSource.getSpecification(curveName, currencyPair.toString());
if (specification == null) {
s_logger.error("Couldn't find FX forward curve specification called " + curveName + " with target " + target);
return null;
}
final QuoteType quoteType = specification.getQuoteType();
if (quoteType != FXForwardCurveSpecification.QuoteType.Outright && quoteType != FXForwardCurveSpecification.QuoteType.Points) {
s_logger.error("Cannot handle quote type " + quoteType);
return null;
}
final Set<ValueRequirement> requirements = new HashSet<>();
final FXForwardCurveInstrumentProvider provider = specification.getCurveInstrumentProvider();
for (final Tenor tenor : definition.getTenors()) {
final ExternalId identifier = provider.getInstrument(atZDT.toLocalDate(), tenor);
requirements.add(new ValueRequirement(provider.getDataFieldName(), ComputationTargetType.PRIMITIVE, identifier));
}
requirements.add(new ValueRequirement(provider.getDataFieldName(), ComputationTargetType.PRIMITIVE, provider.getSpotInstrument()));
return requirements;
}
@Override
public Set<ComputedValue> execute(final FunctionExecutionContext executionContext, final FunctionInputs inputs, final ComputationTarget target,
final Set<ValueRequirement> desiredValues) {
final Clock snapshotClock = executionContext.getValuationClock();
final ZonedDateTime now = ZonedDateTime.now(snapshotClock);
final ValueRequirement desiredValue = desiredValues.iterator().next();
final String curveName = desiredValue.getConstraint(ValuePropertyNames.CURVE);
final UnorderedCurrencyPair currencyPair = UnorderedCurrencyPair.of(target.getUniqueId());
final FXForwardCurveDefinition definition = curveDefinitionSource.getDefinition(curveName, currencyPair.toString());
if (definition == null) {
throw new OpenGammaRuntimeException("Couldn't find FX forward curve definition called " + curveName + " for target " + target);
}
final FXForwardCurveSpecification specification = curveSpecificationSource.getSpecification(curveName, currencyPair.toString());
if (specification == null) {
throw new OpenGammaRuntimeException("Couldn't find FX forward curve specification called " + curveName + " for target " + target);
}
final FXForwardCurveInstrumentProvider provider = specification.getCurveInstrumentProvider();
final ValueRequirement spotRequirement = new ValueRequirement(provider.getDataFieldName(), ComputationTargetType.PRIMITIVE, provider.getSpotInstrument());
if (inputs.getValue(spotRequirement) == null) {
throw new OpenGammaRuntimeException("Could not get value for spot; requirement was " + spotRequirement);
}
final Double spot = (Double) inputs.getValue(spotRequirement);
final Map<ExternalId, Double> data = new HashMap<>();
final boolean isRegular = specification.isMarketQuoteConvention();
for (final Tenor tenor : definition.getTenors()) {
final ExternalId identifier = provider.getInstrument(now.toLocalDate(), tenor);
final ValueRequirement requirement = new ValueRequirement(provider.getDataFieldName(), ComputationTargetType.PRIMITIVE, identifier);
if (inputs.getValue(requirement) != null) {
final Double value = (Double) inputs.getValue(requirement);
switch (specification.getQuoteType()) {