final FinancialSecurity security = (FinancialSecurity) target.getSecurity();
final Currency payCurrency = getPayCurrency(security);
final Currency receiveCurrency = getReceiveCurrency(security);
final ComputedValue input = inputs.getComputedValue(ValueRequirementNames.FX_PRESENT_VALUE);
final ValueSpecification inputSpec = input.getSpecification();
final CurrencyLabelledMatrix1D fxPresentValue = (CurrencyLabelledMatrix1D) input.getValue();
if (fxPresentValue.size() != 2) {
throw new OpenGammaRuntimeException("Expected " + ValueRequirementNames.FX_PRESENT_VALUE + " input to contain 2 currency values, but found " + fxPresentValue.size());
}
int payIndex = -1;
int receiveIndex = -1;
for (int i = 0; i < 2; i++) {
final Currency currency = fxPresentValue.getKeys()[i];
if (payCurrency.equals(currency)) {
payIndex = i;
} else if (receiveCurrency.equals(currency)) {
receiveIndex = i;
} else {
throw new OpenGammaRuntimeException(ValueRequirementNames.FX_PRESENT_VALUE + " contains unexpected currency " + currency + ". Expected " + payCurrency + " or " + receiveCurrency + ".");
}
}
final double payValue = fxPresentValue.getValues()[payIndex];
final double receiveValue = fxPresentValue.getValues()[receiveIndex];
final double spot = (Double) inputs.getValue(ValueRequirementNames.SPOT_RATE);
final double pv = payValue + spot * receiveValue;
return ImmutableSet.of(new ComputedValue(getResultSpec(target, inputSpec.getProperties().copy()), pv));
}