예제 #1
0
 /**
  * Gets the best descriptive name.
  *
  * @return the best descriptive name, not null
  */
 public String getBestName() {
   Security security = getTarget();
   ObjectId objectId = getObjectId();
   ExternalIdBundle bundle = getExternalId();
   if (security != null) {
     // Try to retrieve the security's assigned name
     String name = security.getName();
     if (StringUtils.isNotBlank(name)) {
       return name;
     }
     bundle = security.getExternalIdBundle();
   }
   if (bundle != null && bundle.size() > 0) {
     if (bundle.getValue(ExternalSchemes.BLOOMBERG_TICKER) != null) {
       return bundle.getValue(ExternalSchemes.BLOOMBERG_TICKER);
     } else if (bundle.getValue(ExternalSchemes.RIC) != null) {
       return bundle.getValue(ExternalSchemes.RIC);
     } else if (bundle.getValue(ExternalSchemes.ACTIVFEED_TICKER) != null) {
       return bundle.getValue(ExternalSchemes.ACTIVFEED_TICKER);
     } else {
       return bundle.getExternalIds().iterator().next().getValue();
     }
   }
   if (objectId != null) {
     return objectId.toString();
   }
   return "";
 }
예제 #2
0
 /**
  * Checks if this bundle contains any key from the specified bundle.
  *
  * @param bundle the bundle to search for, empty returns false, not null
  * @return true if this bundle contains any key from the specified bundle
  */
 public boolean containsAny(final ExternalIdBundle bundle) {
   ArgumentChecker.notNull(bundle, "bundle");
   for (final ExternalId externalId : bundle.getExternalIds()) {
     if (_externalIds.contains(externalId)) {
       return true;
     }
   }
   return false;
 }
 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");
 }
예제 #4
0
 /**
  * Compares the bundles.
  *
  * @param other the other external identifier, not null
  * @return negative if this is less, zero if equal, positive if greater
  */
 @Override
 public int compareTo(final ExternalIdBundle other) {
   final Set<ExternalId> mySet = getExternalIds();
   final Set<ExternalId> otherSet = other.getExternalIds();
   if (mySet.size() < otherSet.size()) {
     return -1;
   }
   if (mySet.size() > otherSet.size()) {
     return 1;
   }
   final List<ExternalId> myList = new ArrayList<ExternalId>(mySet); // already sorted
   final List<ExternalId> otherList = new ArrayList<ExternalId>(otherSet); // already sorted
   for (int i = 0; i < myList.size(); i++) {
     final int c = myList.get(i).compareTo(otherList.get(i));
     if (c != 0) {
       return c;
     }
   }
   return 0;
 }
 private DoubleTimeSeries<ZonedDateTime> getIndexTimeSeries(
     final SwapLeg leg,
     final ZonedDateTime swapEffectiveDate,
     final ZonedDateTime now,
     final boolean includeEndDate,
     final HistoricalTimeSeriesBundle timeSeries) {
   if (leg instanceof FloatingInterestRateLeg) {
     final FloatingInterestRateLeg floatingLeg = (FloatingInterestRateLeg) leg;
     final ExternalIdBundle id = getIndexIdForSwap(floatingLeg);
     // Implementation note: To catch first fixing. SwapSecurity does not have this date.
     if (now.isBefore(swapEffectiveDate)) { // TODO: review if this is the correct condition
       return ArrayZonedDateTimeDoubleTimeSeries.EMPTY_SERIES;
     }
     final HistoricalTimeSeries ts = timeSeries.get(MarketDataRequirementNames.MARKET_VALUE, id);
     if (ts == null) {
       throw new OpenGammaRuntimeException(
           "Could not get time series of underlying index "
               + id.getExternalIds().toString()
               + " bundle used was "
               + id);
     }
     if (ts.getTimeSeries().isEmpty()) {
       return ArrayZonedDateTimeDoubleTimeSeries.EMPTY_SERIES;
     }
     final FastBackedDoubleTimeSeries<LocalDate> localDateTS = ts.getTimeSeries();
     final FastLongDoubleTimeSeries convertedTS =
         localDateTS.toFastLongDoubleTimeSeries(DateTimeNumericEncoding.TIME_EPOCH_MILLIS);
     final LocalTime fixingTime =
         LocalTime.of(
             0,
             0); // FIXME CASE Converting a daily historical time series to an arbitrary time. Bad
                 // idea
     return new ArrayZonedDateTimeDoubleTimeSeries(
         new ZonedDateTimeEpochMillisConverter(now.getZone(), fixingTime), convertedTS);
   }
   return null;
 }
 /**
  * Returns the time series to be used in the toDerivative method.
  *
  * @param id The ExternalId bundle.
  * @param startDate The time series start date (included in the time series).
  * @param timeZone The time zone to use for the returned series
  * @param dataSource The time series data source.
  * @return The time series.
  */
 private DoubleTimeSeries<ZonedDateTime> getIndexTimeSeries(
     final ExternalIdBundle id,
     final TimeZone timeZone,
     final HistoricalTimeSeriesBundle timeSeries) {
   final HistoricalTimeSeries ts = timeSeries.get(MarketDataRequirementNames.MARKET_VALUE, id);
   // Implementation note: the normalization take place in the getHistoricalTimeSeries
   if (ts == null) {
     throw new OpenGammaRuntimeException(
         "Could not get time series of underlying index " + id.getExternalIds().toString());
   }
   if (ts.getTimeSeries().isEmpty()) {
     return ArrayZonedDateTimeDoubleTimeSeries.EMPTY_SERIES;
   }
   final FastBackedDoubleTimeSeries<LocalDate> localDateTS = ts.getTimeSeries();
   final FastLongDoubleTimeSeries convertedTS =
       localDateTS.toFastLongDoubleTimeSeries(DateTimeNumericEncoding.TIME_EPOCH_MILLIS);
   final LocalTime fixingTime =
       LocalTime.of(
           0,
           0); // FIXME CASE Converting a daily historical time series to an arbitrary time. Bad
               // idea
   return new ArrayZonedDateTimeDoubleTimeSeries(
       new ZonedDateTimeEpochMillisConverter(timeZone, fixingTime), convertedTS);
 }