public interface LocalDateDoubleTimeSeries
double values.
A time-series is similar to both a SortedMap of value keyed
by date-time and a List of date-time to value pairs. As such,
the date/times do not have to be evenly spread over time within the series.
The distribution of the data will influence which implementation is most appropriate.
Implementations must be immutable and thread-safe beans.
Note that Double.NaN is used internally as a sentinel
value and is therefore not allowed as a value.
| Modifier and Type | Method and Description |
|---|---|
static LocalDateDoubleTimeSeriesBuilder |
builder()
Creates an empty builder, used to create time-series.
|
static Collector<LocalDateDoublePoint,LocalDateDoubleTimeSeriesBuilder,LocalDateDoubleTimeSeries> |
collector()
Returns a collector that can be used to create a time-series from a stream of points.
|
boolean |
containsDate(LocalDate date)
Checks if this time-series contains a value for the specified date.
|
Stream<LocalDate> |
dates()
Returns a stream over the dates of this time-series.
|
static LocalDateDoubleTimeSeries |
empty()
Returns an empty time-series.
|
LocalDateDoubleTimeSeries |
filter(ObjDoublePredicate<LocalDate> predicate)
Create a new time-series by filtering this one.
|
void |
forEach(ObjDoubleConsumer<LocalDate> action)
Applies an action to each pair in the time series.
|
OptionalDouble |
get(LocalDate date)
Gets the value associated with the specified date.
|
default LocalDate |
getEarliestDate()
Get the earliest date contained in this time-series.
|
default double |
getEarliestValue()
Get the value held for the earliest date contained in this time-series.
|
LocalDate |
getLatestDate()
Get the latest date contained in this time-series.
|
double |
getLatestValue()
Get the value held for the latest date contained in this time-series.
|
LocalDateDoubleTimeSeries |
headSeries(int numPoints)
Gets part of this series as a sub-series, choosing the earliest entries.
|
default LocalDateDoubleTimeSeries |
intersection(LocalDateDoubleTimeSeries other,
DoubleBinaryOperator mapper)
Obtains the intersection of a pair of time series.
|
boolean |
isEmpty()
Indicates if this time-series is empty.
|
LocalDateDoubleTimeSeries |
mapDates(Function<? super LocalDate,? extends LocalDate> mapper)
Applies an operation to each date in the time series which creates a new date, returning a new time series
with the new dates and the points from this time series.
|
LocalDateDoubleTimeSeries |
mapValues(DoubleUnaryOperator mapper)
Applies an operation to each value in the time series.
|
static LocalDateDoubleTimeSeries |
of(LocalDate date,
double value)
Obtains a time-series containing a single date and value.
|
default Pair<LocalDateDoubleTimeSeries,LocalDateDoubleTimeSeries> |
partition(ObjDoublePredicate<LocalDate> predicate)
Partition the time-series into a pair of distinct series using a predicate.
|
default Pair<LocalDateDoubleTimeSeries,LocalDateDoubleTimeSeries> |
partitionByValue(DoublePredicate predicate)
Partition the time-series into a pair of distinct series using a predicate.
|
int |
size()
Return the size of this time-series.
|
Stream<LocalDateDoublePoint> |
stream()
Returns a stream over the points of this time-series.
|
LocalDateDoubleTimeSeries |
subSeries(LocalDate startInclusive,
LocalDate endExclusive)
Gets part of this series as a sub-series between two dates.
|
LocalDateDoubleTimeSeries |
tailSeries(int numPoints)
Gets part of this series as a sub-series, choosing the latest entries.
|
LocalDateDoubleTimeSeriesBuilder |
toBuilder()
Return a builder populated with the values from this series.
|
default LocalDateDoubleTimeSeries |
union(LocalDateDoubleTimeSeries other,
DoubleBinaryOperator mapper)
Obtains the union of a pair of time series.
|
DoubleStream |
values()
Returns a stream over the values of this time-series.
|
static LocalDateDoubleTimeSeries empty()
static LocalDateDoubleTimeSeries of(LocalDate date, double value)
date - the singleton datevalue - the singleton valuestatic LocalDateDoubleTimeSeriesBuilder builder()
The builder has methods to create and modify a time-series.
static Collector<LocalDateDoublePoint,LocalDateDoubleTimeSeriesBuilder,LocalDateDoubleTimeSeries> collector()
int size()
boolean isEmpty()
boolean containsDate(LocalDate date)
date - the date to check forOptionalDouble get(LocalDate date)
The result is an OptionalDouble which avoids the need to handle null
or exceptions. Use isPresent() to check whether the value is present.
Use orElse(double) to default a missing value.
date - the date to get the value fordefault LocalDate getEarliestDate()
If the time-series is empty then NoSuchElementException will be thrown.
NoSuchElementException - if the time-series is emptydefault double getEarliestValue()
If the time-series is empty then NoSuchElementException will be thrown.
NoSuchElementException - if the time-series is emptyLocalDate getLatestDate()
If the time-series is empty then NoSuchElementException will be thrown.
NoSuchElementException - if the time-series is emptydouble getLatestValue()
If the time-series is empty then NoSuchElementException will be thrown.
NoSuchElementException - if the time-series is emptyLocalDateDoubleTimeSeries subSeries(LocalDate startInclusive, LocalDate endExclusive)
The date-times do not have to match exactly. The sub-series contains all entries between the two dates using a half-open interval. The start date is included, the end date is excluded. The dates may be before or after the end of the time-series.
To obtain the series before a specific date, used LocalDate.MIN as the first argument.
To obtain the series from a specific date, used LocalDate.MAX as the second argument.
startInclusive - the start date, inclusiveendExclusive - the end date, exclusiveIllegalArgumentException - if the end is before the startLocalDateDoubleTimeSeries headSeries(int numPoints)
The sub-series contains the earliest part of the series up to the specified number of points. If the series contains less points than the number requested, the whole time-series is returned.
numPoints - the number of items to select, zero or greaterIllegalArgumentException - if the number of items is less than zeroLocalDateDoubleTimeSeries tailSeries(int numPoints)
The sub-series contains the latest part of the series up to the specified number of points. If the series contains less points than the number requested, the whole time-series is returned.
numPoints - the number of items to select, zero or greaterIllegalArgumentException - if the number of items is less than zeroStream<LocalDateDoublePoint> stream()
This provides access to the entire time-series.
Stream<LocalDate> dates()
This is most useful to summarize the dates in the stream, such as calculating the maximum or minimum date, or searching for a specific value.
DoubleStream values()
This is most useful to summarize the values in the stream, such as calculating the maximum, minimum or average value, or searching for a specific value.
void forEach(ObjDoubleConsumer<LocalDate> action)
This is generally used to apply a mathematical operation to the values. For example, the operator could multiply each value by a constant, or take the inverse.
base.forEach((date, value) -> System.out.println(date + "=" + value));
action - the action to be applied to each pairLocalDateDoubleTimeSeries mapDates(Function<? super LocalDate,? extends LocalDate> mapper)
This operation creates a new time series with the same data but the dates moved.
The operation must not change the dates in a way that reorders them. The mapped dates must be in ascending order or an exception is thrown.
updatedSeries = timeSeries.mapDates(date -> date.plusYears(1));
mapper - the operation applied to each date in the time seriesLocalDateDoubleTimeSeries mapValues(DoubleUnaryOperator mapper)
This is generally used to apply a mathematical operation to the values. For example, the operator could multiply each value by a constant, or take the inverse.
multiplied = base.mapValues(value -> value * 3);
mapper - the operator to be applied to the valuesLocalDateDoubleTimeSeries filter(ObjDoublePredicate<LocalDate> predicate)
The time-series can be filtered by both date and value.
Note that if filtering by date range is required, it is likely to be more efficient to
use subSeries(LocalDate, LocalDate) as that avoids traversal of the whole series.
predicate - the predicate to use to the filter the elements of the seriesdefault LocalDateDoubleTimeSeries intersection(LocalDateDoubleTimeSeries other, DoubleBinaryOperator mapper)
This returns a time-series with the intersection of the dates of the two inputs. The operator is invoked to combine the values.
other - the time-series to combine withmapper - the function to be used to combine the valuesdefault LocalDateDoubleTimeSeries union(LocalDateDoubleTimeSeries other, DoubleBinaryOperator mapper)
This returns a time-series with the union of the dates of the two inputs. When the same date occurs in both time-series, the operator is invoked to combine the values.
other - the time-series to combine withmapper - the function to be used to combine the valuesdefault Pair<LocalDateDoubleTimeSeries,LocalDateDoubleTimeSeries> partition(ObjDoublePredicate<LocalDate> predicate)
Points in the time-series which match the predicate will be put into the first series, whilst those points which do not match will be put into the second.
predicate - predicate used to test the points in the time-seriesPair containing two time-series. The first is a series
made of all the points in this series which match the predicate. The
second is a series made of the points which do not match.default Pair<LocalDateDoubleTimeSeries,LocalDateDoubleTimeSeries> partitionByValue(DoublePredicate predicate)
Points in the time-series whose values match the predicate will be put into the first series, whilst those points whose values do not match will be put into the second.
predicate - predicate used to test the points in the time-seriesPair containing two time-series. The first is a series
made of all the points in this series which match the predicate. The
second is a series made of the points which do not match.LocalDateDoubleTimeSeriesBuilder toBuilder()
This can be used to mutate the time-series.
Copyright 2009-Present by OpenGamma Inc. and individual contributors
Apache v2 licensed
Additional documentation can be found at strata.opengamma.io.