ConfigDocumentWatchSetProvider.reinitOnChanges(context, this, YieldCurveDefinition.class);
}
@Override
public CompiledFunctionDefinition compile(final FunctionCompilationContext context, final Instant atInstant) {
final ConfigSource configurationSource = OpenGammaCompilationContext.getConfigSource(context);
final MultiCurveCalculationConfig impliedConfiguration = configurationSource.getLatestByName(MultiCurveCalculationConfig.class, _curveCalculationConfig);
if (impliedConfiguration == null) {
throw new OpenGammaRuntimeException("Multi-curve calculation called " + _curveCalculationConfig + " was null");
}
ComputationTarget target = context.getComputationTargetResolver().resolve(impliedConfiguration.getTarget());
if (!(target.getValue() instanceof Currency)) {
throw new OpenGammaRuntimeException("Target of curve calculation configuration was not a currency");
}
final Currency impliedCurrency = (Currency) target.getValue();
if (!IMPLIED_DEPOSIT.equals(impliedConfiguration.getCalculationMethod())) {
throw new OpenGammaRuntimeException("Curve calculation method was not " + IMPLIED_DEPOSIT + " for configuration called " + _curveCalculationConfig);
}
final String[] impliedCurveNames = impliedConfiguration.getYieldCurveNames();
if (impliedCurveNames.length != 1) {
throw new OpenGammaRuntimeException("Can only handle configurations with a single implied curve");
}
final LinkedHashMap<String, String[]> originalConfigurationName = impliedConfiguration.getExogenousConfigData();
if (originalConfigurationName == null || originalConfigurationName.size() != 1) {
throw new OpenGammaRuntimeException("Need a configuration with one exogenous configuration");
}
final Map.Entry<String, String[]> entry = Iterables.getOnlyElement(originalConfigurationName.entrySet());
final String[] originalCurveNames = entry.getValue();
if (originalCurveNames.length != 1) {
s_logger.warn("Found more than one exogenous configuration name; using only the first");
}
final MultiCurveCalculationConfig originalConfiguration = configurationSource.getLatestByName(MultiCurveCalculationConfig.class, entry.getKey());
if (originalConfiguration == null) {
throw new OpenGammaRuntimeException("Multi-curve calculation called " + entry.getKey() + " was null");
}
target = context.getComputationTargetResolver().resolve(originalConfiguration.getTarget());
if (!(target.getValue() instanceof Currency)) {
throw new OpenGammaRuntimeException("Target of curve calculation configuration was not a currency");
}
final Currency originalCurrency = (Currency) target.getValue();
if (!originalCurrency.equals(impliedCurrency)) {
throw new OpenGammaRuntimeException("Currency targets for configurations " + _curveCalculationConfig + " and " + entry.getKey() + " did not match");
}
final YieldCurveDefinition impliedDefinition = configurationSource.getLatestByName(YieldCurveDefinition.class, impliedCurveNames[0] + "_" + impliedCurrency.getCode());
if (impliedDefinition == null) {
throw new OpenGammaRuntimeException("Could not get implied definition called " + impliedCurveNames[0] + "_" + impliedCurrency.getCode());
}
final Set<FixedIncomeStrip> strips = impliedDefinition.getStrips();
for (final FixedIncomeStrip strip : strips) {