Package com.opengamma.core.historicaltimeseries

Examples of com.opengamma.core.historicaltimeseries.HistoricalTimeSeries


  }
 
  public void getLatestDataPoint() {
    NonVersionedRedisHistoricalTimeSeriesSource htsSource = new NonVersionedRedisHistoricalTimeSeriesSource(getJedisPool(), getRedisPrefix());
    UniqueId id = UniqueId.of("Test", "1");
    HistoricalTimeSeries hts = htsSource.getHistoricalTimeSeries(id);
    assertNull(hts);
   
    LocalDateDoubleTimeSeriesBuilder tsBuilder = ImmutableLocalDateDoubleTimeSeries.builder();
    tsBuilder.put(LocalDate.parse("2013-06-04"), 14.0);
    tsBuilder.put(LocalDate.parse("2013-06-05"), 15.0);
    tsBuilder.put(LocalDate.parse("2013-06-06"), 16.0);
    tsBuilder.put(LocalDate.parse("2013-06-07"), 17.0);
    tsBuilder.put(LocalDate.parse("2013-06-08"), 18.0);
    tsBuilder.put(LocalDate.parse("2013-06-09"), 24.0);
    tsBuilder.put(LocalDate.parse("2013-06-10"), 25.0);
    tsBuilder.put(LocalDate.parse("2013-06-11"), 26.0);
    tsBuilder.put(LocalDate.parse("2013-06-12"), 27.0);
    tsBuilder.put(LocalDate.parse("2013-06-13"), 28.0);
    tsBuilder.put(LocalDate.parse("2013-06-14"), 34.0);
    tsBuilder.put(LocalDate.parse("2013-06-15"), 35.0);
    tsBuilder.put(LocalDate.parse("2013-06-16"), 36.0);
    tsBuilder.put(LocalDate.parse("2013-06-17"), 37.0);
    tsBuilder.put(LocalDate.parse("2013-06-18"), 38.0);
   
    htsSource.updateTimeSeries(id, tsBuilder.build());
   
    hts = htsSource.getHistoricalTimeSeries(id);
    assertNotNull(hts);
    assertEquals(id, hts.getUniqueId());
   
    LocalDateDoubleTimeSeries ts = hts.getTimeSeries();
    assertEquals(15, ts.size());
    assertEquals(14.0, ts.getValue(LocalDate.parse("2013-06-04")), 0.00001);
    assertEquals(15.0, ts.getValue(LocalDate.parse("2013-06-05")), 0.00001);
    assertEquals(16.0, ts.getValue(LocalDate.parse("2013-06-06")), 0.00001);
    assertEquals(17.0, ts.getValue(LocalDate.parse("2013-06-07")), 0.00001);
View Full Code Here


   * Test how fast we can add large historical timeseries adding one data point at a time.
   */
  @Test(enabled = false)
  public void largePerformanceTestOneDataPoint() {
    NonVersionedRedisHistoricalTimeSeriesSource source = new NonVersionedRedisHistoricalTimeSeriesSource(getJedisPool(), getRedisPrefix());
    HistoricalTimeSeries hts = createSampleHts();
    long start = System.nanoTime();
    LocalDateDoubleTimeSeries timeSeries = hts.getTimeSeries();
    for (Entry<LocalDate, Double> entry : timeSeries) {
      source.updateTimeSeriesPoint(hts.getUniqueId(), entry.getKey(), entry.getValue());
    }
    long end = System.nanoTime();
    double durationInSec = ((double) (end - start)) / 1e9;
    System.out.println("Adding " + hts.getTimeSeries().size() + " datapoints took " + durationInSec + " sec");
    HistoricalTimeSeries storedHts = source.getHistoricalTimeSeries(hts.getUniqueId());
    assertNotNull(storedHts);
    assertEquals(hts.getUniqueId(), storedHts.getUniqueId());
    assertEquals(hts.getTimeSeries(), storedHts.getTimeSeries());
  }
View Full Code Here

   */
  @Test(enabled = false)
  public void largePerformanceTestBulkInsert() {
    NonVersionedRedisHistoricalTimeSeriesSource source = new NonVersionedRedisHistoricalTimeSeriesSource(getJedisPool(), getRedisPrefix());
    double totalDurationInSec = 0.0;
    HistoricalTimeSeries hts = null;
    for (int i = 0; i < ITER_SIZE; i++) {
      hts = createSampleHts();
      long start = System.nanoTime();
      source.updateTimeSeries(hts.getUniqueId(), hts.getTimeSeries());
      totalDurationInSec  += ((double) (System.nanoTime() - start)) / 1e9;
      HistoricalTimeSeries storedHts = source.getHistoricalTimeSeries(hts.getUniqueId());
      assertNotNull(storedHts);
      assertEquals(hts.getUniqueId(), storedHts.getUniqueId());
      assertEquals(hts.getTimeSeries(), storedHts.getTimeSeries());
    }
    System.out.println("Adding " + hts.getTimeSeries().size() + " datapoints took " + totalDurationInSec/ITER_SIZE + " sec");
  }
View Full Code Here

  }
 
  @Test(enabled = false)
  public void largePerformanceTestRead() {
    NonVersionedRedisHistoricalTimeSeriesSource source = new NonVersionedRedisHistoricalTimeSeriesSource(getJedisPool(), getRedisPrefix());
    HistoricalTimeSeries hts = null;
    double totalDurationInSec = 0.0;
    for (int i = 0; i < ITER_SIZE; i++) {
      hts = createSampleHts();
      source.updateTimeSeries(hts.getUniqueId(), hts.getTimeSeries());
      long start = System.nanoTime();
      HistoricalTimeSeries storedHts = source.getHistoricalTimeSeries(hts.getUniqueId());
      totalDurationInSec += ((double) (System.nanoTime() - start)) / 1e9;
      assertNotNull(storedHts);
      assertEquals(hts.getUniqueId(), storedHts.getUniqueId());
      assertEquals(hts.getTimeSeries(), storedHts.getTimeSeries());
    }
    System.out.println("Reading " + hts.getTimeSeries().size() + " datapoints took " + totalDurationInSec/ITER_SIZE + " sec");
  }
View Full Code Here

      final ComputationTargetSpecification targetSpec, final ValueRequirement desiredValue) {
    final LocalDate startDate = DateConstraint.evaluate(executionContext, desiredValue.getConstraint(HistoricalTimeSeriesFunctionUtils.START_DATE_PROPERTY));
    final boolean includeStart = HistoricalTimeSeriesFunctionUtils.parseBoolean(desiredValue.getConstraint(HistoricalTimeSeriesFunctionUtils.INCLUDE_START_PROPERTY));
    LocalDate endDate = DateConstraint.evaluate(executionContext, desiredValue.getConstraint(HistoricalTimeSeriesFunctionUtils.END_DATE_PROPERTY));
    final boolean includeEnd = HistoricalTimeSeriesFunctionUtils.parseBoolean(desiredValue.getConstraint(HistoricalTimeSeriesFunctionUtils.INCLUDE_END_PROPERTY));
    HistoricalTimeSeries hts = timeSeriesSource.getHistoricalTimeSeries(targetSpec.getUniqueId(), startDate, includeStart, endDate, includeEnd);
    final String adjusterString = desiredValue.getConstraint(HistoricalTimeSeriesFunctionUtils.ADJUST_PROPERTY);
    hts = HistoricalTimeSeriesAdjustment.parse(adjusterString).adjust(hts);
    return hts;
  }
View Full Code Here

    final HistoricalTimeSeriesSource timeSeriesSource = OpenGammaExecutionContext.getHistoricalTimeSeriesSource(executionContext);
    final HistoricalTimeSeriesBundle bundle = new HistoricalTimeSeriesBundle();
    for (final ComputedValue input : inputs.getAllValues()) {
      if (ValueRequirementNames.HISTORICAL_TIME_SERIES.equals(input.getSpecification().getValueName())) {
        final String fieldName = input.getSpecification().getProperty(DATA_FIELD_PROPERTY);
        final HistoricalTimeSeries hts = (HistoricalTimeSeries) input.getValue();
        final ExternalIdBundle ids = timeSeriesSource.getExternalIdBundle(hts.getUniqueId());
        if (fieldName == null) {
          // Default to MARKET_VALUE in the bundle; this is not probably correct but this shouldn't happen for well written functions
          bundle.add(MarketDataRequirementNames.MARKET_VALUE, ids, hts);
        } else {
          bundle.add(fieldName, ids, hts);
View Full Code Here

      return null;
    }
    // look up the rate timeseries identifier out of the bundle
    final ExternalId tsIdentifier = getTimeSeriesIdentifier(liborConvention);
    // look up the value on our chosen trade date
    final HistoricalTimeSeries initialRateSeries = getHistoricalSource().getHistoricalTimeSeries(MarketDataRequirementNames.MARKET_VALUE, tsIdentifier.toBundle(), null, tradeDate,
        true, tradeDate, true);
    if (initialRateSeries == null || initialRateSeries.getTimeSeries().isEmpty()) {
      s_logger.error("couldn't get series for {} on {}", tsIdentifier, tradeDate);
      return null;
    }
    Double initialRate = initialRateSeries.getTimeSeries().getEarliestValue();
    // get the identifier for the swap rate for the maturity we're interested in (assuming the fixed rate will be =~ swap rate)
    final ExternalId swapRateForMaturityIdentifier = getSwapRateFor(ccy, tradeDate, maturity);
    if (swapRateForMaturityIdentifier == null) {
      s_logger.error("Couldn't get swap rate identifier for {} [{}] from {}", new Object[] {ccy, maturity, tradeDate });
      return null;
    }
    final HistoricalTimeSeries fixedRateSeries = getHistoricalSource().getHistoricalTimeSeries(MarketDataRequirementNames.MARKET_VALUE, swapRateForMaturityIdentifier.toBundle(),
        null, tradeDate, true,
        tradeDate, true);
    if (fixedRateSeries == null) {
      s_logger.error("can't find time series for {} on {}", swapRateForMaturityIdentifier, tradeDate);
      return null;
    }
    Double fixedRate = (fixedRateSeries.getTimeSeries().getEarliestValue() + getRandom().nextDouble()) / 100d;
    Double notional = (double) (getRandom(99999) + 1) * 1000;
    ZonedDateTime tradeDateTime = tradeDate.atStartOfDay(ZoneOffset.UTC);
    ZonedDateTime maturityDateTime = tradeDate.plus(maturity.getPeriod()).atStartOfDay(ZoneOffset.UTC);
    String counterparty = "CParty";
    SwapLeg fixedLeg = new FixedInterestRateLeg(swapConvention.getSwapFixedLegDayCount(),
View Full Code Here

    final ExternalId swapRateForMaturityIdentifier = getSwapRateFor(configSource, ccy, tradeDate, maturity);
    if (swapRateForMaturityIdentifier == null) {
      throw new OpenGammaRuntimeException("Couldn't get swap rate identifier for " + ccy + " [" + maturity + "]" + " from " + tradeDate);
    }

    final HistoricalTimeSeries fixedRateSeries = historicalSource.getHistoricalTimeSeries("PX_LAST",
        swapRateForMaturityIdentifier.toBundle(), HistoricalTimeSeriesRatingFieldNames.DEFAULT_CONFIG_NAME, tradeDate.minusDays(30), true, tradeDate, true);
    if (fixedRateSeries == null) {
      throw new OpenGammaRuntimeException("can't find time series for " + swapRateForMaturityIdentifier + " on " + tradeDate);
    }
    final Double fixedRate = (fixedRateSeries.getTimeSeries().getLatestValue() + random.nextDouble()) / 100d;
    return fixedRate;
  }
View Full Code Here

    return fixedRate;
  }

  private Double getInitialRate(final LocalDate tradeDate, final ExternalId liborIdentifier) {
    final HistoricalTimeSeriesSource historicalSource = getToolContext().getHistoricalTimeSeriesSource();
    final HistoricalTimeSeries initialRateSeries = historicalSource.getHistoricalTimeSeries(
      "PX_LAST", liborIdentifier.toBundle(),
      HistoricalTimeSeriesRatingFieldNames.DEFAULT_CONFIG_NAME, tradeDate.minusDays(30), true, tradeDate, true);
    if (initialRateSeries == null || initialRateSeries.getTimeSeries().isEmpty()) {
      throw new OpenGammaRuntimeException("couldn't get series for " + liborIdentifier);
    }
    return initialRateSeries.getTimeSeries().getLatestValue();
  }
View Full Code Here

    } catch (Exception ex) {
      s_logger.warn("Unable to obtain underlying id for " + currency + " " + start.toLocalDate() + " " + tenor, ex);
      return null;
    }
   
    final HistoricalTimeSeries underlyingSeries = getHistoricalSource().getHistoricalTimeSeries(MarketDataRequirementNames.MARKET_VALUE, underlyingIdentifier.toBundle(), null, start.toLocalDate(),
        true, start.toLocalDate(), true);
    if ((underlyingSeries == null) || underlyingSeries.getTimeSeries().isEmpty()) {
      return null;
    }
    final double rate = underlyingSeries.getTimeSeries().getEarliestValue() * getRandom(0.5, 1.5);
    final double amount = 10000 * (getRandom(1500) + 200);
    final FRASecurity security = new FRASecurity(currency, region, start, maturity, rate, amount, underlyingIdentifier, fixingDate);
    security.setName(createName(currency, amount, rate, maturity));
    return security;
  }
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.