- All Known Implementing Classes:
TenorFromArray
,TimeDiscretizationFromArray
Interface to classes providing time discretization,
i.e. a map \( i \mapsto t_{i} \) for i = 0, 1, 2, ..., n.
Classes implementing this interface should provide convenient methods
to transform an index to a time and a time to an index.
- Version:
- 1.0
- Author:
- Christian Fries
-
Method Summary
Modifier and TypeMethodDescriptiondefault DoubleStream
Return a DoubleStream of this time discretization.default TimeDiscretization
filter(DoublePredicate timesToKeep)
Create a newTimeDiscretization
with a subset ofthis
time discretization.Return a clone of this time discretization asArrayList<Double>
.double[]
Return a clone of this time discretization asdouble[]
.default double
Returns the first time in the time discretization.default double
Returns the last time in the time discretization.int
int
double
Returns the smallest time span distinguishable in this time discretization.double
getTime(int timeIndex)
Returns the time for the given time index.int
getTimeIndex(double time)
Returns the time index for the given time.int
getTimeIndexNearestGreaterOrEqual(double time)
Returns the time index for the time in the time discretization which is the nearest to the given time, being greater or equal (i.e.int
getTimeIndexNearestLessOrEqual(double time)
Returns the time index for the time in the time discretization which is the nearest to the given time, being less or equal (i.e.getTimeShiftedTimeDiscretization(double timeShift)
Return a new time discretization where all time points have been shifted by a given time shift.double
getTimeStep(int timeIndex)
Returns the time step from the given time index to the next one.intersect(TimeDiscretization that)
Returns the intersection of this time discretization with another one.union(TimeDiscretization that)
Returns the union of this time discretization with another one.Methods inherited from interface java.lang.Iterable
forEach, iterator, spliterator
-
Method Details
-
getNumberOfTimes
int getNumberOfTimes()- Returns:
- Returns the number of time discretization points.
-
getNumberOfTimeSteps
int getNumberOfTimeSteps()- Returns:
- Returns the number of time steps (= number of discretization points-1).
-
getTime
double getTime(int timeIndex)Returns the time for the given time index.- Parameters:
timeIndex
- Time index- Returns:
- Returns the time for a given time index.
-
getTimeStep
double getTimeStep(int timeIndex)Returns the time step from the given time index to the next one.- Parameters:
timeIndex
- Time index- Returns:
- Returns the time step
-
getTimeIndex
int getTimeIndex(double time)Returns the time index for the given time. If the given time is not in the time discretization the method returns a negative number being (-insertionPoint-1).- Parameters:
time
- The time.- Returns:
- Returns the time index for a given time.
-
getTimeIndexNearestLessOrEqual
int getTimeIndexNearestLessOrEqual(double time)Returns the time index for the time in the time discretization which is the nearest to the given time, being less or equal (i.e. max(i : timeDiscretizationFromArray[i] ≤ time where timeDiscretizationFromArray[i] ≤ timeDiscretizationFromArray[j]) for i ≤ j.- Parameters:
time
- Given time.- Returns:
- Returns a time index or -1, if the given time is smaller than the this.getFirstTime().
-
getTimeIndexNearestGreaterOrEqual
int getTimeIndexNearestGreaterOrEqual(double time)Returns the time index for the time in the time discretization which is the nearest to the given time, being greater or equal (i.e. min(i : timeDiscretizationFromArray[i] ≥ time where timeDiscretizationFromArray[i] ≤ timeDiscretizationFromArray[j]) for i ≤ j.- Parameters:
time
- Given time.- Returns:
- Returns a time index or getNumberOfTimes(), if the given time is smaller than the this.getLastTime().
-
getFirstTime
default double getFirstTime()Returns the first time in the time discretization.- Returns:
- The first time in the time discretization.
-
getLastTime
default double getLastTime()Returns the last time in the time discretization.- Returns:
- The last time in the time discretization.
-
getAsDoubleArray
double[] getAsDoubleArray()Return a clone of this time discretization asdouble[]
.- Returns:
- The time discretization as
double[]
-
getAsArrayList
Return a clone of this time discretization asArrayList<Double>
. Note that this method is costly in terms of performance.- Returns:
- The time discretization as
ArrayList<Double>
-
doubleStream
Return a DoubleStream of this time discretization.- Returns:
- The time discretization as
DoubleStream
-
getTickSize
double getTickSize()Returns the smallest time span distinguishable in this time discretization.- Returns:
- A non-negative double containing the tick size.
-
filter
Create a newTimeDiscretization
with a subset ofthis
time discretization.- Parameters:
timesToKeep
- True if the time point should belong to the newTimeDiscretization
- Returns:
- A
TimeDiscretization
with a subset ofthis
time discretization.
-
union
Returns the union of this time discretization with another one. This means that the times of the other time discretization will be added. In case the tick sizes differ the union will have the smaller tick size, i. e. the finer precision. Note that when the differing tick sizes are not integer multiples of each other time points might get shifted due to rounding; for examplea.intersect(a.union(b))
might not be equal toa
.- Parameters:
that
- Another time discretization containing points to add to the time discretization.- Returns:
- A new time discretization containing both the time points of this and the other discretization.
-
intersect
Returns the intersection of this time discretization with another one. This means that all times not contained in the other time discretization will be removed. In case the tick sizes differ the intersection will have the greater tick size, i. e. the coarser precision. Note that when the differing tick sizes are not integer multiples of each other time points might get shifted due to rounding; for examplea.intersect(a.union(b))
might not be equal toa
.- Parameters:
that
- Another time discretization containing points to add to the time discretization.- Returns:
- A new time discretization containing both the time points of this and the other discretization.
-
getTimeShiftedTimeDiscretization
Return a new time discretization where all time points have been shifted by a given time shift.- Parameters:
timeShift
- A time shift applied to all discretization points.- Returns:
- A new time discretization where all time points have been shifted by the given time shift.
-