Esempio n. 1
0
 public EARN_ANN_DT_TIME_HIST_WITH_EPS(Element e) {
   this.year_period = e.getElementAsString("Year/Period");
   this.announsment_date = e.getElementAsString("Announcement Date");
   this.announsment_time = e.getElementAsString("Announcement Time");
   this.earnings_EPS = e.getElementAsString("Earnings EPS");
   this.comparable_EPS = e.getElementAsString("Comparable EPS");
   this.estimate_EPS = e.getElementAsString("Estimate EPS");
 }
Esempio n. 2
0
  protected void processError(Element element) {
    int code = element.getElementAsInt32("code");
    String category = element.getElementAsString("category");
    String subcategory = element.getElementAsString("subcategory");
    String message = element.getElementAsString("message");

    String errorMessage =
        MessageFormat.format(ERROR_MESSAGE_FORMAT, code, category, subcategory, message);
    s_logger.warn(errorMessage);
  }
Esempio n. 3
0
 public BEST_ANALYST_RECS_BULK(Element element) {
   this.firm = element.getElementAsString("Firm Name");
   this.analyst = element.getElementAsString("Analyst");
   this.recom = element.getElementAsString("Recommendation");
   this.rating = element.getElementAsString("Rating");
   this.action_code = element.getElementAsString("Action Code");
   this.target_price = element.getElementAsString("Target Price");
   this.period = element.getElementAsString("Period");
   this.date = element.getElementAsString("Date");
   this.barr = element.getElementAsString("BARR");
   this.year_return = element.getElementAsString("1 Year Return");
 }
Esempio n. 4
0
 private void processFieldData(
     Element securityElem,
     String field,
     Map<String, ExternalIdBundle> bbgSecDomainMap,
     Map<ExternalIdBundle, HistoricalTimeSeries> result) {
   String secDes = securityElem.getElementAsString(BloombergConstants.SECURITY);
   ExternalIdBundle identifiers = bbgSecDomainMap.get(secDes);
   if (identifiers == null) {
     String message =
         "Found time series data for unrecognized security" + secDes + " " + bbgSecDomainMap;
     throw new OpenGammaRuntimeException(message);
   }
   HistoricalTimeSeries hts = result.get(identifiers);
   MapLocalDateDoubleTimeSeries timeSeries;
   if (hts == null) {
     timeSeries = new MapLocalDateDoubleTimeSeries();
     hts = new SimpleHistoricalTimeSeries(UID_SUPPLIER.get(), timeSeries);
     result.put(identifiers, hts);
   } else {
     timeSeries = (MapLocalDateDoubleTimeSeries) hts.getTimeSeries();
   }
   Element fieldDataArray = securityElem.getElement(FIELD_DATA);
   int numValues = fieldDataArray.numValues();
   for (int i = 0; i < numValues; i++) {
     Element fieldData = fieldDataArray.getValueAsElement(i);
     Datetime date = fieldData.getElementAsDate("date");
     double lastPrice = fieldData.getElementAsFloat64(field);
     int year = date.year();
     int month = date.month();
     int day = date.dayOfMonth();
     timeSeries.putDataPoint(LocalDate.of(year, month, day), lastPrice);
   }
 }
  @Override
  public void processMessage(Message msg) {
    final Element arraySecurityData = msg.getElement("securityData");
    final int numItems = arraySecurityData.numValues();
    for (int i = 0; i < numItems; ++i) {
      final Element securityData = arraySecurityData.getValueAsElement(i);

      final String security = securityData.getElementAsString("security");

      Map<String, Map<String, String>> pv;
      if (answer.containsKey(security)) {
        pv = answer.get(security);
      } else {
        pv = new HashMap<>();
        answer.put(security, pv);
      }
      final Map<String, String> values = new HashMap<>();
      pv.put(period, values);

      if (securityData.hasElement("securityError")) {
        final String value = securityData.getElementAsString("securityError");
        log.error("SecurityError:" + value);
        values.put("securityError", value);
        continue;
      }

      final Element fieldData = securityData.getElement("fieldData");
      for (String field : fields) {
        if (fieldData.hasElement(field)) {
          try {
            String value = fieldData.getElementAsString(field);
            values.put(field, value);
          } catch (Exception e) {
            log.error(e);
          }
        }
      }
    }
  }
Esempio n. 6
0
  private LocalDateDoubleTimeSeries processRequest(
      String identifier, Request request, String field) {
    CorrelationID cid = submitBloombergRequest(request);
    BlockingQueue<Element> resultElements = getResultElement(cid);

    if (resultElements == null || resultElements.isEmpty()) {
      s_logger.info("Unable to get HistoricalTimeSeries for {}", identifier);
      return null;
    }
    List<LocalDate> dates = new ArrayList<LocalDate>();
    List<Double> values = new ArrayList<Double>();
    for (Element resultElem : resultElements) {
      if (resultElem.hasElement(RESPONSE_ERROR)) {
        s_logger.warn("Response error");
        processError(resultElem.getElement(RESPONSE_ERROR));
      }
      Element securityElem = resultElem.getElement(SECURITY_DATA);
      if (securityElem.hasElement(SECURITY_ERROR)) {
        processError(securityElem.getElement(SECURITY_ERROR));
        return null;
      }
      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.getElement(FIELD_DATA), field, dates, values);
      }
    }
    return new ArrayLocalDateDoubleTimeSeries(dates, values);
  }
Esempio n. 7
0
  @Override
  public void processMessage(Message message) {
    Element ReferenceDataResponse = message.asElement();
    Element securityDataArray = ReferenceDataResponse.getElement("securityData");
    for (int i = 0; i < securityDataArray.numValues(); ++i) {
      final Element securityData = securityDataArray.getValueAsElement(i);

      final String security = securityData.getElementAsString("security");

      if (securityData.hasElement("securityError")) {
        log.error("SecurityError:" + securityData.getElement("securityError"));
        continue;
      }

      final Element fieldData = securityData.getElement("fieldData");

      for (String p : fields) {
        if (p.equals("BEST_ANALYST_RECS_BULK")) {
          final List<BEST_ANALYST_RECS_BULK> values = new ArrayList<>();
          bestAnalyst.put(security, values);

          final Element best_anal_recs_bulk = fieldData.getElement("BEST_ANALYST_RECS_BULK");
          for (int m = 0; m < best_anal_recs_bulk.numValues(); m++) {
            final Element e = best_anal_recs_bulk.getValueAsElement(m);
            values.add(new BEST_ANALYST_RECS_BULK(e));
          }
        }

        if (p.equals("EARN_ANN_DT_TIME_HIST_WITH_EPS")) {
          final List<EARN_ANN_DT_TIME_HIST_WITH_EPS> values = new ArrayList<>();
          earnHistWithEps.put(security, values);

          final Element element = fieldData.getElement("EARN_ANN_DT_TIME_HIST_WITH_EPS");
          for (int t = 0; t < element.numValues(); t++) {
            final Element e = element.getValueAsElement(t);
            values.add(new EARN_ANN_DT_TIME_HIST_WITH_EPS(e));
          }
        }

        if (p.equals("ERN_ANN_DT_AND_PER")) {
          final List<ERN_ANN_DT_AND_PER> values = new ArrayList<>();
          ernAnnDTandPer.put(security, values);

          final Element element = fieldData.getElement("ERN_ANN_DT_AND_PER");
          final int ernItems = element.numValues();
          for (int j = 0; j < ernItems; ++j) {
            final Element e = element.getValueAsElement(j);
            values.add(new ERN_ANN_DT_AND_PER(e));
          }
        }

        if (p.equals("BLOOMBERG_PEERS")) {
          final List<String> values = new ArrayList<String>();
          peerTicker.put(security, values);

          final Element blm_peers = fieldData.getElement("BLOOMBERG_PEERS");
          for (int j = 0; j < blm_peers.numValues(); ++j) {
            final Element e = blm_peers.getValueAsElement(j);
            final String peer = e.getElementAsString("Peer Ticker");
            values.add(peer);

            peers.add(peer);
          }
        }
      }
    }
  }
Esempio n. 8
0
 /** @param e */
 public ERN_ANN_DT_AND_PER(Element e) {
   this.ead = e.getElementAsString("Earnings Announcement Date");
   this.eyap = e.getElementAsString("Earnings Year and Period");
 }
Esempio n. 9
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;
  }