class PortfolioReader {

  public Pair<Portfolio, Set<ManageableSecurity>> createPortfolio() {

    // Can't create a ManageablePortfolio as that does not hold positions
    // just object ids which we clearly don't have at this point
    SimplePortfolioNode rootNode = new SimplePortfolioNode(_portfolioName);
    Portfolio portfolio = new SimplePortfolio(_portfolioName, rootNode);

    // We don't particularly care which securities are from which node as
    // the positions contain the id bundles so we can easily reconstruct
    Set<ManageableSecurity> securities = new HashSet<>();

    ObjectsPair<ManageablePosition, ManageableSecurity[]> positionData;
    while ((positionData = _positionReader.readNext()) != null) {

      ManageablePosition manageablePosition = positionData.getFirst();

      ManageableSecurity security = positionData.getSecond()[0];
      if (security.getExternalIdBundle().isEmpty()) {
        security.setExternalIdBundle(generateNewId());
      }

      Position position = convertPosition(manageablePosition, security);

      for (ManageableSecurity sec : positionData.getSecond()) {
        securities.add(sec);
      }

      rootNode.addPosition(position);
    }

    _positionReader.close();

    return Pairs.of(portfolio, securities);
  }

  public  PortfolioReader(PositionReader positionReader, String name);

}