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 ConventionBundle iborIndexConvention = _conventionSource.getConventionBundle(iborLeg.getFloatingReferenceRateId());
if (iborIndexConvention == null) {
throw new OpenGammaRuntimeException("Could not get Ibor index convention for " + currency + " using " + iborLeg.getFloatingReferenceRateId() + " from swap " +
swapSecurity.getExternalIdBundle());
}
final Frequency freqIbor = iborLeg.getFrequency();
final Period tenorIbor = getTenor(freqIbor);
final IborIndex indexIbor = new IborIndex(currency, tenorIbor, iborIndexConvention.getSettlementDays(), iborIndexConvention.getDayCount(),
iborIndexConvention.getBusinessDayConvention(), iborIndexConvention.isEOMConvention(), 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;
}