throw new OpenGammaRuntimeException("Could not handle swap maturity " + maturity);
}
final ZonedDateTime swaptionExpiry = tradeDate.plus(expiryPeriod).atStartOfDay().atZone(ZoneOffset.UTC);
final ZonedDateTime swapMaturity = swaptionExpiry.plus(maturity.getPeriod());
final double amount = 100000 * (1 + random.nextInt(30));
final InterestRateNotional notional = new InterestRateNotional(ccy, amount);
final double rate = getSwapRate(ccy, tradeDate, maturity) * (1 + ((random.nextDouble() - 0.5) / 30.));
final Frequency frequency = ccy.equals(Currency.USD) ? PeriodFrequency.QUARTERLY : PeriodFrequency.SEMI_ANNUAL;
final SwapLeg fixedLeg = new FixedInterestRateLeg(DAY_COUNT, PeriodFrequency.SEMI_ANNUAL, region, BDC, notional, false, rate);
final SwapLeg floatLeg = new FloatingInterestRateLeg(DAY_COUNT, frequency, region, BDC, notional, false, floatingRate, FloatingRateType.IBOR);
final SwapLeg payLeg, receiveLeg;
final String swapName, swaptionName;
final boolean isLong = random.nextBoolean();
final boolean isCashSettled = random.nextBoolean();
final boolean payer;
if (random.nextBoolean()) {
payLeg = fixedLeg;
receiveLeg = floatLeg;
swapName = swapString + " pay " + ccy + " " + notional.getAmount() + " @ " + STRIKE_FORMATTER.format(rate);
swaptionName = (isLong ? "Long " : "Short ") + swaptionString + " x " + swapString + " pay " + ccy + " " + notional.getAmount() + " @ " + STRIKE_FORMATTER.format(rate);
payer = true;
} else {
payLeg = floatLeg;
receiveLeg = fixedLeg;
swapName = swapString + " receive " + ccy + " " + notional.getAmount() + " @ " + STRIKE_FORMATTER.format(rate);
swaptionName = (isLong ? "Long " : "Short ") + swaptionString + " x " + swapString + " receive " + ccy + " " + notional.getAmount() + " @ " + STRIKE_FORMATTER.format(rate);
payer = false;
}
final SwapSecurity swap = new SwapSecurity(swaptionExpiry, swaptionExpiry.plusDays(2), swapMaturity, COUNTERPARTY, payLeg, receiveLeg);
swap.setName(swapName);
final ExternalId underlyingId = ExternalId.of(ID_SCHEME, GUIDGenerator.generate().toString());