final ZonedDateTime endDate = capFloorSecurity.getMaturityDate();
final double notional = capFloorSecurity.getNotional();
final Currency currency = capFloorSecurity.getCurrency();
final Frequency payFreq = capFloorSecurity.getFrequency();
// FIXME: convert frequency to period in a better way
final Period tenorPayment = getTenor(payFreq);
final boolean isIbor = capFloorSecurity.isIbor();
final ConventionBundle iborIndexConvention;
final ExternalId regionId;
if (isIbor) { // Cap/floor on Ibor
iborIndexConvention = _conventionSource.getConventionBundle(capFloorSecurity.getUnderlyingId());
if (iborIndexConvention == null) {
throw new OpenGammaRuntimeException("Could not get ibor index convention for " + capFloorSecurity.getUnderlyingId());
}
regionId = iborIndexConvention.getRegion();
final Calendar calendar = CalendarUtils.getCalendar(_regionSource, _holidaySource, regionId);
final IborIndex index = new IborIndex(currency, iborIndexConvention.getPeriod(), iborIndexConvention.getSettlementDays(), iborIndexConvention.getDayCount(),
iborIndexConvention.getBusinessDayConvention(), iborIndexConvention.isEOMConvention(), "Ibor");
return AnnuityCapFloorIborDefinition.from(startDate, endDate, notional, index, capFloorSecurity.getDayCount(), tenorPayment, capFloorSecurity.isPayer(), capFloorSecurity.getStrike(),
capFloorSecurity.isCap(), calendar);
}
// Cap/floor on CMS
final ConventionBundle swapIndexConvention = _conventionSource.getConventionBundle(capFloorSecurity.getUnderlyingId());
if (swapIndexConvention == null) {
throw new OpenGammaRuntimeException("Could not get swap index convention for " + capFloorSecurity.getUnderlyingId().toString());
}
iborIndexConvention = _conventionSource.getConventionBundle(swapIndexConvention.getSwapFloatingLegInitialRate());
if (iborIndexConvention == null) {
throw new OpenGammaRuntimeException("Could not get ibor index convention for " + swapIndexConvention.getSwapFloatingLegInitialRate());
}
regionId = swapIndexConvention.getSwapFloatingLegRegion();
final Calendar calendar = CalendarUtils.getCalendar(_regionSource, _holidaySource, regionId);
final IborIndex iborIndex = new IborIndex(currency, tenorPayment, iborIndexConvention.getSettlementDays(), iborIndexConvention.getDayCount(),
iborIndexConvention.getBusinessDayConvention(), iborIndexConvention.isEOMConvention());
final Period fixedLegPaymentPeriod = getTenor(swapIndexConvention.getSwapFixedLegFrequency());
final IndexSwap swapIndex = new IndexSwap(fixedLegPaymentPeriod, swapIndexConvention.getSwapFixedLegDayCount(), iborIndex, swapIndexConvention.getPeriod(), calendar);
return AnnuityCapFloorCMSDefinition.from(startDate, endDate, notional, swapIndex, tenorPayment, capFloorSecurity.getDayCount(), capFloorSecurity.isPayer(), capFloorSecurity.getStrike(),
capFloorSecurity.isCap(), calendar);
}