Package com.opengamma.core.historicaltimeseries

Examples of com.opengamma.core.historicaltimeseries.HistoricalTimeSeries


  //-------------------------------------------------------------------------
  public void getHistoricalTimeSeries_UniqueId() {
    LocalDate[] dates = {LocalDate.of(2011, 6, 30)};
    double[] values = {12.34d};
    ImmutableLocalDateDoubleTimeSeries timeSeries = ImmutableLocalDateDoubleTimeSeries.of(dates, values);
    HistoricalTimeSeries series = new SimpleHistoricalTimeSeries(UID, timeSeries);
   
    when(_underlyingSource.getHistoricalTimeSeries(UID)).thenReturn(series);
   
    // Fetching same series twice should return same result
    HistoricalTimeSeries series1 = _cachingSource.getHistoricalTimeSeries(UID);
    HistoricalTimeSeries series2 = _cachingSource.getHistoricalTimeSeries(UID);
    assertEquals(series, series1);
    assertEquals(series, series2);
    assertEquals(series1, series2);
   
    // underlying source should only have been called once if cache worked as expected
View Full Code Here


      @QueryParam("includeEnd") boolean includeEnd,
      @QueryParam("maxPoints") Integer maxPoints) {
    final UniqueId uniqueId = ObjectId.parse(idStr).atVersion(version);
    final LocalDate start = (startStr != null ? LocalDate.parse(startStr) : null);
    final LocalDate end = (endStr != null ? LocalDate.parse(endStr) : null);
    final HistoricalTimeSeries result;
    if (start == null && end == null && maxPoints == null) {
      result = getHistoricalTimeSeriesSource().getHistoricalTimeSeries(uniqueId);
    } else if (maxPoints != null) {
      result = getHistoricalTimeSeriesSource().getHistoricalTimeSeries(uniqueId, start, includeStart, end, includeEnd, maxPoints);
    } else {
View Full Code Here

      @QueryParam("includeEnd") boolean includeEnd,
      @QueryParam("maxPoints") Integer maxPoints) {
    final ExternalIdBundle bundle = ExternalIdBundle.parse(idStrs);
    final LocalDate start = (startStr != null ? LocalDate.parse(startStr) : null);
    final LocalDate end = (endStr != null ? LocalDate.parse(endStr) : null);
    final HistoricalTimeSeries result;
    if (idValidityDateStr != null) {
      final LocalDate idValidityDate = ("ALL".equals(idValidityDateStr) ? null : LocalDate.parse(idValidityDateStr));
      if (start == null && end == null && maxPoints == null) {
        result = getHistoricalTimeSeriesSource().getHistoricalTimeSeries(
            bundle, idValidityDate, dataSource, dataProvider, dataField);
View Full Code Here

      @QueryParam("includeEnd") boolean includeEnd,
      @QueryParam("maxPoints") Integer maxPoints) {
    final ExternalIdBundle bundle = ExternalIdBundle.parse(idStrs);
    final LocalDate start = (startStr != null ? LocalDate.parse(startStr) : null);
    final LocalDate end = (endStr != null ? LocalDate.parse(endStr) : null);
    final HistoricalTimeSeries result;
    if (idValidityDateStr != null) {
      final LocalDate idValidityDate = ("ALL".equals(idValidityDateStr) ? null : LocalDate.parse(idValidityDateStr));
      if (start == null && end == null && maxPoints == null) {
        result = getHistoricalTimeSeriesSource().getHistoricalTimeSeries(
            dataField, bundle, idValidityDate, resolutionKey);
View Full Code Here

  @Override
  public Pair<LocalDate, Double> getLatestDataPoint(UniqueId uniqueId, LocalDate start, boolean includeStart, LocalDate end, boolean includeEnd) {
    ArgumentChecker.notNull(uniqueId, "uniqueId");
   
    HistoricalTimeSeries hts = getHistoricalTimeSeries(uniqueId, start, includeStart, end, includeEnd);
    Pair<LocalDate, Double> latestPoint = null;
    if (hts != null && hts.getTimeSeries() != null) {
      latestPoint = Pair.of(hts.getTimeSeries().getLatestTime(), hts.getTimeSeries().getLatestValue());
    }
    return latestPoint;
  }
View Full Code Here

 
  protected HistoricalTimeSeries getHistoricalTimeSeries(ExternalIdBundle identifierBundle) {
    UniqueId uniqueId = toUniqueId(identifierBundle);
   
    LocalDateDoubleTimeSeries ts = getLocalDateDoubleTimeSeries(identifierBundle);
    HistoricalTimeSeries hts = new SimpleHistoricalTimeSeries(uniqueId, ts);
    return hts;
  }
View Full Code Here

      timeSeriesRequirements.addAll(requirements);
    }
    final HistoricalTimeSeriesBundle timeSeries = new HistoricalTimeSeriesBundle();
    final HistoricalTimeSeriesSource timeSeriesSource = OpenGammaExecutionContext.getHistoricalTimeSeriesSource(executionContext);
    for (ValueRequirement timeSeriesRequirement : timeSeriesRequirements) {
      final HistoricalTimeSeries hts = HistoricalTimeSeriesFunction.executeImpl(executionContext, timeSeriesSource,
          timeSeriesRequirement.getTargetReference().getSpecification(), timeSeriesRequirement);
      if (hts == null) {
        throw new OpenGammaRuntimeException("Can't get time series for " + timeSeriesRequirement);
      }
      timeSeries.add(timeSeriesRequirement.getConstraint(HistoricalTimeSeriesFunctionUtils.DATA_FIELD_PROPERTY), timeSeriesSource.getExternalIdBundle(hts.getUniqueId()), hts);
    }
    return Collections.singleton(new ComputedValue(new ValueSpecification(ValueRequirementNames.YIELD_CURVE_INSTRUMENT_CONVERSION_HISTORICAL_TIME_SERIES, target.toSpecification(), desiredValue
        .getConstraints()), timeSeries));
  }
View Full Code Here

        final HistoricalTimeSeriesBundle bundleForCurve = (HistoricalTimeSeriesBundle) inputs.getValue(bundleRequirement);
        final CurveSpecification curveSpec = (CurveSpecification) inputs.getValue(specRequirement);
        for (final CurveNodeWithIdentifier node : curveSpec.getNodes()) {
          String dataField = node.getDataField();
          ExternalIdBundle ids = ExternalIdBundle.of(node.getIdentifier());
          HistoricalTimeSeries ts = bundleForCurve.get(dataField, ids);
          if (ts != null) {
            bundle.add(dataField, ids, bundleForCurve.get(dataField, ids));
          } else {
            s_logger.info("Could not get historical time series for {}", ids);
          }
          if (node instanceof PointsCurveNodeWithIdentifier) {
            final PointsCurveNodeWithIdentifier pointsNode = (PointsCurveNodeWithIdentifier) node;
            dataField = pointsNode.getUnderlyingDataField();
            ids = ExternalIdBundle.of(pointsNode.getUnderlyingIdentifier());
            ts = bundleForCurve.get(dataField, ids);
            if (ts != null) {
              bundle.add(dataField, ids, bundleForCurve.get(dataField, ids));
            } else {
              s_logger.info("Could not get historical time series for {}", ids);
            }
          }
          if (node.getCurveNode() instanceof ZeroCouponInflationNode) {
            final ZeroCouponInflationNode inflationNode = (ZeroCouponInflationNode) node.getCurveNode();
            final ConventionSource conventionSource = OpenGammaExecutionContext.getConventionSource(executionContext);
            Convention convention = conventionSource.getConvention(inflationNode.getInflationLegConvention());
            if (convention == null) {
              throw new OpenGammaRuntimeException("Convention with id " + inflationNode.getInflationLegConvention() + " was null");
            }
            if (!(convention instanceof InflationLegConvention)) {
              throw new OpenGammaRuntimeException("Cannot handle convention type " + convention.getClass());
            }
            final InflationLegConvention inflationLegConvention = (InflationLegConvention) convention;
            convention = conventionSource.getConvention(inflationLegConvention.getPriceIndexConvention());
            if (convention == null) {
              throw new OpenGammaRuntimeException("Convention with id " + inflationLegConvention.getPriceIndexConvention() + " was null");
            }
            if (!(convention instanceof PriceIndexConvention)) {
              throw new OpenGammaRuntimeException("Cannot handle convention type " + convention.getClass());
            }
            ids = ExternalIdBundle.of(((PriceIndexConvention) convention).getPriceIndexId());
            final HistoricalTimeSeries priceIndexSeries = bundleForCurve.get(dataField, ids);
            if (priceIndexSeries != null) {
              if (priceIndexSeries.getTimeSeries().isEmpty()) {
                s_logger.info("Could for get historical time series for {}", ids);
              } else {
                bundle.add(dataField, ids, bundleForCurve.get(dataField, ids));
              }
            } else {
View Full Code Here

      final LocalDate date = LocalDate.parse(dateString);
      final Map<LocalDate, MultipleCurrencyAmount> cashFlows;
      if (inputs.getAllValues().isEmpty()) {
        cashFlows = NETTING_CASH_FLOW_CALCULATOR.getCashFlows(definition, date);
      } else {
        final HistoricalTimeSeries fixingSeries = (HistoricalTimeSeries) Iterables.getOnlyElement(inputs.getAllValues()).getValue();
        if (fixingSeries == null) {
          cashFlows = NETTING_CASH_FLOW_CALCULATOR.getCashFlows(definition, date);
        } else {
          cashFlows = NETTING_CASH_FLOW_CALCULATOR.getCashFlows(definition, fixingSeries.getTimeSeries(), date);
        }
      }
      final ValueProperties properties = createValueProperties().with(PROPERTY_DATE, dateString).get();
      return Collections.singleton(new ComputedValue(new ValueSpecification(ValueRequirementNames.NETTED_FIXED_CASH_FLOWS, target.toSpecification(), properties),
          new FixedPaymentMatrix(cashFlows)));
View Full Code Here

            Map<ExternalIdBundle, LocalDateDoubleTimeSeries> resultMap = _historicalTimeSeriesProvider.getHistoricalTimeSeries(
                Collections.singleton(bundleWithDates.toBundle()), BloombergConstants.BLOOMBERG_DATA_SOURCE_NAME, dataProvider, dataField, LocalDateRange.of(start, end, true));
            LocalDateDoubleTimeSeries timeSeries = resultMap.get(bundleWithDates.toBundle());
            UniqueId tsUid = _htsMaster.updateTimeSeriesDataPoints(added.getInfo().getTimeSeriesObjectId(), timeSeries);
           
            HistoricalTimeSeries hts = _htsMaster.getTimeSeries(tsUid);
            assertNotNull(hts);
            assertEquals(timeSeries, hts.getTimeSeries());
            result.add(Pair.of(added, hts));
          }
        }
      }
    }
View Full Code Here

TOP

Related Classes of com.opengamma.core.historicaltimeseries.HistoricalTimeSeries

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.