throw new OpenGammaRuntimeException("Could not find ibor leg for " + underlyingSecurity);
}
final IborIndex iborIndex = iborLeg.getIborIndex();
final Calendar calendar = iborLeg.getIborCalendar();
final DayCount fixedLegDayCount = fixedLeg.getDayCount();
final Frequency frequency = fixedLeg.getFrequency();
final Period fixedLegPeriod;
if (frequency instanceof PeriodFrequency) {
fixedLegPeriod = ((PeriodFrequency) frequency).getPeriod();
} else if (frequency instanceof SimpleFrequency) {
fixedLegPeriod = ((SimpleFrequency) frequency).toPeriodFrequency().getPeriod();
} else {
throw new OpenGammaRuntimeException("Can only handle PeriodFrequency or SimpleFrequency");
}
return new GeneratorSwapFixedIbor("Swap Generator", fixedLegPeriod, fixedLegDayCount, iborIndex, calendar);
}
case OIS: {
IndexON onIndex;
Calendar calendar;
if (swap.getFirstLeg() instanceof AnnuityCouponONDefinition) {
final AnnuityCouponONDefinition annuityCouponONDefinition = (AnnuityCouponONDefinition) swap.getFirstLeg();
onIndex = annuityCouponONDefinition.getOvernightIndex();
calendar = annuityCouponONDefinition.getCalendar();
} else if (swap.getSecondLeg() instanceof AnnuityCouponONDefinition) {
final AnnuityCouponONDefinition annuityCouponONDefinition = (AnnuityCouponONDefinition) swap.getSecondLeg();
onIndex = annuityCouponONDefinition.getOvernightIndex();
calendar = annuityCouponONDefinition.getCalendar();
} else if (swap.getFirstLeg().getNthPayment(0) instanceof CouponONCompoundedDefinition) {
final CouponONCompoundedDefinition couponONDefinition = (CouponONCompoundedDefinition) swap.getFirstLeg().getNthPayment(0);
onIndex = couponONDefinition.getIndex();
calendar = couponONDefinition.getCalendar();
} else if (swap.getSecondLeg().getNthPayment(0) instanceof CouponONCompoundedDefinition) {
final CouponONCompoundedDefinition couponONDefinition = (CouponONCompoundedDefinition) swap.getSecondLeg().getNthPayment(0);
onIndex = couponONDefinition.getIndex();
calendar = couponONDefinition.getCalendar();
} else {
throw new OpenGammaRuntimeException("Could not find overnight leg for " + underlyingSecurity);
}
final DayCount fixedLegDayCount = fixedLeg.getDayCount();
final Frequency frequency = fixedLeg.getFrequency();
final Period fixedLegPeriod;
if (frequency instanceof PeriodFrequency) {
fixedLegPeriod = ((PeriodFrequency) frequency).getPeriod();
} else if (frequency instanceof SimpleFrequency) {
fixedLegPeriod = ((SimpleFrequency) frequency).toPeriodFrequency().getPeriod();