if (curveCalculationConfigNames == null || curveCalculationConfigNames.size() != 1) {
return null;
}
final String domesticCurveCalculationConfigName = curveCalculationConfigNames.iterator().next();
final ConfigSource configSource = OpenGammaCompilationContext.getConfigSource(context);
final ConfigDBFXForwardCurveDefinitionSource fxCurveDefinitionSource = new ConfigDBFXForwardCurveDefinitionSource(configSource);
final ConfigDBFXForwardCurveSpecificationSource fxCurveSpecificationSource = new ConfigDBFXForwardCurveSpecificationSource(configSource);
final ConfigDBCurveCalculationConfigSource curveCalculationConfigSource = new ConfigDBCurveCalculationConfigSource(configSource);
final MultiCurveCalculationConfig domesticCurveCalculationConfig = curveCalculationConfigSource.getConfig(domesticCurveCalculationConfigName);
if (domesticCurveCalculationConfig == null) {
s_logger.error("Could not get domestic curve calculation config called {}", domesticCurveCalculationConfigName);
return null;
}
if (!domesticCurveCalculationConfig.getCalculationMethod().equals(FX_IMPLIED)) {
return null;
}
final Set<String> rootFinderAbsoluteTolerance = constraints.getValues(MultiYieldCurvePropertiesAndDefaults.PROPERTY_ROOT_FINDER_ABSOLUTE_TOLERANCE);
if (rootFinderAbsoluteTolerance == null || rootFinderAbsoluteTolerance.size() != 1) {
return null;
}
final Set<String> rootFinderRelativeTolerance = constraints.getValues(MultiYieldCurvePropertiesAndDefaults.PROPERTY_ROOT_FINDER_RELATIVE_TOLERANCE);
if (rootFinderRelativeTolerance == null || rootFinderRelativeTolerance.size() != 1) {
return null;
}
final Set<String> maxIterations = constraints.getValues(MultiYieldCurvePropertiesAndDefaults.PROPERTY_ROOT_FINDER_MAX_ITERATIONS);
if (maxIterations == null || maxIterations.size() != 1) {
return null;
}
final Set<String> decomposition = constraints.getValues(MultiYieldCurvePropertiesAndDefaults.PROPERTY_DECOMPOSITION);
if (decomposition == null || decomposition.size() != 1) {
return null;
}
final Set<String> useFiniteDifference = constraints.getValues(MultiYieldCurvePropertiesAndDefaults.PROPERTY_USE_FINITE_DIFFERENCE);
if (useFiniteDifference == null || useFiniteDifference.size() != 1) {
return null;
}
final Set<String> interpolatorName = constraints.getValues(InterpolatedDataProperties.X_INTERPOLATOR_NAME);
if (interpolatorName == null || interpolatorName.size() != 1) {
return null;
}
final Set<String> leftExtrapolatorName = constraints.getValues(InterpolatedDataProperties.LEFT_X_EXTRAPOLATOR_NAME);
if (leftExtrapolatorName == null || leftExtrapolatorName.size() != 1) {
return null;
}
final Set<String> rightExtrapolatorName = constraints.getValues(InterpolatedDataProperties.RIGHT_X_EXTRAPOLATOR_NAME);
if (rightExtrapolatorName == null || rightExtrapolatorName.size() != 1) {
return null;
}
if (domesticCurveCalculationConfig.getExogenousConfigData() == null) {
s_logger.error("Need an externally-supplied curve to imply data; tried {}", domesticCurveCalculationConfigName);
return null;
}
if (domesticCurveCalculationConfig.getYieldCurveNames().length != 1) {
s_logger.error("Can only handle one curve at the moment");
return null;
}
if (!domesticCurveCalculationConfig.getTarget().equals(target.toSpecification())) {
s_logger.info("Invalid target, was {} - expected {}", target, domesticCurveCalculationConfig.getTarget());
return null;
}
final Map<String, String[]> exogenousConfigs = domesticCurveCalculationConfig.getExogenousConfigData();
if (exogenousConfigs.size() != 1) {
s_logger.error("Can only handle curves with one foreign curve config");
return null;
}
final Map.Entry<String, String[]> foreignCurveConfigNames = exogenousConfigs.entrySet().iterator().next();
final MultiCurveCalculationConfig foreignConfig = curveCalculationConfigSource.getConfig(foreignCurveConfigNames.getKey());
if (foreignConfig == null) {
s_logger.error("Foreign config was null; tried {}", foreignCurveConfigNames.getKey());
return null;
}
final ComputationTargetSpecification foreignCurrencySpec = foreignConfig.getTarget();
if (!foreignCurrencySpec.getType().isTargetType(ComputationTargetType.CURRENCY)) {
s_logger.error("Can only handle curves with currencies as ids at the moment");
return null;
}
final String domesticCurveName = domesticCurveCalculationConfig.getYieldCurveNames()[0];
final Currency domesticCurrency = target.getValue(ComputationTargetType.CURRENCY);
final Set<ValueRequirement> requirements = new HashSet<>();
final Currency foreignCurrency = ComputationTargetType.CURRENCY.resolve(foreignCurrencySpec.getUniqueId());
final UnorderedCurrencyPair currencyPair = UnorderedCurrencyPair.of(domesticCurrency, foreignCurrency);
final FXForwardCurveDefinition definition = fxCurveDefinitionSource.getDefinition(domesticCurveName, currencyPair.toString());
if (definition == null) {
s_logger.error("Couldn't find FX forward curve definition called " + domesticCurveName + " with target " + currencyPair);
return null;
}
final FXForwardCurveSpecification fxForwardCurveSpec = fxCurveSpecificationSource.getSpecification(domesticCurveName, currencyPair.toString());