示例#1
0
  private HistoricalTimeSeries doGetHistoricalTimeSeries(
      ExternalIdBundle identifiers,
      String dataSource,
      String dataProvider,
      String field,
      LocalDate startDate,
      LocalDate endDate,
      Integer maxPoints) {
    ArgumentChecker.notNull(identifiers, "identifiers");
    ArgumentChecker.notNull(field, "field");
    ArgumentChecker.notNull(startDate, "startDate");
    ArgumentChecker.notNull(endDate, "endDate");
    Validate.isTrue(
        ObjectUtils.equals(dataSource, BLOOMBERG_DATA_SOURCE_NAME),
        getClass().getName() + "cannot support " + dataSource);

    if (maxPoints != null && maxPoints > 0) {
      throw new UnsupportedOperationException(
          "Fetching a bounded number of points from the start of a Bloomberg time-series is unsupported");
    }

    s_logger.info("Getting HistoricalTimeSeries for security {}", identifiers);

    ensureStarted();

    if (endDate.isBefore(startDate)) {
      throw new IllegalArgumentException("endDate must be after startDate");
    }
    ExternalId dsid = BloombergDomainIdentifierResolver.resolvePreferredIdentifier(identifiers);
    String bbgKey =
        BloombergDomainIdentifierResolver.toBloombergKeyWithDataProvider(dsid, dataProvider);
    Request request =
        composeRequest(bbgKey, dataSource, dataProvider, field, startDate, endDate, maxPoints);
    _statistics.gotFields(Collections.singleton(bbgKey), Collections.singleton(field));
    LocalDateDoubleTimeSeries timeSeries = processRequest(bbgKey, request, field);
    return new SimpleHistoricalTimeSeries(UID_SUPPLIER.get(), timeSeries);
  }
示例#2
0
  // -------------------------------------------------------------------------
  @Override
  public Map<ExternalIdBundle, HistoricalTimeSeries> getHistoricalTimeSeries(
      Set<ExternalIdBundle> identifierSet,
      String dataSource,
      String dataProvider,
      String dataField,
      LocalDate start,
      boolean includeStart,
      LocalDate end,
      boolean includeEnd) {
    ArgumentChecker.notNull(identifierSet, "identifierSet");
    ArgumentChecker.notNull(dataField, "dataField");
    ArgumentChecker.notNull(start, "start");
    ArgumentChecker.notNull(end, "end");
    Validate.isTrue(
        ObjectUtils.equals(dataSource, BLOOMBERG_DATA_SOURCE_NAME),
        getClass().getName() + "cannot support " + dataSource);

    if (end.isBefore(start)) {
      throw new IllegalArgumentException("end must be after start");
    }

    ensureStarted();
    s_logger.debug("Getting historical data for {}", identifierSet);

    if (identifierSet.isEmpty()) {
      s_logger.info("Historical data request for empty identifier set");
      return Collections.emptyMap();
    }
    Map<String, ExternalIdBundle> bbgSecDomainMap = new HashMap<String, ExternalIdBundle>();
    Request request = getRefDataService().createRequest(BLOOMBERG_HISTORICAL_DATA_REQUEST);
    Element securitiesElem = request.getElement(BLOOMBERG_SECURITIES_REQUEST);
    for (ExternalIdBundle identifiers : identifierSet) {
      ExternalId preferredIdentifier =
          BloombergDomainIdentifierResolver.resolvePreferredIdentifier(identifiers);
      s_logger.debug(
          "Resolved preferred identifier {} from identifier bundle {}",
          preferredIdentifier,
          identifiers);
      String bbgKey =
          BloombergDomainIdentifierResolver.toBloombergKeyWithDataProvider(
              preferredIdentifier, dataProvider);
      securitiesElem.appendValue(bbgKey);
      bbgSecDomainMap.put(bbgKey, identifiers);
    }

    Element fieldElem = request.getElement(BLOOMBERG_FIELDS_REQUEST);
    fieldElem.appendValue(dataField);

    // TODO: inclusive start / exclusive end
    request.set("periodicityAdjustment", "ACTUAL");
    request.set("periodicitySelection", "DAILY");
    request.set("startDate", printYYYYMMDD(start));
    request.set("endDate", printYYYYMMDD(end));
    request.set("adjustmentSplit", true);

    _statistics.gotFields(bbgSecDomainMap.keySet(), Collections.singleton(dataField));
    CorrelationID cid = submitBloombergRequest(request);
    BlockingQueue<Element> resultElements = getResultElement(cid);
    if (resultElements == null || resultElements.isEmpty()) {
      s_logger.warn("Unable to get historical data for {}", identifierSet);
      return null;
    }

    // REVIEW simon 2011/11/01: should this be deduped with the single case?
    Map<ExternalIdBundle, HistoricalTimeSeries> result =
        new HashMap<ExternalIdBundle, HistoricalTimeSeries>();
    for (Element resultElem : resultElements) {
      if (resultElem.hasElement(RESPONSE_ERROR)) {
        s_logger.warn("Response error");
        processError(resultElem.getElement(RESPONSE_ERROR));
        continue;
      }
      Element securityElem = resultElem.getElement(SECURITY_DATA);
      if (securityElem.hasElement(SECURITY_ERROR)) {
        processError(securityElem.getElement(SECURITY_ERROR));
      }
      if (securityElem.hasElement(FIELD_EXCEPTIONS)) {
        Element fieldExceptions = securityElem.getElement(FIELD_EXCEPTIONS);

        for (int i = 0; i < fieldExceptions.numValues(); i++) {
          Element fieldException = fieldExceptions.getValueAsElement(i);
          String fieldId = fieldException.getElementAsString(FIELD_ID);
          s_logger.warn("Field error on {}", fieldId);
          Element errorInfo = fieldException.getElement(ERROR_INFO);
          processError(errorInfo);
        }
      }
      if (securityElem.hasElement(FIELD_DATA)) {
        processFieldData(securityElem, dataField, bbgSecDomainMap, result);
      }
    }
    if (identifierSet.size() != result.size()) {
      s_logger.warn(
          "Failed to get time series results for ({}/{}) {}",
          new Object[] {
            identifierSet.size() - result.size(),
            identifierSet.size(),
            Sets.difference(identifierSet, result.keySet())
          });
    }
    return result;
  }