s_logger.debug("Got option {}", optionTicker);
final BloombergTickerParserEQOption optionInfo = BloombergTickerParserEQOption.getOptionParser(optionTicker);
s_logger.debug("Got option info {}", optionInfo);
final LocalDate key = optionInfo.getExpiry();
Set<BloombergTickerParserEQOption> set = optionsByExpiry.get(key);
if (set == null) {
set = new HashSet<BloombergTickerParserEQOption>();
optionsByExpiry.put(key, set);
}
set.add(optionInfo);
}
final Set<ExternalId> tickersToLoad = new HashSet<ExternalId>();
final BigDecimal expiryCount = BigDecimal.valueOf(expiries.length);
final BigDecimal defaultAmountAtExpiry = underlyingAmount.divide(expiryCount, BigDecimal.ROUND_DOWN);
final BigDecimal spareAmountAtExpiry = defaultAmountAtExpiry.add(BigDecimal.ONE);
int spareCount = underlyingAmount.subtract(defaultAmountAtExpiry.multiply(expiryCount)).intValue();
for (final Period bucketPeriod : expiries) {
final ManageablePortfolioNode bucketNode = new ManageablePortfolioNode(bucketPeriod.toString().substring(1));
final LocalDate nowish = LocalDate.now().withDayOfMonth(20); //This avoids us picking different options every time this script is run
final LocalDate targetExpiry = nowish.plus(bucketPeriod);
final LocalDate chosenExpiry = optionsByExpiry.floorKey(targetExpiry);
if (chosenExpiry == null) {
s_logger.info("No options for {} on {}", targetExpiry, underlying);
continue;
}
s_logger.info("Using time {} for bucket {} ({})", new Object[] {chosenExpiry, bucketPeriod, targetExpiry });