final SnapshotDataBundle snapshot = (SnapshotDataBundle) inputs.getValue(ValueRequirementNames.CURVE_MARKET_DATA);
final LocalDate spotDate = (!desiredValue.getConstraints().getValues(ISDAFunctionConstants.ISDA_CURVE_DATE).isEmpty())
? LocalDate.parse(desiredValue.getConstraint(ISDAFunctionConstants.ISDA_CURVE_DATE))
: now.toLocalDate();
DepositConvention cashConvention = null;
VanillaIborLegConvention floatLegConvention = null;
SwapFixedLegConvention fixLegConvention = null;
IborIndexConvention liborConvention = null;
final int nNodes = specification.getNodes().size();
final double[] marketDataForCurve = new double[nNodes];
final ISDAInstrumentTypes[] instruments = new ISDAInstrumentTypes[nNodes];
final Period[] tenors = new Period[nNodes];
int k = 0;
for (final CurveNodeWithIdentifier node : specification.getNodes()) {
final Double marketData = snapshot.getDataPoint(node.getIdentifier());
if (marketData == null) {
throw new OpenGammaRuntimeException("Could not get market data for " + node.getIdentifier());
}
marketDataForCurve[k] = marketData;
tenors[k] = node.getCurveNode().getResolvedMaturity().getPeriod();
if (node.getCurveNode() instanceof CashNode) {
instruments[k] = ISDAInstrumentTypes.MoneyMarket;
final ExternalId cashConventionId = ((CashNode) node.getCurveNode()).getConvention();
if (cashConvention == null) {
cashConvention = conventionSource.getConvention(DepositConvention.class, cashConventionId);
} else if (!cashConvention.getExternalIdBundle().contains(cashConventionId)) {
throw new OpenGammaRuntimeException("Got 2 types of cash convention: " + cashConvention.getExternalIdBundle() + " " + cashConventionId);
}
} else if (node.getCurveNode() instanceof SwapNode) {
instruments[k] = ISDAInstrumentTypes.Swap;
final ExternalId payConventionId = ((SwapNode) node.getCurveNode()).getPayLegConvention();
final Convention payConvention = conventionSource.getConvention(payConventionId);
if (payConvention == null) {
throw new OpenGammaRuntimeException("Convention '" + payConventionId + "' not found");
}
final ExternalId receiveConventionId = ((SwapNode) node.getCurveNode()).getReceiveLegConvention();
final Convention receiveConvention = conventionSource.getConvention(receiveConventionId);
if (receiveConvention == null) {
throw new OpenGammaRuntimeException("Convention '" + receiveConventionId + "' not found");
}
if (payConvention instanceof VanillaIborLegConvention) { // float leg
if (floatLegConvention == null) {
floatLegConvention = (VanillaIborLegConvention) payConvention;
} else if (!floatLegConvention.getExternalIdBundle().contains(payConventionId)) {
throw new OpenGammaRuntimeException("Got 2 types of float leg convention: " + payConvention.getExternalIdBundle() + " " + payConventionId);
}
} else if (payConvention instanceof SwapFixedLegConvention) {
if (fixLegConvention == null) {
fixLegConvention = (SwapFixedLegConvention) payConvention;
} else if (!fixLegConvention.getExternalIdBundle().contains(payConventionId)) {
throw new OpenGammaRuntimeException("Got 2 types of fixed leg convention: " + payConvention.getExternalIdBundle() + " " + payConventionId);
}
} else {
throw new OpenGammaRuntimeException("Unexpected swap convention type: " + payConvention);
}
if (receiveConvention instanceof VanillaIborLegConvention) { // float leg
if (floatLegConvention == null) {
floatLegConvention = (VanillaIborLegConvention) receiveConvention;
} else if (!floatLegConvention.getExternalIdBundle().contains(receiveConventionId)) {
throw new OpenGammaRuntimeException("Got 2 types of float leg convention: " + receiveConvention.getExternalIdBundle() + " " + receiveConventionId);
}
} else if (receiveConvention instanceof SwapFixedLegConvention) {
if (fixLegConvention == null) {
fixLegConvention = (SwapFixedLegConvention) receiveConvention;
} else if (!fixLegConvention.getExternalIdBundle().contains(receiveConventionId)) {
throw new OpenGammaRuntimeException("Got 2 types of fixed leg convention: " + receiveConvention.getExternalIdBundle() + " " + receiveConventionId);
}
} else {
throw new OpenGammaRuntimeException("Unexpected swap convention type: " + receiveConvention);
}
} else {
throw new OpenGammaRuntimeException("Can't handle node type " + node.getCurveNode().getClass().getSimpleName() + " at node " + node);
}
k++;
}
ArgumentChecker.notNull(cashConvention, "Cash convention");
ArgumentChecker.notNull(floatLegConvention, "Floating leg convention");
ArgumentChecker.notNull(fixLegConvention, "Fixed leg convention");
liborConvention = conventionSource.getConvention(IborIndexConvention.class, floatLegConvention.getIborIndexConvention());
ArgumentChecker.notNull(liborConvention, floatLegConvention.getIborIndexConvention().toString());
final ISDACompliantYieldCurve yieldCurve = ISDACompliantYieldCurveBuild.build(spotDate, spotDate, instruments, tenors, marketDataForCurve, cashConvention.getDayCount(),
fixLegConvention.getDayCount(), fixLegConvention.getPaymentTenor().getPeriod(), ACT_365, liborConvention.getBusinessDayConvention());
final ValueProperties properties = desiredValue.getConstraints().copy()
.with(ISDAFunctionConstants.ISDA_CURVE_DATE, spotDate.toString())
.get();