@Override
public Set<ValueRequirement> getRequirements(final FunctionCompilationContext context, final ComputationTarget target, final ValueRequirement desiredValue) {
final Position position = target.getPosition();
final FinancialSecurity security = (FinancialSecurity) position.getSecurity();
final String currency = FinancialSecurityUtils.getCurrency(security).getCode();
final ValueProperties constraints = desiredValue.getConstraints();
final Set<String> periodNames = constraints.getValues(SAMPLING_PERIOD);
if (periodNames == null || periodNames.size() != 1) {
return null;
}
final String samplingPeriod = periodNames.iterator().next();
final Set<String> scheduleNames = constraints.getValues(SCHEDULE_CALCULATOR);
if (scheduleNames == null || scheduleNames.size() != 1) {
return null;
}
final Set<String> samplingFunctionNames = constraints.getValues(SAMPLING_FUNCTION);
if (samplingFunctionNames == null || samplingFunctionNames.size() != 1) {
return null;
}
final CreditSecurityToIdentifierVisitor identifierVisitor = new CreditSecurityToIdentifierVisitor(OpenGammaCompilationContext.getSecuritySource(context));
final String spreadCurveName = security.accept(identifierVisitor).getUniqueId().getValue();
final Set<ValueRequirement> requirements = new HashSet<>();
requirements.add(getBucketedCS01Requirement(security));
requirements.add(getCreditSpreadCurveHTSRequirement(security, getCurvePrefix() + "_" + spreadCurveName, samplingPeriod));
final Set<String> resultCurrencies = constraints.getValues(CURRENCY);
if (resultCurrencies != null && resultCurrencies.size() == 1) {
final ValueRequirement ccyConversionTSRequirement = getCurrencyConversionTSRequirement(position, currency, resultCurrencies);
if (ccyConversionTSRequirement != null) {
requirements.add(ccyConversionTSRequirement);
requirements.add(new ValueRequirement(ValueRequirementNames.CURRENCY_PAIRS, ComputationTargetSpecification.NULL));