// load all equity securities
final Collection<EquitySecurity> securities = createAndPersistEquitySecurities();
// create shell portfolio
final ManageablePortfolio portfolio = createEmptyPortfolio();
final ManageablePortfolioNode rootNode = portfolio.getRootNode();
// add each security to the portfolio
for (EquitySecurity security : securities) {
GICSCode gics = security.getGicsCode();
if (gics == null || gics.getCode().length() != 2) {
continue;
}
String sector = SECTORS.get(gics.getSectorCode());
if (sector == null) {
s_logger.info("unrecognised sector code {}", gics.getSectorCode());
continue;
}
// create portfolio structure
ManageablePortfolioNode sectorNode = rootNode.findNodeByName(sector);
if (sectorNode == null) {
s_logger.debug("Creating node for sector {}", sector);
sectorNode = new ManageablePortfolioNode(sector);
rootNode.addChildNode(sectorNode);
}
// create the position and add it to the master
final ManageablePosition position = createPositionAndTrade(security);
final PositionDocument addedPosition = addPosition(position);
// add the position reference (the unique identifier) to portfolio
sectorNode.addPosition(addedPosition.getUniqueId());
}
// adds the complete tree structure to the master
addPortfolio(portfolio);
}