@Override
public FinancialSecurity visitSwapNode(final SwapNode swapNode) {
final Convention payLegConvention = _conventionSource.getConvention(swapNode.getPayLegConvention());
if (payLegConvention == null) {
throw new OpenGammaRuntimeException("Convention with id " + swapNode.getPayLegConvention() + " was null");
}
final Convention receiveLegConvention = _conventionSource.getConvention(swapNode.getReceiveLegConvention());
if (receiveLegConvention == null) {
throw new OpenGammaRuntimeException("Convention with id " + swapNode.getPayLegConvention() + " was null");
}
final Pair<? extends InterestRateLeg, Triple<ZonedDateTime, ZonedDateTime, ZonedDateTime>> payLeg;
final Pair<? extends InterestRateLeg, Triple<ZonedDateTime, ZonedDateTime, ZonedDateTime>> receiveLeg;
final boolean isFloatFloat = ((payLegConvention instanceof VanillaIborLegConvention) || (payLegConvention instanceof OISLegConvention))
&& ((receiveLegConvention instanceof VanillaIborLegConvention) || (receiveLegConvention instanceof OISLegConvention));
if (payLegConvention instanceof SwapFixedLegConvention) {
payLeg = getFixedLeg((SwapFixedLegConvention) payLegConvention, swapNode, true);
} else if (payLegConvention instanceof VanillaIborLegConvention) {
payLeg = getIborLeg(_identifier, (VanillaIborLegConvention) payLegConvention, swapNode, true, false);
} else if (payLegConvention instanceof OISLegConvention) {
payLeg = getOISLeg(_identifier, (OISLegConvention) payLegConvention, swapNode, true, false);
} else {
throw new OpenGammaRuntimeException("Cannot handle convention type " + payLegConvention.getClass());
}
if (receiveLegConvention instanceof SwapFixedLegConvention) {
receiveLeg = getFixedLeg((SwapFixedLegConvention) receiveLegConvention, swapNode, false);
} else if (receiveLegConvention instanceof VanillaIborLegConvention) {
receiveLeg = getIborLeg(_identifier,
(VanillaIborLegConvention) receiveLegConvention,
swapNode,
false,
isFloatFloat);
} else if (receiveLegConvention instanceof OISLegConvention) {
receiveLeg = getOISLeg(_identifier, (OISLegConvention) receiveLegConvention, swapNode, false, isFloatFloat);
} else {
throw new OpenGammaRuntimeException("Cannot handle convention type " + receiveLegConvention.getClass());
}
if (!payLeg.getSecond().getFirst().equals(receiveLeg.getSecond().getFirst())) {
throw new OpenGammaRuntimeException(
"Both, pay and receive legs should resolve equal start dates, but instead there were: payleg(" + payLeg.getSecond().getFirst() + "), receiveLeg(" + receiveLeg.getSecond().getFirst() + ")");
}
if (!payLeg.getSecond().getSecond().equals(receiveLeg.getSecond().getSecond())) {
throw new OpenGammaRuntimeException(
"Both, pay and receive legs should resolve equal effective dates, but instead there were: payleg(" + payLeg.getSecond().getSecond() + "), " +
"receiveLeg(" + receiveLeg.getSecond().getSecond() + ")");
}
if (!payLeg.getSecond().getThird().equals(receiveLeg.getSecond().getThird())) {
throw new OpenGammaRuntimeException(
"Both, pay and receive legs should resolve equal maturity dates, but instead there were: payleg(" + payLeg.getSecond().getThird() + "), " +
"receiveLeg(" + receiveLeg.getSecond().getThird() + ")");
}
return new SwapSecurity(payLeg.getSecond().getFirst(),
payLeg.getSecond().getSecond(),