final String forwardTenorName = forwardTenorNames.iterator().next();
final ForwardSwapCurveDefinition definition = curveDefinitionSource.getDefinition(curveName, currency.toString());
if (definition == null) {
throw new OpenGammaRuntimeException("Couldn't find a forward swap curve definition called " + curveName + " with target " + target);
}
final ForwardSwapCurveSpecification specification = curveSpecificationSource.getSpecification(curveName, currency.toString());
if (specification == null) {
throw new OpenGammaRuntimeException("Couldn't find a forward swap curve specification called " + curveName + " with target " + target);
}
final Set<ValueRequirement> requirements = new HashSet<ValueRequirement>();
final ForwardSwapCurveInstrumentProvider provider = (ForwardSwapCurveInstrumentProvider) specification.getCurveInstrumentProvider();
final Tenor forwardTenor = Tenor.of(Period.parse(forwardTenorName));
for (final Tenor tenor : definition.getTenors()) {
final ExternalId identifier = provider.getInstrument(atZDT.toLocalDate(), tenor, forwardTenor);
requirements.add(new ValueRequirement(provider.getDataFieldName(), ComputationTargetType.PRIMITIVE, identifier));
}
requirements.add(new ValueRequirement(provider.getDataFieldName(), ComputationTargetType.PRIMITIVE, provider.getSpotInstrument(forwardTenor)));
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 String forwardTenorName = desiredValue.getConstraint(PROPERTY_FORWARD_TENOR);
final Currency currencyPair = target.getValue(PrimitiveComputationTargetType.CURRENCY);
final ForwardSwapCurveDefinition definition = curveDefinitionSource.getDefinition(curveName, currencyPair.toString());
if (definition == null) {
throw new OpenGammaRuntimeException("Couldn't find a forward swap curve definition called " + curveName + " for target " + target);
}
final ForwardSwapCurveSpecification 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 ForwardSwapCurveInstrumentProvider provider = (ForwardSwapCurveInstrumentProvider) specification.getCurveInstrumentProvider();
final Tenor forwardTenor = Tenor.of(Period.parse(forwardTenorName));
final ValueRequirement spotRequirement = new ValueRequirement(provider.getDataFieldName(), ComputationTargetType.PRIMITIVE, provider.getSpotInstrument(forwardTenor));
if (inputs.getValue(spotRequirement) == null) {
throw new OpenGammaRuntimeException("Could not get value for spot; requirement was " + spotRequirement);
}