if (curveCalculationConfigNames == null || curveCalculationConfigNames.size() != 1) {
return null;
}
final String domesticCurveCalculationConfigName = curveCalculationConfigNames.iterator().next();
final ConfigSource configSource = OpenGammaCompilationContext.getConfigSource(context);
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.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;
}
if (!domesticCurveCalculationConfig.getCalculationMethod().equals(FX_IMPLIED)) {
return null;
}
ValueProperties.Builder seriesConstraints = null;
Set<String> values = desiredValue.getConstraints().getValues(DATA_FIELD_PROPERTY);
if ((values == null) || values.isEmpty()) {
seriesConstraints = desiredValue.getConstraints().copy().with(DATA_FIELD_PROPERTY, MarketDataRequirementNames.MARKET_VALUE);
} else if (values.size() > 1) {
seriesConstraints = desiredValue.getConstraints().copy().withoutAny(DATA_FIELD_PROPERTY)
.with(DATA_FIELD_PROPERTY, values.iterator().next());
}
values = desiredValue.getConstraints().getValues(RESOLUTION_KEY_PROPERTY);
if ((values == null) || values.isEmpty()) {
if (seriesConstraints == null) {
seriesConstraints = desiredValue.getConstraints().copy();
}
seriesConstraints.with(RESOLUTION_KEY_PROPERTY, "");
} else if (values.size() > 1) {
if (seriesConstraints == null) {
seriesConstraints = desiredValue.getConstraints().copy();
}
seriesConstraints.withoutAny(RESOLUTION_KEY_PROPERTY).with(RESOLUTION_KEY_PROPERTY, values.iterator().next());
}
values = desiredValue.getConstraints().getValues(START_DATE_PROPERTY);
if ((values == null) || values.isEmpty()) {
if (seriesConstraints == null) {
seriesConstraints = desiredValue.getConstraints().copy();
}
seriesConstraints.with(START_DATE_PROPERTY, "Null");
}
values = desiredValue.getConstraints().getValues(INCLUDE_START_PROPERTY);
if ((values == null) || (values.size() != 1)) {
if (seriesConstraints == null) {
seriesConstraints = desiredValue.getConstraints().copy();
}
seriesConstraints.with(INCLUDE_START_PROPERTY, YES_VALUE);
}
values = desiredValue.getConstraints().getValues(END_DATE_PROPERTY);
if ((values == null) || values.isEmpty()) {
if (seriesConstraints == null) {
seriesConstraints = desiredValue.getConstraints().copy();
}
seriesConstraints.with(END_DATE_PROPERTY, "Now");
}
values = desiredValue.getConstraints().getValues(INCLUDE_END_PROPERTY);
if ((values == null) || (values.size() != 1)) {
if (seriesConstraints == null) {
seriesConstraints = desiredValue.getConstraints().copy();
}
seriesConstraints.with(INCLUDE_END_PROPERTY, YES_VALUE);
}
if (seriesConstraints != null) {
Set<String> propertyValue = constraints.getValues(PROPERTY_ROOT_FINDER_ABSOLUTE_TOLERANCE);
if (propertyValue == null) {
seriesConstraints.withAny(PROPERTY_ROOT_FINDER_ABSOLUTE_TOLERANCE);
} else {
seriesConstraints.with(PROPERTY_ROOT_FINDER_ABSOLUTE_TOLERANCE, propertyValue);
}
propertyValue = constraints.getValues(PROPERTY_ROOT_FINDER_RELATIVE_TOLERANCE);
if (propertyValue == null) {
seriesConstraints.withAny(PROPERTY_ROOT_FINDER_RELATIVE_TOLERANCE);
} else {
seriesConstraints.with(PROPERTY_ROOT_FINDER_RELATIVE_TOLERANCE, propertyValue);
}
propertyValue = constraints.getValues(PROPERTY_ROOT_FINDER_MAX_ITERATIONS);
if (propertyValue == null) {
seriesConstraints.withAny(PROPERTY_ROOT_FINDER_MAX_ITERATIONS);
} else {
seriesConstraints.with(PROPERTY_ROOT_FINDER_MAX_ITERATIONS, propertyValue);
}
propertyValue = constraints.getValues(PROPERTY_DECOMPOSITION);
if (propertyValue == null) {
seriesConstraints.withAny(PROPERTY_DECOMPOSITION);
} else {
seriesConstraints.with(PROPERTY_DECOMPOSITION, propertyValue);
}
propertyValue = constraints.getValues(PROPERTY_USE_FINITE_DIFFERENCE);
if (propertyValue == null) {
seriesConstraints.withAny(PROPERTY_USE_FINITE_DIFFERENCE);
} else {
seriesConstraints.with(PROPERTY_USE_FINITE_DIFFERENCE, propertyValue);
}
propertyValue = constraints.getValues(X_INTERPOLATOR_NAME);
if (propertyValue == null) {
seriesConstraints.withAny(X_INTERPOLATOR_NAME);
} else {
seriesConstraints.with(X_INTERPOLATOR_NAME, propertyValue);
}
propertyValue = constraints.getValues(LEFT_X_EXTRAPOLATOR_NAME);
if (propertyValue == null) {
seriesConstraints.withAny(LEFT_X_EXTRAPOLATOR_NAME);
} else {
seriesConstraints.with(LEFT_X_EXTRAPOLATOR_NAME, propertyValue);
}
propertyValue = constraints.getValues(RIGHT_X_EXTRAPOLATOR_NAME);
if (propertyValue == null) {
seriesConstraints.withAny(RIGHT_X_EXTRAPOLATOR_NAME);
} else {
seriesConstraints.with(RIGHT_X_EXTRAPOLATOR_NAME, propertyValue);
}
return Collections.singleton(new ValueRequirement(YIELD_CURVE_SERIES, target.toSpecification(), seriesConstraints.get()));
}
final Set<String> rootFinderAbsoluteTolerance = constraints.getValues(PROPERTY_ROOT_FINDER_ABSOLUTE_TOLERANCE);
if (rootFinderAbsoluteTolerance == null || rootFinderAbsoluteTolerance.size() != 1) {
return null;
}
final Set<String> rootFinderRelativeTolerance = constraints.getValues(PROPERTY_ROOT_FINDER_RELATIVE_TOLERANCE);
if (rootFinderRelativeTolerance == null || rootFinderRelativeTolerance.size() != 1) {
return null;
}
final Set<String> maxIterations = constraints.getValues(PROPERTY_ROOT_FINDER_MAX_ITERATIONS);
if (maxIterations == null || maxIterations.size() != 1) {
return null;
}
final Set<String> decomposition = constraints.getValues(PROPERTY_DECOMPOSITION);
if (decomposition == null || decomposition.size() != 1) {
return null;
}
final Set<String> useFiniteDifference = constraints.getValues(PROPERTY_USE_FINITE_DIFFERENCE);
if (useFiniteDifference == null || useFiniteDifference.size() != 1) {
return null;
}
final Set<String> interpolatorName = constraints.getValues(X_INTERPOLATOR_NAME);
if (interpolatorName == null || interpolatorName.size() != 1) {
return null;
}
final Set<String> leftExtrapolatorName = constraints.getValues(LEFT_X_EXTRAPOLATOR_NAME);
if (leftExtrapolatorName == null || leftExtrapolatorName.size() != 1) {
return null;
}
final Set<String> rightExtrapolatorName = constraints.getValues(RIGHT_X_EXTRAPOLATOR_NAME);
if (rightExtrapolatorName == null || rightExtrapolatorName.size() != 1) {
return null;
}
final ConfigDBFXForwardCurveDefinitionSource fxCurveDefinitionSource = new ConfigDBFXForwardCurveDefinitionSource(configSource);
final ConfigDBFXForwardCurveSpecificationSource fxCurveSpecificationSource = new ConfigDBFXForwardCurveSpecificationSource(configSource);
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();