@Override
public Set<ComputedValue> execute(final FunctionExecutionContext executionContext, final FunctionInputs inputs, final ComputationTarget target,
final Set<ValueRequirement> desiredValues) throws AsynchronousExecution {
if (inputs.getAllValues().size() == 0) {
return Collections.singleton(new ComputedValue(_spec, new FXMatrix()));
}
final FXMatrix matrix = new FXMatrix();
final Iterator<Currency> iter = _currencies.iterator();
final Currency initialCurrency = iter.next();
final CurrencyPairs pairs = (CurrencyPairs) inputs.getValue(CURRENCY_PAIRS);
while (iter.hasNext()) {
final Currency otherCurrency = iter.next();
if (pairs.getCurrencyPair(initialCurrency, otherCurrency).getBase().equals(initialCurrency)) {
final double spotRate = (Double) inputs.getValue(new ValueRequirement(ValueRequirementNames.SPOT_RATE,
CurrencyPair.TYPE.specification(CurrencyPair.of(otherCurrency, initialCurrency))));
matrix.addCurrency(otherCurrency, initialCurrency, spotRate);
} else {
final double spotRate = (Double) inputs.getValue(new ValueRequirement(ValueRequirementNames.SPOT_RATE,
CurrencyPair.TYPE.specification(CurrencyPair.of(otherCurrency, initialCurrency))));
matrix.addCurrency(otherCurrency, initialCurrency, 1 / spotRate);
}
}
return Collections.singleton(new ComputedValue(_spec, matrix));
}