final ZonedDateTime endDate = capFloorCMSSpreadSecurity.getMaturityDate();
final double notional = capFloorCMSSpreadSecurity.getNotional();
final Currency currency = capFloorCMSSpreadSecurity.getCurrency();
final Frequency payFreq = capFloorCMSSpreadSecurity.getFrequency();
// FIXME: convert frequency to period in a better way
final Period tenorPayment = getTenor(payFreq);
final ExternalId[] swapIndexId = new ExternalId[2];
swapIndexId[0] = capFloorCMSSpreadSecurity.getLongId();
swapIndexId[1] = capFloorCMSSpreadSecurity.getShortId();
final ConventionBundle[] swapIndexConvention = new ConventionBundle[2];
final ConventionBundle[] iborIndexConvention = new ConventionBundle[2];
for (int loopindex = 0; loopindex < 2; loopindex++) {
swapIndexConvention[loopindex] = _conventionSource.getConventionBundle(swapIndexId[loopindex]);
if (swapIndexConvention[loopindex] == null) {
throw new OpenGammaRuntimeException("Could not get swap index convention for " + swapIndexId[loopindex].toString());
}
iborIndexConvention[loopindex] = _conventionSource.getConventionBundle(swapIndexConvention[loopindex].getSwapFloatingLegInitialRate());
if (iborIndexConvention[loopindex] == null) {
throw new OpenGammaRuntimeException("Could not get ibor index convention for " + swapIndexConvention[loopindex].getSwapFloatingLegInitialRate());
}
}
final ExternalId regionId = swapIndexConvention[0].getSwapFloatingLegRegion();
final Calendar calendar = CalendarUtils.getCalendar(_regionSource, _holidaySource, regionId);
final IborIndex[] iborIndex = new IborIndex[2];
final IndexSwap[] swapIndex = new IndexSwap[2];
for (int loopindex = 0; loopindex < 2; loopindex++) {
iborIndex[loopindex] = new IborIndex(currency, tenorPayment, iborIndexConvention[loopindex].getSettlementDays(), iborIndexConvention[loopindex].getDayCount(),
iborIndexConvention[loopindex].getBusinessDayConvention(), iborIndexConvention[loopindex].isEOMConvention());
final Period fixedLegPaymentPeriod = getTenor(swapIndexConvention[loopindex].getSwapFixedLegFrequency());
swapIndex[loopindex] = new IndexSwap(fixedLegPaymentPeriod, swapIndexConvention[loopindex].getSwapFixedLegDayCount(), iborIndex[loopindex], swapIndexConvention[loopindex].getPeriod(), calendar);
}
return AnnuityCapFloorCMSSpreadDefinition.from(startDate, endDate, notional, swapIndex[0], swapIndex[1], tenorPayment, capFloorCMSSpreadSecurity.getDayCount(),
capFloorCMSSpreadSecurity.isPayer(), capFloorCMSSpreadSecurity.getStrike(), capFloorCMSSpreadSecurity.isCap(), calendar, calendar);
}