Ejemplo n.º 1
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);
   }
 }
Ejemplo n.º 2
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);
  }
Ejemplo n.º 3
0
 private static UniqueId createSyntheticIdentifier() {
   return s_syntheticIdentifiers.get();
 }