@Override
public Set<ComputedValue> execute(final FunctionExecutionContext executionContext, final FunctionInputs inputs, final ComputationTarget target,
final Set<ValueRequirement> desiredValues) throws AsynchronousExecution {
final Position position = target.getPosition();
final Clock snapshotClock = executionContext.getValuationClock();
final LocalDate now = ZonedDateTime.now(snapshotClock).toLocalDate();
final String currency = FinancialSecurityUtils.getCurrency(position.getSecurity()).getCode();
final ValueRequirement desiredValue = Iterables.getOnlyElement(desiredValues);
final ValueProperties constraints = desiredValue.getConstraints();
final String desiredCurrency;
final Set<String> desiredCurrencies = constraints.getValues(ValuePropertyNames.CURRENCY);
if (desiredCurrencies != null && !desiredCurrencies.isEmpty()) {
desiredCurrency = Iterables.getOnlyElement(desiredCurrencies);
} else {
desiredCurrency = currency;
}
final Period samplingPeriod = getSamplingPeriod(desiredValue.getConstraint(ValuePropertyNames.SAMPLING_PERIOD));
final LocalDate startDate = now.minus(samplingPeriod);
final Schedule scheduleCalculator = getScheduleCalculator(desiredValue.getConstraint(ValuePropertyNames.SCHEDULE_CALCULATOR));
final TimeSeriesSamplingFunction samplingFunction = getSamplingFunction(desiredValue.getConstraint(ValuePropertyNames.SAMPLING_FUNCTION));
final LocalDate[] schedule = HOLIDAY_REMOVER.getStrippedSchedule(scheduleCalculator.getSchedule(startDate, now, true, false), WEEKEND_CALENDAR);
final ConfigSource configSource = OpenGammaExecutionContext.getConfigSource(executionContext);
final CreditSecurityToIdentifierVisitor identifierVisitor = new CreditSecurityToIdentifierVisitor(OpenGammaExecutionContext.getSecuritySource(executionContext));
final FinancialSecurity security = (FinancialSecurity) target.getPosition().getSecurity();
final String spreadCurveName = security.accept(identifierVisitor).getUniqueId().getValue();
//TODO
final String curveName = getCurvePrefix() + "_" + spreadCurveName;
final CurveSpecification curveSpecification = CurveUtils.getCurveSpecification(snapshotClock.instant(), configSource, now, curveName);
DoubleTimeSeries<?> fxSeries = null;
boolean isInverse = true;
if (!desiredCurrency.equals(currency)) {
final Object fxSeriesObject = inputs.getValue(ValueRequirementNames.HISTORICAL_FX_TIME_SERIES);
if (fxSeriesObject == null) {