final ZonedDateTime effectiveDate = swapSecurity.getEffectiveDate();
final ZonedDateTime maturityDate = swapSecurity.getMaturityDate();
final SwapLeg payLeg = swapSecurity.getPayLeg();
final SwapLeg receiveLeg = swapSecurity.getReceiveLeg();
final FixedInterestRateLeg fixedLeg = (FixedInterestRateLeg) (payFixed ? payLeg : receiveLeg);
final FloatingInterestRateLeg iborLeg = (FloatingInterestRateLeg) (payFixed ? receiveLeg : payLeg);
final ExternalId regionId = payLeg.getRegionId();
final Calendar calendar = CalendarUtils.getCalendar(_regionSource, _holidaySource, regionId);
final Currency currency = ((InterestRateNotional) payLeg.getNotional()).getCurrency();
final IborIndexConvention iborIndexConvention = getIborLegConvention(currency);
final Frequency freqIbor = iborLeg.getFrequency();
final Period tenorIbor = getTenor(freqIbor);
final int spotLag = iborIndexConvention.getSettlementDays();
final IborIndex indexIbor = new IborIndex(currency, tenorIbor, spotLag, iborIndexConvention.getDayCount(),
iborIndexConvention.getBusinessDayConvention(), iborIndexConvention.isIsEOM(), iborIndexConvention.getName());
final Frequency freqFixed = fixedLeg.getFrequency();
final Period tenorFixed = getTenor(freqFixed);
final double fixedLegNotional = ((InterestRateNotional) fixedLeg.getNotional()).getAmount();
final double iborLegNotional = ((InterestRateNotional) iborLeg.getNotional()).getAmount();
if (hasSpread) {
final double spread = ((FloatingSpreadIRLeg) iborLeg).getSpread();
return SwapFixedIborSpreadDefinition.from(effectiveDate, maturityDate, tenorFixed, fixedLeg.getDayCount(), fixedLeg.getBusinessDayConvention(), fixedLeg.isEom(), fixedLegNotional,
fixedLeg.getRate(), tenorIbor, iborLeg.getDayCount(), iborLeg.getBusinessDayConvention(), iborLeg.isEom(), iborLegNotional, indexIbor, spread, payFixed, calendar);
}
final SwapFixedIborDefinition swap = SwapFixedIborDefinition.from(effectiveDate, maturityDate, tenorFixed, fixedLeg.getDayCount(), fixedLeg.getBusinessDayConvention(), fixedLeg.isEom(),
fixedLegNotional, fixedLeg.getRate(), tenorIbor, iborLeg.getDayCount(), iborLeg.getBusinessDayConvention(), iborLeg.isEom(), iborLegNotional, indexIbor, payFixed, calendar);
return swap;
}