private HistoricalTimeSeriesInfoDocument loadTimeSeries(ExternalIdBundle idBundle) { ReferenceDataProvider referenceDataProvider = ((BloombergToolContext) getToolContext()).getBloombergReferenceDataProvider(); if (idBundle.getExternalId(ExternalSchemes.BLOOMBERG_BUID) == null && idBundle.getExternalId(ExternalSchemes.BLOOMBERG_TICKER) != null) { // For some reason loading some series by TICKER fails, but BUID works BiMap<String, ExternalIdBundle> map = BloombergDataUtils.convertToBloombergBuidKeys( Collections.singleton(idBundle), referenceDataProvider); if (map.size() != 1) { throw new OpenGammaRuntimeException("Failed to get buid"); } for (String key : map.keySet()) { ReferenceDataResult buidResult = referenceDataProvider.getFields( Collections.singleton(key), Collections.singleton(BloombergConstants.FIELD_ID_BBG_UNIQUE)); String buid = buidResult .getResult(key) .getFieldData() .getString(BloombergConstants.FIELD_ID_BBG_UNIQUE); idBundle = idBundle.withExternalId(ExternalSchemes.bloombergTickerSecurityId(buid)); } } ExternalIdBundle searchBundle = idBundle.withoutScheme( ExternalSchemes .ISIN); // For things which move country, e.g. ISIN(VALE5 BZ Equity) == ISIN(RIODF // US Equity) Map<ExternalId, UniqueId> timeSeries = getToolContext() .getHistoricalTimeSeriesLoader() .addTimeSeries( searchBundle.getExternalIds(), "CMPL", "PX_LAST", LocalDate.now().minusYears(1), null); if (timeSeries.size() != 1) { throw new OpenGammaRuntimeException( "Failed to load time series " + idBundle + " " + timeSeries); } for (UniqueId uid : timeSeries.values()) { return getToolContext().getHistoricalTimeSeriesMaster().get(uid); } throw new OpenGammaRuntimeException("Unexpected state"); }
@Override public Map<JmsTopicNameResolveRequest, String> resolve( Collection<JmsTopicNameResolveRequest> requests) { Map<JmsTopicNameResolveRequest, String> returnValue = new HashMap<JmsTopicNameResolveRequest, String>(); Map<String, Collection<JmsTopicNameResolveRequest>> lookupKey2Requests = new HashMap<String, Collection<JmsTopicNameResolveRequest>>(); for (JmsTopicNameResolveRequest request : requests) { ExternalId marketDataUniqueId = request.getMarketDataUniqueId(); if (!marketDataUniqueId.getScheme().equals(SecurityUtils.BLOOMBERG_BUID)) { s_logger.info("No Bloomberg BUID found, was given: " + marketDataUniqueId); returnValue.put(request, null); continue; } String lookupKey = BloombergDomainIdentifierResolver.toBloombergKey(marketDataUniqueId); Collection<JmsTopicNameResolveRequest> requestsForLookupKey = lookupKey2Requests.get(lookupKey); if (requestsForLookupKey == null) { requestsForLookupKey = new ArrayList<JmsTopicNameResolveRequest>(); lookupKey2Requests.put(lookupKey, requestsForLookupKey); } requestsForLookupKey.add(request); } if (!lookupKey2Requests.keySet().isEmpty()) { ReferenceDataResult referenceData = _referenceDataProvider.getFields( lookupKey2Requests.keySet(), BloombergConstants.JMS_TOPIC_NAME_RESOLVER_FIELDS); for (Map.Entry<String, Collection<JmsTopicNameResolveRequest>> entry : lookupKey2Requests.entrySet()) { String lookupKey = entry.getKey(); PerSecurityReferenceDataResult result = referenceData.getResult(lookupKey); for (JmsTopicNameResolveRequest request : entry.getValue()) { String jmsTopicName = getJmsTopicName(request, result); returnValue.put(request, jmsTopicName); } } } return returnValue; }
// ------------------------------------------------------------------------- protected ManageablePortfolio generatePortfolio(String portfolioName) { ReferenceDataProvider referenceDataProvider = ((BloombergToolContext) getToolContext()).getBloombergReferenceDataProvider(); ManageablePortfolio portfolio = new ManageablePortfolio(portfolioName); // Is this a hack? ManageablePortfolioNode rootNode = portfolio.getRootNode(); portfolio.setRootNode(rootNode); // String indexTickerSuffix = " Index"; Set<String> memberEquities = new HashSet<String>(); for (Entry<String, String> entry : INDEXES_TO_EXCHANGE.entrySet()) { String indexTickerSuffix = " Index"; String underlying = entry.getKey(); String ticker = underlying + indexTickerSuffix; // don't add index (delete at some point) // addNodes(rootNode, ticker, false, INDEX_OPTION_PERIODS); Set<String> indexMembers = BloombergDataUtils.getIndexMembers(referenceDataProvider, ticker); for (String member : indexMembers) { String symbol = getBloombergEquitySymbol(entry.getValue(), member); // time series errors for Walmart // Todo: investegate & fix if ("WMT US Equity".equals(symbol)) { continue; } memberEquities.add(symbol); } } // Sort the symbols for the current index by market cap (highest to lowest), skipping any in the // list of EXCLUDED_SECTORS TreeMap<Double, String> equityByMarketCap = new TreeMap<Double, String>(); ReferenceDataResult fields = referenceDataProvider.getFields( memberEquities, Sets.newHashSet( BloombergFields.CURRENT_MARKET_CAP_FIELD, BloombergConstants.FIELD_GICS_SUB_INDUSTRY)); for (String equity : memberEquities) { PerSecurityReferenceDataResult result = fields.getResult(equity); String gicsCodeString = result.getFieldData().getString(BloombergConstants.FIELD_GICS_SUB_INDUSTRY); GICSCode gicsCode = GICSCode.of(gicsCodeString); if (EXCLUDED_SECTORS.contains(gicsCode.getSectorDescription())) { continue; } Double marketCap = result.getFieldData().getDouble(BloombergFields.CURRENT_MARKET_CAP_FIELD); equityByMarketCap.put(marketCap, equity); } // Add a given number of symbols (MEMBERS_DEPTH) to the portfolio and store in a List // When adding to the portfolio, add a collar of options with PVs distributed equally +/- around // 0 int count = 0; List<String> chosenEquities = new ArrayList<String>(); for (Entry<Double, String> entry : equityByMarketCap.descendingMap().entrySet()) { if (count++ >= _numMembers) { break; } addNodes(rootNode, entry.getValue(), true, MEMBER_OPTION_PERIODS); chosenEquities.add(entry.getValue()); } s_logger.info("Generated collar portfolio for {}", chosenEquities); return portfolio; }