final PositionGenerator positions = new SimplePositionGenerator<>(securities, getSecurityPersister(), getCounterPartyGenerator());
return new LeafPortfolioNodeGenerator(new StaticNameGenerator("Swaptions"), positions, size);
}
private SwaptionSecurity[] createSwaptions(final int size) {
final SecurityMaster securityMaster = getToolContext().getSecurityMaster();
final List<Currency> currencies = new ArrayList<>(REGIONS.keySet());
final ZonedDateTime[] tradeDates = new ZonedDateTime[size];
final Random rng = new Random(123);
final ZonedDateTime date = DateUtils.previousWeekDay().atStartOfDay(ZoneOffset.UTC);
Arrays.fill(tradeDates, date);
final SwaptionSecurity[] swaptions = new SwaptionSecurity[size];
for (int i = 0; i < size; i++) {
final Currency currency = currencies.get(rng.nextInt(currencies.size()));
final ExternalId region = REGIONS.get(currency);
final ExternalId floatingRate = TICKERS.get(currency);
final int swaptionYears = 1 + rng.nextInt(9);
final ZonedDateTime swaptionExpiry = date.plusYears(swaptionYears);
final int swapYears = 1 + rng.nextInt(28);
final ZonedDateTime swapMaturity = swaptionExpiry.plusMonths(swapYears);
final double amount = 100000 * (1 + rng.nextInt(30));
final InterestRateNotional notional = new InterestRateNotional(currency, amount);
final double rate = swapYears * rng.nextDouble() / 500;
final Frequency frequency = currency.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 = rng.nextBoolean();
final boolean isCashSettled = rng.nextBoolean();
final boolean payer;
if (rng.nextBoolean()) {
payLeg = fixedLeg;
receiveLeg = floatLeg;
swapName = swapYears + "Y pay " + currency + " " + notional.getAmount() + " @ " + STRIKE_FORMATTER.format(rate);
swaptionName = (isLong ? "Long " : "Short ") + swaptionYears + "Y x " + swapYears + "Y pay " + currency + " " + notional.getAmount() + " @ " + STRIKE_FORMATTER.format(rate);
payer = true;
} else {
payLeg = floatLeg;
receiveLeg = fixedLeg;
swapName = swapYears + "Y receive " + currency + " " + notional.getAmount() + " @ " + STRIKE_FORMATTER.format(rate);
swaptionName = (isLong ? "Long " : "Short ") + swaptionYears + "Y x " + swapYears + "Y receive " + currency + " " + notional.getAmount() + " @ " + STRIKE_FORMATTER.format(rate);
payer = false;
}
final SwapSecurity swap = new SwapSecurity(swaptionExpiry, swaptionExpiry.plusDays(2), swapMaturity, COUNTER_PARTY_OPT, payLeg, receiveLeg);
swap.setName(swapName);
final SecurityDocument toAddDoc = new SecurityDocument();
toAddDoc.setSecurity(swap);
securityMaster.add(toAddDoc);
final ExternalId swapId = getSecurityPersister().storeSecurity(swap).iterator().next();
final SwaptionSecurity swaption = new SwaptionSecurity(payer, swapId, isLong, new Expiry(swaptionExpiry), isCashSettled, currency);
swaption.setName(swaptionName);
swaptions[i] = swaption;
}