s_logger.info(sb.toString());
return securities;
}
private Pair<SwaptionSecurity, SwapSecurity> makeSwaptionAndUnderlying(final Random random, final Currency ccy, final LocalDate tradeDate, final Tenor expiry, final Tenor maturity) {
final ExternalId region = REGIONS.get(ccy);
final ExternalId floatingRate = IBOR.get(ccy);
final String swaptionString;
final Period expiryPeriod = expiry.getPeriod();
if (expiryPeriod.getYears() != 0) {
swaptionString = expiryPeriod.getYears() + "Y";
} else if (expiryPeriod.getMonths() != 0) {
swaptionString = expiryPeriod.getMonths() + "M";
} else {
throw new OpenGammaRuntimeException("Could not handle swaption expiry " + expiry);
}
final String swapString;
final Period maturityPeriod = maturity.getPeriod();
if (maturityPeriod.getYears() != 0) {
swapString = maturityPeriod.getYears() + "Y";
} else if (maturityPeriod.getMonths() != 0) {
swapString = maturityPeriod.getMonths() + "M";
} else {
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());
swap.addExternalId(underlyingId);
final SwaptionSecurity swaption = new SwaptionSecurity(payer, underlyingId, isLong, new Expiry(swaptionExpiry), isCashSettled, ccy);
swaption.setName(swaptionName);
swaption.addExternalId(ExternalId.of(ID_SCHEME, GUIDGenerator.generate().toString()));
return Pair.of(swaption, swap);