示例#1
0
  // -------------------------------------------------------------------------
  private Request composeRequest(
      final String identifier,
      final String dataSource,
      final String dataProvider,
      final String field,
      LocalDate startDate,
      LocalDate endDate,
      Integer maxPoints) {
    ArgumentChecker.notNull(identifier, "identifier must not be null or empty");

    Request request = getRefDataService().createRequest(BLOOMBERG_HISTORICAL_DATA_REQUEST);
    Element securitiesElem = request.getElement(BLOOMBERG_SECURITIES_REQUEST);
    securitiesElem.appendValue(identifier);

    Element fieldElem = request.getElement(BLOOMBERG_FIELDS_REQUEST);

    fieldElem.appendValue(field == null ? "PX_LAST" : field);

    request.set("periodicityAdjustment", "ACTUAL");
    request.set("periodicitySelection", "DAILY");
    request.set("startDate", DateUtils.printYYYYMMDD(startDate));
    request.set("endDate", DateUtils.printYYYYMMDD(endDate));
    request.set("returnEids", true);

    if (maxPoints != null && maxPoints <= 0) {
      request.set("maxDataPoints", -maxPoints);
    }

    return request;
  }
  @Override
  public void execute(String name) {
    final BloombergSession bs = new BloombergSession(name);
    bs.start();
    try {
      final Service service = bs.getService("//blp/refdata");

      for (String crncy : currency) {

        final String idq[] = {"1CQ", "2CQ", "3CQ", "4CQ", "1CS", "2CS", "1CY", "2CY"};
        for (final String quarter : idq) {
          final Request request = service.createRequest("ReferenceDataRequest");

          final Element _securities = request.getElement("securities");
          for (String s : securities) {
            final int p = s.indexOf('|');
            if (crncy.equals(s.substring(p + 1))) {
              _securities.appendValue(s.substring(0, p));
            }
          }

          final Element _fields = request.getElement("fields");
          for (String field : fields) {
            _fields.appendValue(field);
          }

          final Element overrides = request.getElement("overrides");

          final Element overridePeriod = overrides.appendElement();
          overridePeriod.setElement("fieldId", "BEST_FPERIOD_OVERRIDE");
          overridePeriod.setElement("value", period = quarter);

          final Element overrideCrncy = overrides.appendElement();
          overrideCrncy.setElement("fieldId", "EQY_FUND_CRNCY");
          overrideCrncy.setElement("value", crncy);

          if (null != override) {
            final Element overrideDataSource = overrides.appendElement();
            overrideDataSource.setElement("fieldId", "BEST_DATA_SOURCE_OVERRIDE");
            overrideDataSource.setElement("value", override);
          }

          bs.sendRequest(request, this);
        }
      }
    } finally {
      bs.stop();
    }
  }
示例#3
0
  @Override
  public void execute(String name) {
    final BloombergSession bs = new BloombergSession(name);
    bs.start();
    try {
      final Request request = bs.createRequest("//blp/refdata", "ReferenceDataRequest");

      Element _securities = request.getElement("securities");
      for (String security : securities) {
        _securities.appendValue(security);
      }

      Element _fields = request.getElement("fields");
      for (String field : fields) {
        _fields.appendValue(field);
      }

      bs.sendRequest(request, this);

      if (!peers.isEmpty()) {
        final Request requestP = bs.createRequest("//blp/refdata", "ReferenceDataRequest");

        final Element securitiesP = requestP.getElement("securities");
        for (String peer : peers) {
          securitiesP.appendValue(peer + " Equity");
        }

        final Element fieldsP = requestP.getElement("fields");
        fieldsP.appendValue("CUR_MKT_CAP");
        fieldsP.appendValue("OPER_ROE");
        fieldsP.appendValue("BS_TOT_LIAB2");
        fieldsP.appendValue("PE_RATIO");
        fieldsP.appendValue("INDUSTRY_subGROUP");
        fieldsP.appendValue("INDUSTRY_GROUP");
        fieldsP.appendValue("EBITDA");

        bs.sendRequest(
            requestP,
            new MessageHandler() {

              @Override
              public void processMessage(Message message) {
                Element ReferenceDataResponse = message.asElement();
                if (ReferenceDataResponse.hasElement("responseError")) {
                  log.error("*****ResponceError*****");
                }
                Element securityDataArray = ReferenceDataResponse.getElement("securityData");
                int numItems = securityDataArray.numValues();
                for (int i = 0; i < numItems; ++i) {
                  Element securityData = securityDataArray.getValueAsElement(i);
                  String security = securityData.getElementAsString("security");
                  if (securityData.hasElement("securityError")) {
                    log.error("SecurityError:" + securityData.getElement("securityError"));
                    return;
                  } else {
                    Element fieldData = securityData.getElement("fieldData");

                    final PeerData item = new PeerData(security, fieldData);
                    peersData.add(item);
                  }
                }
              }
            },
            new CorrelationID(1));
      }
    } finally {
      bs.stop();
    }
  }
示例#4
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;
  }