Package com.opengamma.core.historicaltimeseries

Examples of com.opengamma.core.historicaltimeseries.HistoricalTimeSeries


    List<Pair<HistoricalTimeSeriesInfoDocument, HistoricalTimeSeries>> previousSeriesDocs = addTimeSeries();
    htsMasterUpdater.run();
    for (Pair<HistoricalTimeSeriesInfoDocument, HistoricalTimeSeries> previous : previousSeriesDocs) {
      HistoricalTimeSeriesInfoDocument currentDoc = htsMaster.get(previous.getFirst().getObjectId(), VersionCorrection.LATEST);
      assertEquals(previous.getFirst().getUniqueId(), currentDoc.getUniqueId())// document not changed
      HistoricalTimeSeries currentSeries = htsMaster.getTimeSeries(previous.getSecond().getUniqueId(), VersionCorrection.LATEST);
      assertNotNull(currentSeries);
      //will update only for Bloomberg dataSource
      if (previous.getFirst().getInfo().getDataSource().equals(BLOOMBERG_DATA_SOURCE_NAME)) {
        assertEquals(previousWeekDay(), currentSeries.getTimeSeries().getLatestTime());
        LocalDateDoubleTimeSeries previousSeries = previous.getSecond().getTimeSeries();
        final LocalDate previousStart = previousSeries.getEarliestTime();
        final LocalDate previousEnd = previousSeries.getLatestTime();
        assertEquals(previousSeries, currentSeries.getTimeSeries().subSeries(previousStart, true, previousEnd, true));
      } else {
        assertEquals(previous.getSecond().getTimeSeries(), currentSeries.getTimeSeries());
      }
    }
  }
View Full Code Here


   
    htsMasterUpdater.setStartDate(startDate);
    htsMasterUpdater.setEndDate(endDate);
    htsMasterUpdater.run();
    for (Pair<HistoricalTimeSeriesInfoDocument, HistoricalTimeSeries> previous : previousSeriesDocs) {
      HistoricalTimeSeries currentSeries = htsMaster.getTimeSeries(previous.getSecond().getUniqueId(), VersionCorrection.LATEST);
      assertNotNull(currentSeries);
      //will update only for Bloomberg dataSource
      if (previous.getFirst().getInfo().getDataSource().equals(BLOOMBERG_DATA_SOURCE_NAME)) {
        assertEquals(endDate, currentSeries.getTimeSeries().getLatestTime());
        LocalDateDoubleTimeSeries previousSeries = previous.getSecond().getTimeSeries();
        final LocalDate previousStart = previousSeries.getEarliestTime();
        final LocalDate previousEnd = previousSeries.getLatestTime();
        assertEquals(previousSeries, currentSeries.getTimeSeries().subSeries(previousStart, true, previousEnd, true));
      } else {
        assertEquals(previous.getSecond().getTimeSeries().getLatestTime(), currentSeries.getTimeSeries().getLatestTime());
      }
    }
  }
View Full Code Here

    //sleep for 1sec because of nano sec accuracy lost in the database
    Thread.sleep(1000);
    htsMasterUpdater.setReload(true);
    htsMasterUpdater.run();
    for (Pair<HistoricalTimeSeriesInfoDocument, HistoricalTimeSeries> previous : previousDocs) {
      HistoricalTimeSeries currentSeries = htsMaster.getTimeSeries(previous.getSecond().getUniqueId(), VersionCorrection.LATEST);
      assertNotNull(currentSeries);
      // after reload time series start date should be same, because the test provider returns
      // time-series with previous start date, but this may be different in production
      assertEquals(previous.getSecond().getTimeSeries().getEarliestTime(), currentSeries.getTimeSeries().getEarliestTime());
      // will reload only for Bloomberg dataSource
      if (previous.getFirst().getInfo().getDataSource().equals(BLOOMBERG_DATA_SOURCE_NAME)) {
        assertTrue(!previous.getSecond().getTimeSeries().equals(currentSeries.getTimeSeries()));
      } else {
        assertEquals(previous.getSecond().getTimeSeries(), currentSeries.getTimeSeries());
      }
    }
  }
View Full Code Here

      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 ImmutableZonedDateTimeDoubleTimeSeries.ofEmpty(now.getZone());
      }
      final HistoricalTimeSeries ts = timeSeries.get(MarketDataRequirementNames.MARKET_VALUE, id);
      if (ts == null) {
        s_logger.info("Could not get time series of underlying index " + id.getExternalIds().toString() + " bundle used was " + id);
        return ImmutableZonedDateTimeDoubleTimeSeries.ofEmpty(now.getZone());
      }
      if (ts.getTimeSeries().isEmpty()) {
        return ImmutableZonedDateTimeDoubleTimeSeries.ofEmpty(now.getZone());
      }
      LocalDateDoubleTimeSeries localDateTS = ts.getTimeSeries();
      //TODO remove me when KWCDC Curncy is normalised correctly
      if (localDateTS.getLatestValue() > 0.50) {
        localDateTS = localDateTS.divide(100);
      }
      return convertTimeSeries(now.getZone(), localDateTS);
    } else if (leg instanceof InflationIndexSwapLeg) {
      final InflationIndexSwapLeg indexLeg = (InflationIndexSwapLeg) leg;
      final ExternalIdBundle id = getIndexIdForInflationSwap(indexLeg);
      // 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 ImmutableZonedDateTimeDoubleTimeSeries.ofEmpty(now.getZone());
      }
      final HistoricalTimeSeries ts = timeSeries.get(MarketDataRequirementNames.MARKET_VALUE, id);
      if (ts == null) {
        s_logger.info("Could not get time series of underlying index " + id.getExternalIds().toString() + " bundle used was " + id);
        return ImmutableZonedDateTimeDoubleTimeSeries.ofEmpty(now.getZone());
      }
      if (ts.getTimeSeries().isEmpty()) {
        return ImmutableZonedDateTimeDoubleTimeSeries.ofEmpty(now.getZone());
      }
      LocalDateDoubleTimeSeries localDateTS = ts.getTimeSeries();
      //TODO remove me when KWCDC Curncy is normalised correctly
      if (localDateTS.getLatestValue() > 0.50) {
        localDateTS = localDateTS.divide(100);
      }
      return convertTimeSeries(now.getZone(), localDateTS);
View Full Code Here

   * @param timeZone The time zone to use for the returned series
   * @param dataSource The time series data source.
   * @return The time series.
   */
  private static ZonedDateTimeDoubleTimeSeries getIndexTimeSeries(final ExternalIdBundle id, final ZoneId 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 ImmutableZonedDateTimeDoubleTimeSeries.ofEmpty(timeZone);
    }
    return convertTimeSeries(timeZone, ts.getTimeSeries());
  }
View Full Code Here

    BloombergHistoricalTimeSeriesLoader loader = getLoader();
   
    List<Pair<HistoricalTimeSeriesInfoDocument, HistoricalTimeSeries>> previousSeriesDocs = addTimeSeries();
    assertNotNull(previousSeriesDocs);
    assertFalse(previousSeriesDocs.isEmpty());
    HistoricalTimeSeries previousHts = htsMaster.getTimeSeries(previousSeriesDocs.get(0).getSecond().getUniqueId());
    previousHts.getUniqueId();
    assertTrue(loader.updateTimeSeries(previousHts.getUniqueId()));
    HistoricalTimeSeries updatedTS = htsMaster.getTimeSeries(previousHts.getUniqueId(), VersionCorrection.LATEST);
    assertTrue(!previousHts.getUniqueId().equals(updatedTS.getUniqueId()));
    assertTrue(!previousHts.getTimeSeries().equals(updatedTS.getTimeSeries()));
  }
View Full Code Here

    if (tsIterator == null) {
      throw new OpenGammaRuntimeException("No nodal market data time-series available");
    }
    for (int t = 0; t < tenors.length; t++) {
      final Tenor tenor = tenors[t];
      final HistoricalTimeSeries dbNodeTimeSeries = tsIterator.next();
      if (dbNodeTimeSeries == null) {
        throw new OpenGammaRuntimeException("No time-series for strip with tenor " + tenor);
      }
      final LocalDateDoubleTimeSeries nodeTimeSeries = samplingFunction.getSampledTimeSeries(dbNodeTimeSeries.getTimeSeries(), schedule);
      LocalDateDoubleTimeSeries returnSeries = getReturnSeries(nodeTimeSeries, desiredValue);

      // Clip the time-series to the range originally asked for
      returnSeries = returnSeries.subSeries(startDate, includeStart, returnSeries.getLatestTime(), true);
View Full Code Here

          }
        } else {
          throw new OpenGammaRuntimeException("Unexpected convention on inflation leg, expected an inflation leg convention");
        }

        final HistoricalTimeSeries historicalTimeSeries = timeSeries.get(node.getDataField(), priceIndexId);
        if (historicalTimeSeries == null) {
          throw new OpenGammaRuntimeException("Could not get price time series for " + priceIndexId);
        }
        final DoubleTimeSeries<?> ts = historicalTimeSeries.getTimeSeries();
        if (ts == null) {
          throw new OpenGammaRuntimeException("Could not get price time series for " + priceIndexId);
        }
        final int length = ts.size();
        if (length == 0) {
          throw new OpenGammaRuntimeException("Price time series for " + priceIndexId + " was empty");
        }
        final ZonedDateTimeDoubleTimeSeries multiply = convertTimeSeries(ZoneId.of("UTC"), (LocalDateDoubleTimeSeries) ts.multiply(100));
        return ((InstrumentDefinitionWithData<?, ZonedDateTimeDoubleTimeSeries[]>) definition).toDerivative(
            now,
            new ZonedDateTimeDoubleTimeSeries[] {multiply, multiply});
      }
      if (node.getCurveNode() instanceof RateFutureNode || node.getCurveNode() instanceof DeliverableSwapFutureNode) {
        ArgumentChecker.notNull(timeSeries, "time series");
        final ExternalId id = node.getIdentifier();
        final HistoricalTimeSeries historicalTimeSeries = timeSeries.get(node.getDataField(), id);
        if (historicalTimeSeries == null) {
          if (node.getCurveNode() instanceof DeliverableSwapFutureNode) {
            final double lastMarginPrice = 0.99;
            return ((InstrumentDefinitionWithData<?, Double>) definition).toDerivative(now, lastMarginPrice);
          }
          throw new OpenGammaRuntimeException("Could not get price time series for " + id);
        }
        final DoubleTimeSeries<?> ts = historicalTimeSeries.getTimeSeries();
        if (ts == null) {
          throw new OpenGammaRuntimeException("Could not get price time series for " + id);
        }
        final int length = ts.size();
        if (length == 0) {
          throw new OpenGammaRuntimeException("Price time series for " + id + " was empty");
        }
        if (definition instanceof FederalFundsFutureTransactionDefinition) {
          final DoubleTimeSeries<ZonedDateTime>[] tsArray = new DoubleTimeSeries[2];
          tsArray[0] = convertTimeSeries(now.getZone(), historicalTimeSeries.getTimeSeries());
          return ((InstrumentDefinitionWithData<?, DoubleTimeSeries<ZonedDateTime>[]>) definition).toDerivative(now, tsArray); //CSIGNORE
        }
        final double lastMarginPrice = ts.getLatestValue();
        return ((InstrumentDefinitionWithData<?, Double>) definition).toDerivative(now, lastMarginPrice);
      }
View Full Code Here

    final boolean includeEnd = HistoricalTimeSeriesFunctionUtils.parseBoolean(desiredValue.getConstraint(HistoricalTimeSeriesFunctionUtils.INCLUDE_END_PROPERTY));
    final HistoricalTimeSeriesBundle bundle = new HistoricalTimeSeriesBundle();
    final Set<CurveNodeWithIdentifier> nodes = curveSpecification.getNodes();
    for (final CurveNodeWithIdentifier node : nodes) {
      final ExternalIdBundle identifier = ExternalIdBundle.of(node.getIdentifier());
      final HistoricalTimeSeries timeSeries = timeSeriesSource.getHistoricalTimeSeries(dataField, identifier, resolutionKey, startDate, includeStart, endDate, includeEnd);
      if (timeSeries != null) {
        bundle.add(dataField, identifier, timeSeries);
      } else {
        s_logger.warn("Could not get time series for {}", identifier);
      }
View Full Code Here

    Map<ExternalIdBundle, LocalDateDoubleTimeSeries> map = _provider.getHistoricalTimeSeries(externalIdBundles, dataSource, dataProvider, dataField, dateRange);
    Map<ExternalIdBundle, HistoricalTimeSeries> result = Maps.newHashMap();
    for (ExternalIdBundle bundle : map.keySet()) {
      LocalDateDoubleTimeSeries ts = map.get(bundle);
      HistoricalTimeSeries hts = null;
      if (ts != null) {
        hts = new SimpleHistoricalTimeSeries(_uniqueIdSupplier.get(), ts);
      }
      result.put(bundle, 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.