PortfolioReader { public Pair<Portfolio, Set<ManageableSecurity>> createPortfolio() { SimplePortfolioNode rootNode = new SimplePortfolioNode(_portfolioName); Portfolio portfolio = new SimplePortfolio(_portfolioName, rootNode); 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); } PortfolioReader(PositionReader positionReader, String name); Pair<Portfolio, Set<ManageableSecurity>> createPortfolio();  }
@Test public void testListedSecurityLoad() { String data = "\"currency\",\"exchange\",\"exerciseType\",\"expiry\",\"externalIdBundle\",\"underlyingId\",\"optionType\",\"position:quantity\",\"securityType\",\"trade:counterpartyExternalId\",\"trade:deal\",\"trade:premium\",\"trade:premiumCurrency\",\"trade:premiumDate\",\"trade:premiumTime\",\"trade:quantity\",\"trade:tradeDate\",\"trade:tradeTime\"\n" + "\"USD\",\"NEW YORK STOCK EXCHANGE INC.\",\"European\",\"2050-01-01T00:00:00+00:00[Europe/London]\",\"EIFO_ID~EIFO1234\",\"UNDERLYING_ID~ul9999\",\"PUT\",\"1264\",\"EQUITY_INDEX_FUTURE_OPTION\",\"CPID~123\",,,,,,1000,\"2014-01-01\",\n"; populateFileWithData(data); PortfolioReader portfolioReader = new PortfolioReader(new SingleSheetSimplePositionReader(_tempFile.getAbsolutePath(), "EquityIndexFutureOption"), "EquityIndexFutureOption Portfolio" ); Pair<Portfolio, Set<ManageableSecurity>> pair = portfolioReader.createPortfolio(); Portfolio portfolio = pair.getFirst(); assertThat(portfolio.getName(), is("EquityIndexFutureOption Portfolio")); Set<ManageableSecurity> securities = pair.getSecond(); assertThat(securities.size(), is(1)); final ExternalIdBundle idBundle = securities.iterator().next().getExternalIdBundle(); assertThat(idBundle, is(ExternalIdBundle.of("EIFO_ID", "EIFO1234"))); List<Position> positions = portfolio.getRootNode().getPositions(); assertThat(positions.size(), is(1)); assertThat(positions.get(0).getSecurityLink().getExternalId(), is(idBundle)); assertThat(positions.get(0).getTrades().iterator().next().getSecurityLink().getExternalId(), is(idBundle)); }
@Test public void testOtcSecurityLoad() { String data = "adjustCashSettlementDate,adjustEffectiveDate,adjustMaturityDate,businessDayConvention,buy,cashSettlementDate,coupon,couponFrequency,dayCount,debtSeniority,effectiveDate,immAdjustMaturityDate,includeAccruedPremium,maturityDate,name,notional,position:quantity,protectionBuyer,protectionSeller,protectionStart,quotedSpread,recoveryRate,referenceEntity,regionId,restructuringClause,startDate,stubType,trade:counterpartyExternalId,trade:premium,trade:premiumCurrency,trade:premiumDate,trade:premiumTime,trade:quantity,trade:tradeDate,trade:tradeTime,upfrontAmount\n" + "FALSE,FALSE,FALSE,Following,TRUE,2013-03-24T00:00:00.0Z,100,Semi-annual,ACT/360,SNRFOR,2013-03-21T00:00:00.0Z,FALSE,TRUE,2020-03-20T00:00:00.0Z,STEM GBP 100 7Y,GBP 1000000,1,EXTERNAL_CODE~ProtBuyer_1,EXTERNAL_CODE~ProtSeller_1,TRUE,100,0.4,MARKIT_RED_CODE~5AB67W,FINANCIAL_REGION~CARIBBEAN,MR,2013-03-20T00:00:00.0Z,SHORT_START,EXTERNAL_CODE~ProtSeller_1,,,,,1,2013-03-22,,GBP 50000"; populateFileWithData(data); PortfolioReader portfolioReader = new PortfolioReader(new SingleSheetSimplePositionReader(_tempFile.getAbsolutePath(), "StandardVanillaCDS"), "CDS Portfolio"); Pair<Portfolio, Set<ManageableSecurity>> pair = portfolioReader.createPortfolio(); Portfolio portfolio = pair.getFirst(); assertThat(portfolio.getName(), is("CDS Portfolio")); Set<ManageableSecurity> securities = pair.getSecond(); assertThat(securities.size(), is(1)); ExternalIdBundle idBundle = securities.iterator().next().getExternalIdBundle(); assertThat(idBundle.isEmpty(), is(false)); List<Position> positions = portfolio.getRootNode().getPositions(); assertThat(positions.size(), is(1)); assertThat(positions.get(0).getSecurityLink().getExternalId(), is(idBundle)); assertThat(positions.get(0).getTrades().iterator().next().getSecurityLink().getExternalId(), is(idBundle)); }