final CurveSpecification curve = (CurveSpecification) inputs.getAllValues().iterator().next().getValue();
final HistoricalTimeSeriesBundle bundle = new HistoricalTimeSeriesBundle();
for (final CurveNodeWithIdentifier node : curve.getNodes()) {
ExternalIdBundle id = ExternalIdBundle.of(node.getIdentifier());
String dataField = node.getDataField();
HistoricalTimeSeries timeSeries = timeSeriesSource.getHistoricalTimeSeries(dataField, id, resolutionKey, startDate, includeStart, endDate, includeEnd);
if (timeSeries != null) {
if (timeSeries.getTimeSeries().isEmpty()) {
s_logger.info("Time series for {} is empty", id);
} else {
bundle.add(dataField, id, timeSeries);
}
} else {
s_logger.info("Couldn't get time series for {}", id);
}
if (node instanceof PointsCurveNodeWithIdentifier) {
final PointsCurveNodeWithIdentifier pointsNode = (PointsCurveNodeWithIdentifier) node;
id = ExternalIdBundle.of(pointsNode.getUnderlyingIdentifier());
dataField = pointsNode.getUnderlyingDataField();
timeSeries = timeSeriesSource.getHistoricalTimeSeries(dataField, id, resolutionKey, startDate, includeStart, endDate, includeEnd);
if (timeSeries != null) {
if (timeSeries.getTimeSeries().isEmpty()) {
s_logger.info("Time series for {} is empty", id);
} else {
bundle.add(dataField, id, timeSeries);
}
} else {
s_logger.info("Couldn't get time series for {}", id);
}
}
if (node.getCurveNode() instanceof ZeroCouponInflationNode) {
final ZeroCouponInflationNode inflationNode = (ZeroCouponInflationNode) node.getCurveNode();
final ConventionSource conventionSource = OpenGammaExecutionContext.getConventionSource(executionContext);
Convention convention = conventionSource.getConvention(inflationNode.getInflationLegConvention());
if (convention == null) {
throw new OpenGammaRuntimeException("Convention with id " + inflationNode.getInflationLegConvention() + " was null");
}
if (!(convention instanceof InflationLegConvention)) {
throw new OpenGammaRuntimeException("Cannot handle convention type " + convention.getClass());
}
final InflationLegConvention inflationLegConvention = (InflationLegConvention) convention;
convention = conventionSource.getConvention(inflationLegConvention.getPriceIndexConvention());
if (convention == null) {
throw new OpenGammaRuntimeException("Convention with id " + inflationLegConvention.getPriceIndexConvention() + " was null");
}
if (!(convention instanceof PriceIndexConvention)) {
throw new OpenGammaRuntimeException("Cannot handle convention type " + convention.getClass());
}
final String priceIndexField = MarketDataRequirementNames.MARKET_VALUE; //TODO
final ExternalIdBundle priceIndexId = ExternalIdBundle.of(((PriceIndexConvention) convention).getPriceIndexId());
final HistoricalTimeSeries priceIndexSeries = timeSeriesSource.getHistoricalTimeSeries(priceIndexField, priceIndexId, resolutionKey, startDate, includeStart, endDate, true);
if (priceIndexSeries != null) {
if (priceIndexSeries.getTimeSeries().isEmpty()) {
s_logger.info("Time series for {} is empty", priceIndexId);
} else {
bundle.add(dataField, priceIndexId, priceIndexSeries);
}
} else {