throw new OpenGammaRuntimeException("Inflation leg convention with id " + getIds(currency, INFLATION_LEG) + " was null");
}
final IndexPrice priceIndex = new IndexPrice(indexConvention.getName(), currency);
final SwapLeg payLeg = security.getPayLeg();
final SwapLeg receiveLeg = security.getReceiveLeg();
final FixedInflationSwapLeg fixedLeg;
final InflationIndexSwapLeg indexLeg;
final boolean isPayer;
if (payLeg instanceof FixedInflationSwapLeg && receiveLeg instanceof InflationIndexSwapLeg) {
fixedLeg = (FixedInflationSwapLeg) payLeg;
indexLeg = (InflationIndexSwapLeg) receiveLeg;
isPayer = true;
} else if (payLeg instanceof InflationIndexSwapLeg && receiveLeg instanceof FixedInflationSwapLeg) {
fixedLeg = (FixedInflationSwapLeg) receiveLeg;
indexLeg = (InflationIndexSwapLeg) payLeg;
isPayer = false;
} else {
throw new OpenGammaRuntimeException("Can only convert fixed / float inflation swaps");
}
final int settlementDays = fixedLegConvention.getSettlementDays();
final boolean isEOM = fixedLegConvention.isIsEOM();
final DayCount fixedLegDayCount = fixedLeg.getDayCount();
final BusinessDayConvention businessDayConvention = fixedLeg.getBusinessDayConvention();
final Calendar calendar = CalendarUtils.getCalendar(_regionSource, _holidaySource, indexConvention.getRegion());
final ZoneOffset zone = ZoneOffset.UTC; //TODO
final Period paymentPeriod = getTenor(indexLeg.getFrequency());
final Period maturityTenor = security.getMaturityTenor().getPeriod();
boolean isMonthly;
switch (indexLeg.getInterpolationMethod()) {
case MONTH_START_LINEAR:
isMonthly = true;
break;
case NONE:
isMonthly = false;
break;
default:
throw new OpenGammaRuntimeException("Cannot handle interpolation method of type " + indexLeg.getInterpolationMethod());
}
final ZonedDateTime settlementDate = ScheduleCalculator.getAdjustedDate(security.getEffectiveDate(), settlementDays, calendar).toLocalDate().atStartOfDay(zone);
final double fixedRate = fixedLeg.getRate();
final int conventionalMonthLag = indexLeg.getConventionalIndexationLag();
final int quotationMonthLag = indexLeg.getQuotationIndexationLag();
final boolean exchangeNotional = security.isExchangeInitialNotional() && security.isExchangeFinalNotional();
final double notional = ((InterestRateNotional) fixedLeg.getNotional()).getAmount();
if (isMonthly) {
return SwapFixedInflationYearOnYearDefinition.fromMonthly(priceIndex, settlementDate, paymentPeriod, (int) (maturityTenor.toTotalMonths() / 12), fixedRate,
notional, isPayer, businessDayConvention, calendar, isEOM, fixedLegDayCount, conventionalMonthLag, quotationMonthLag, exchangeNotional);
}
return SwapFixedInflationYearOnYearDefinition.fromInterpolation(priceIndex, settlementDate, paymentPeriod, maturityTenor, fixedRate,