private SwapSecurity makeSwap(final Random random, final Tenor tenor) {
final ZonedDateTime tradeDate = TRADE_DATE.atStartOfDay(ZoneOffset.UTC);
final ZonedDateTime maturityDate = tradeDate.plus(tenor.getPeriod());
final ExternalId iborReferenceRate = LIBOR_3M;
final PeriodFrequency frequency = PeriodFrequency.QUARTERLY;
final ExternalId cmsId = TICKERS.get(tenor);
if (cmsId == null) {
throw new OpenGammaRuntimeException("Could not get swap rate ticker for " + tenor);
}
final InterestRateNotional notional = new InterestRateNotional(Currency.USD, 1000000 * (1 + random.nextInt(50)));
final FloatingInterestRateLeg iborLeg = new FloatingInterestRateLeg(ACT_360, frequency, REGION, FOLLOWING, notional, true,
iborReferenceRate, FloatingRateType.IBOR);
final FloatingInterestRateLeg cmsLeg = new FloatingInterestRateLeg(ACT_360, frequency, REGION, FOLLOWING, notional, true,
cmsId, FloatingRateType.CMS);
SwapSecurity security;
boolean payIbor;
if (random.nextBoolean()) {
security = new SwapSecurity(tradeDate, tradeDate, maturityDate, COUNTERPARTY, iborLeg, cmsLeg);
payIbor = true;
} else {
security = new SwapSecurity(tradeDate, tradeDate, maturityDate, COUNTERPARTY, cmsLeg, iborLeg);
payIbor = false;
}
security.setName(CURRENCY.getCode() + " " + FORMAT.format(notional.getAmount() / 1000000) + "MM Swap, pay " +
(payIbor ? frequency.getPeriod().getMonths() + "M Libor, receive " + tenor.getPeriod().getYears() + "Y ISDA fixing (" :
tenor.getPeriod().getYears() + "Y ISDA fixing, receive " + frequency.getPeriod().getMonths() + "M Libor (") +
tradeDate.toLocalDate().toString() + " - " + maturityDate.toLocalDate().toString() + ")");
security.addExternalId(ExternalId.of(ID_SCHEME, GUIDGenerator.generate().toString()));
return security;
}