java.lang.Object
net.finmath.time.TimeDiscretizationFromArray
- All Implemented Interfaces:
Serializable
,Iterable<Double>
,TimeDiscretization
- Direct Known Subclasses:
TenorFromArray
This class represents a set of discrete points in time.
It handles the mapping from time indices to time points and back. It uses a time tick size ("quantum"). This is to make comparison of times safe. The default tick size is 1.0 / (365.0 * 24.0) (which corresponds to one hour if 1.0 is a non-leap-year): Times are rounded to the nearest multiple of 1.0 / (365.0 * 24.0). This property can be configured via a System.setProperty("net.finmath.functions.TimeDiscretization.timeTickSize"). Objects of this class are immutable.
It handles the mapping from time indices to time points and back. It uses a time tick size ("quantum"). This is to make comparison of times safe. The default tick size is 1.0 / (365.0 * 24.0) (which corresponds to one hour if 1.0 is a non-leap-year): Times are rounded to the nearest multiple of 1.0 / (365.0 * 24.0). This property can be configured via a System.setProperty("net.finmath.functions.TimeDiscretization.timeTickSize"). Objects of this class are immutable.
- Version:
- 1.6
- Author:
- Christian Fries
- See Also:
- Serialized Form
-
Nested Class Summary
Nested Classes -
Constructor Summary
ConstructorsConstructorDescriptionTimeDiscretizationFromArray(double... times)
Constructs a time discretization from a given set of doubles.TimeDiscretizationFromArray(double initial, double last, double deltaT, TimeDiscretizationFromArray.ShortPeriodLocation shortPeriodLocation)
Constructs an equi-distant time discretization with stub periods at start or end.TimeDiscretizationFromArray(double initial, int numberOfTimeSteps, double deltaT)
Constructs an equi-distant time discretization with points timeDiscretizationFromArray[i] beingfor(i=0; i ≤ timeSteps; i++) timeDiscretizationFromArray[i] = initial + i * deltaT;
TimeDiscretizationFromArray(Double[] times)
Constructs a time discretization from a given set of Doubles.TimeDiscretizationFromArray(Double[] times, double tickSize)
Constructs a time discretization using the given tick size.TimeDiscretizationFromArray(Iterable<Double> times)
Constructs a time discretization from an iterable of doubles.TimeDiscretizationFromArray(Iterable<Double> times, boolean allowDuplicates)
Constructs a time discretization from an iterable of doubles.TimeDiscretizationFromArray(Iterable<Double> times, double tickSize)
Constructs a time discretization using the given tick size.TimeDiscretizationFromArray(Iterable<Double> times, double tickSize, boolean allowDuplicates)
Constructs a time discretization using the given tick size.Constructs a time discretization from a (non closed and not necessarily sorted) stream of doubles.TimeDiscretizationFromArray(DoubleStream times, boolean allowDuplicates)
Constructs a time discretization from a (non closed and not necessarily sorted) stream of doubles.TimeDiscretizationFromArray(DoubleStream times, double tickSize)
Constructs a time discretization using the given tick size.TimeDiscretizationFromArray(DoubleStream times, double tickSize, boolean allowDuplicates)
Constructs a time discretization using the given tick size.TimeDiscretizationFromArray(Stream<Double> times)
Constructs a time discretization from a (non closed and not necessarily sorted) stream of boxed doubles.TimeDiscretizationFromArray(Stream<Double> times, double tickSize)
Constructs a time discretization using the given tick size.TimeDiscretizationFromArray(Stream<Double> times, double tickSize, boolean allowDuplicates)
Constructs a time discretization using the given tick size. -
Method Summary
Modifier and TypeMethodDescriptionboolean
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[]
.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.int
hashCode()
intersect(TimeDiscretization that)
Returns the intersection of this time discretization with another one.iterator()
toString()
union(TimeDiscretization that)
Returns the union of this time discretization with another one.Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
Methods inherited from interface net.finmath.time.TimeDiscretization
doubleStream, getFirstTime, getLastTime
-
Constructor Details
-
TimeDiscretizationFromArray
Constructs a time discretization using the given tick size. The time discretization will be sorted. Duplicate entries are allowed ifallowDuplicates
is true, otherwise duplicate entries are removed.- Parameters:
times
- A non closed and not necessarily sorted stream containing the time points.tickSize
- A non-negative double representing the smallest time span distinguishable.allowDuplicates
- If true, the time discretization allows duplicate entries.
-
TimeDiscretizationFromArray
Constructs a time discretization using the given tick size.- Parameters:
times
- A non closed and not necessarily sorted stream containing the time points.tickSize
- A non-negative double representing the smallest time span distinguishable.
-
TimeDiscretizationFromArray
Constructs a time discretization from a (non closed and not necessarily sorted) stream of doubles. The time discretization will be sorted. Duplicate entries are allowed ifallowDuplicates
is true, otherwise duplicate entries are removed.- Parameters:
times
- A double stream of time points for the time discretization.allowDuplicates
- If true, the time discretization allows duplicate entries.
-
TimeDiscretizationFromArray
Constructs a time discretization from a (non closed and not necessarily sorted) stream of doubles.- Parameters:
times
- A double stream of time points for the time discretization.
-
TimeDiscretizationFromArray
Constructs a time discretization using the given tick size.- Parameters:
times
- A non closed and not necessarily sorted stream containing the time points.tickSize
- A non-negative double representing the smallest time span distinguishable.allowDuplicates
- If true, the time discretization allows duplicate entries.
-
TimeDiscretizationFromArray
Constructs a time discretization using the given tick size. The time discretization will be sorted. Duplicate entries are allowed ifallowDuplicates
is true, otherwise duplicate entries are removed.- Parameters:
times
- A non closed and not necessarily sorted stream containing the time points.tickSize
- A non-negative double representing the smallest time span distinguishable.
-
TimeDiscretizationFromArray
Constructs a time discretization from a (non closed and not necessarily sorted) stream of boxed doubles.- Parameters:
times
- A double stream of time points for the time discretization.
-
TimeDiscretizationFromArray
public TimeDiscretizationFromArray(Iterable<Double> times, double tickSize, boolean allowDuplicates)Constructs a time discretization using the given tick size. The iteration of the iterable does not have to happen in order.- Parameters:
times
- The time to constitute the time discretization.tickSize
- A non-negative double representing the smallest time span distinguishable.allowDuplicates
- If true, the time discretization allows duplicate entries.
-
TimeDiscretizationFromArray
Constructs a time discretization using the given tick size. The iteration of the iterable does not have to happen in order.- Parameters:
times
- The time to constitute the time discretization.tickSize
- A non-negative double representing the smallest time span distinguishable.
-
TimeDiscretizationFromArray
Constructs a time discretization from an iterable of doubles. The iteration does not have to happen in order.- Parameters:
times
- The time to constitute the time discretization.allowDuplicates
- If true, the time discretization allows duplicate entries.
-
TimeDiscretizationFromArray
Constructs a time discretization from an iterable of doubles. The iteration does not have to happen in order.- Parameters:
times
- The time to constitute the time discretization.
-
TimeDiscretizationFromArray
public TimeDiscretizationFromArray(double... times)Constructs a time discretization from a given set of doubles. The given array does not need to be sorted.- Parameters:
times
- Given array or arguments list of discretization points.
-
TimeDiscretizationFromArray
Constructs a time discretization from a given set of Doubles. The given array does not need to be sorted.- Parameters:
times
- Given boxed array of discretization points.
-
TimeDiscretizationFromArray
Constructs a time discretization using the given tick size. The given array does not need to be sorted.- Parameters:
times
- Given boxed array of discretization points.tickSize
- A non-negative double representing the smallest time span distinguishable.
-
TimeDiscretizationFromArray
public TimeDiscretizationFromArray(double initial, int numberOfTimeSteps, double deltaT)Constructs an equi-distant time discretization with points timeDiscretizationFromArray[i] beingfor(i=0; i ≤ timeSteps; i++) timeDiscretizationFromArray[i] = initial + i * deltaT;
- Parameters:
initial
- First discretization point.numberOfTimeSteps
- Number of time steps.deltaT
- Time step size.
-
TimeDiscretizationFromArray
public TimeDiscretizationFromArray(double initial, double last, double deltaT, TimeDiscretizationFromArray.ShortPeriodLocation shortPeriodLocation)Constructs an equi-distant time discretization with stub periods at start or end.- Parameters:
initial
- First discretization point.last
- Last time steps.deltaT
- Time step size.shortPeriodLocation
- Placement of the stub period.
-
-
Method Details
-
getNumberOfTimes
public int getNumberOfTimes()- Specified by:
getNumberOfTimes
in interfaceTimeDiscretization
- Returns:
- Returns the number of time discretization points.
-
getNumberOfTimeSteps
public int getNumberOfTimeSteps()- Specified by:
getNumberOfTimeSteps
in interfaceTimeDiscretization
- Returns:
- Returns the number of time steps (= number of discretization points-1).
-
getTime
public double getTime(int timeIndex)Description copied from interface:TimeDiscretization
Returns the time for the given time index.- Specified by:
getTime
in interfaceTimeDiscretization
- Parameters:
timeIndex
- Time index- Returns:
- Returns the time for a given time index.
-
getTimeStep
public double getTimeStep(int timeIndex)Description copied from interface:TimeDiscretization
Returns the time step from the given time index to the next one.- Specified by:
getTimeStep
in interfaceTimeDiscretization
- Parameters:
timeIndex
- Time index- Returns:
- Returns the time step
-
getTimeIndex
public int getTimeIndex(double time)Description copied from interface:TimeDiscretization
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).- Specified by:
getTimeIndex
in interfaceTimeDiscretization
- Parameters:
time
- The time.- Returns:
- Returns the time index for a given time.
-
getTimeIndexNearestLessOrEqual
public int getTimeIndexNearestLessOrEqual(double time)Description copied from interface:TimeDiscretization
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.- Specified by:
getTimeIndexNearestLessOrEqual
in interfaceTimeDiscretization
- Parameters:
time
- Given time.- Returns:
- Returns a time index or -1, if the given time is smaller than the this.getFirstTime().
-
getTimeIndexNearestGreaterOrEqual
public int getTimeIndexNearestGreaterOrEqual(double time)Description copied from interface:TimeDiscretization
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.- Specified by:
getTimeIndexNearestGreaterOrEqual
in interfaceTimeDiscretization
- Parameters:
time
- Given time.- Returns:
- Returns a time index or getNumberOfTimes(), if the given time is smaller than the this.getLastTime().
-
getAsDoubleArray
public double[] getAsDoubleArray()Description copied from interface:TimeDiscretization
Return a clone of this time discretization asdouble[]
.- Specified by:
getAsDoubleArray
in interfaceTimeDiscretization
- Returns:
- The time discretization as
double[]
-
getAsArrayList
Description copied from interface:TimeDiscretization
Return a clone of this time discretization asArrayList<Double>
. Note that this method is costly in terms of performance.- Specified by:
getAsArrayList
in interfaceTimeDiscretization
- Returns:
- The time discretization as
ArrayList<Double>
-
getTimeShiftedTimeDiscretization
Description copied from interface:TimeDiscretization
Return a new time discretization where all time points have been shifted by a given time shift.- Specified by:
getTimeShiftedTimeDiscretization
in interfaceTimeDiscretization
- 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.
-
filter
Description copied from interface:TimeDiscretization
Create a newTimeDiscretization
with a subset ofthis
time discretization.- Specified by:
filter
in interfaceTimeDiscretization
- Parameters:
timesToKeep
- True if the time point should belong to the newTimeDiscretization
- Returns:
- A
TimeDiscretization
with a subset ofthis
time discretization.
-
union
Description copied from interface:TimeDiscretization
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
.- Specified by:
union
in interfaceTimeDiscretization
- 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
Description copied from interface:TimeDiscretization
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
.- Specified by:
intersect
in interfaceTimeDiscretization
- 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.
-
getTickSize
public double getTickSize()Description copied from interface:TimeDiscretization
Returns the smallest time span distinguishable in this time discretization.- Specified by:
getTickSize
in interfaceTimeDiscretization
- Returns:
- A non-negative double containing the tick size.
-
iterator
-
toString
-
hashCode
public int hashCode() -
equals
-