@Override
public Set<ComputedValue> execute(final FunctionExecutionContext executionContext, final FunctionInputs inputs, final ComputationTarget target,
final Set<ValueRequirement> desiredValues) throws AsynchronousExecution {
final ZonedDateTime now = ZonedDateTime.now(executionContext.getValuationClock());
final ValueRequirement desiredValue = desiredValues.iterator().next();
final HistoricalTimeSeriesSource timeSeriesSource = OpenGammaExecutionContext.getHistoricalTimeSeriesSource(executionContext);
final ConfigSource configSource = OpenGammaExecutionContext.getConfigSource(executionContext);
final String idName = desiredValue.getConstraint(ValuePropertyNames.CURVE);
final String curveName = idName;
final CurveSpecification curveSpecification = CurveUtils.getCurveSpecification(now.toInstant(), configSource, now.toLocalDate(), curveName);
final String dataField = desiredValue.getConstraint(HistoricalTimeSeriesFunctionUtils.DATA_FIELD_PROPERTY);
final String resolutionKey;
final Set<String> resolutionKeyConstraint = desiredValue.getConstraints().getValues(HistoricalTimeSeriesFunctionUtils.RESOLUTION_KEY_PROPERTY);
if (resolutionKeyConstraint == null || resolutionKeyConstraint.size() != 1) {
resolutionKey = "Null";
} else {
resolutionKey = Iterables.getOnlyElement(resolutionKeyConstraint);
}
final LocalDate startDate = DateConstraint.evaluate(executionContext, desiredValue.getConstraint(HistoricalTimeSeriesFunctionUtils.START_DATE_PROPERTY));
final boolean includeStart = HistoricalTimeSeriesFunctionUtils.parseBoolean(desiredValue.getConstraint(HistoricalTimeSeriesFunctionUtils.INCLUDE_START_PROPERTY));
final Set<String> endDateConstraint = desiredValue.getConstraints().getValues(HistoricalTimeSeriesFunctionUtils.END_DATE_PROPERTY);
final String endDateString;
if (endDateConstraint == null || endDateConstraint.size() != 1) {
endDateString = "Now";
} else {
endDateString = Iterables.getOnlyElement(endDateConstraint);
}
final LocalDate endDate = DateConstraint.evaluate(executionContext, endDateString);
final boolean includeEnd = HistoricalTimeSeriesFunctionUtils.parseBoolean(desiredValue.getConstraint(HistoricalTimeSeriesFunctionUtils.INCLUDE_END_PROPERTY));
final HistoricalTimeSeriesBundle bundle = new HistoricalTimeSeriesBundle();
final Set<CurveNodeWithIdentifier> nodes = curveSpecification.getNodes();
for (final CurveNodeWithIdentifier node : nodes) {
final ExternalIdBundle identifier = ExternalIdBundle.of(node.getIdentifier());
final HistoricalTimeSeries timeSeries = timeSeriesSource.getHistoricalTimeSeries(dataField, identifier, resolutionKey, startDate, includeStart, endDate, includeEnd);
if (timeSeries != null) {
bundle.add(dataField, identifier, timeSeries);
} else {
s_logger.warn("Could not get time series for {}", identifier);
}