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 SummaryNested Classes
- 
Constructor SummaryConstructorsConstructorDescriptionTimeDiscretizationFromArray(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 SummaryModifier and TypeMethodDescriptionbooleanfilter(DoublePredicate timesToKeep)Create a newTimeDiscretizationwith a subset ofthistime discretization.Return a clone of this time discretization asArrayList<Double>.double[]Return a clone of this time discretization asdouble[].intintdoubleReturns the smallest time span distinguishable in this time discretization.doublegetTime(int timeIndex)Returns the time for the given time index.intgetTimeIndex(double time)Returns the time index for the given time.intgetTimeIndexNearestGreaterOrEqual(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.intgetTimeIndexNearestLessOrEqual(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.doublegetTimeStep(int timeIndex)Returns the time step from the given time index to the next one.inthashCode()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.Objectclone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.lang.IterableforEach, spliteratorMethods inherited from interface net.finmath.time.TimeDiscretizationdoubleStream, getFirstTime, getLastTime
- 
Constructor Details- 
TimeDiscretizationFromArrayConstructs a time discretization using the given tick size. The time discretization will be sorted. Duplicate entries are allowed ifallowDuplicatesis 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.
 
- 
TimeDiscretizationFromArrayConstructs 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.
 
- 
TimeDiscretizationFromArrayConstructs a time discretization from a (non closed and not necessarily sorted) stream of doubles. The time discretization will be sorted. Duplicate entries are allowed ifallowDuplicatesis 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.
 
- 
TimeDiscretizationFromArrayConstructs 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.
 
- 
TimeDiscretizationFromArrayConstructs 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.
 
- 
TimeDiscretizationFromArrayConstructs a time discretization using the given tick size. The time discretization will be sorted. Duplicate entries are allowed ifallowDuplicatesis 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.
 
- 
TimeDiscretizationFromArrayConstructs 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.
 
- 
TimeDiscretizationFromArraypublic 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.
 
- 
TimeDiscretizationFromArrayConstructs 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.
 
- 
TimeDiscretizationFromArrayConstructs 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.
 
- 
TimeDiscretizationFromArrayConstructs 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.
 
- 
TimeDiscretizationFromArraypublic 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.
 
- 
TimeDiscretizationFromArrayConstructs 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.
 
- 
TimeDiscretizationFromArrayConstructs 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.
 
- 
TimeDiscretizationFromArraypublic 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.
 
- 
TimeDiscretizationFromArraypublic 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- 
getNumberOfTimespublic int getNumberOfTimes()- Specified by:
- getNumberOfTimesin interface- TimeDiscretization
- Returns:
- Returns the number of time discretization points.
 
- 
getNumberOfTimeStepspublic int getNumberOfTimeSteps()- Specified by:
- getNumberOfTimeStepsin interface- TimeDiscretization
- Returns:
- Returns the number of time steps (= number of discretization points-1).
 
- 
getTimepublic double getTime(int timeIndex)Description copied from interface:TimeDiscretizationReturns the time for the given time index.- Specified by:
- getTimein interface- TimeDiscretization
- Parameters:
- timeIndex- Time index
- Returns:
- Returns the time for a given time index.
 
- 
getTimeSteppublic double getTimeStep(int timeIndex)Description copied from interface:TimeDiscretizationReturns the time step from the given time index to the next one.- Specified by:
- getTimeStepin interface- TimeDiscretization
- Parameters:
- timeIndex- Time index
- Returns:
- Returns the time step
 
- 
getTimeIndexpublic int getTimeIndex(double time)Description copied from interface:TimeDiscretizationReturns 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:
- getTimeIndexin interface- TimeDiscretization
- Parameters:
- time- The time.
- Returns:
- Returns the time index for a given time.
 
- 
getTimeIndexNearestLessOrEqualpublic int getTimeIndexNearestLessOrEqual(double time)Description copied from interface:TimeDiscretizationReturns 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:
- getTimeIndexNearestLessOrEqualin interface- TimeDiscretization
- Parameters:
- time- Given time.
- Returns:
- Returns a time index or -1, if the given time is smaller than the this.getFirstTime().
 
- 
getTimeIndexNearestGreaterOrEqualpublic int getTimeIndexNearestGreaterOrEqual(double time)Description copied from interface:TimeDiscretizationReturns 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:
- getTimeIndexNearestGreaterOrEqualin interface- TimeDiscretization
- Parameters:
- time- Given time.
- Returns:
- Returns a time index or getNumberOfTimes(), if the given time is smaller than the this.getLastTime().
 
- 
getAsDoubleArraypublic double[] getAsDoubleArray()Description copied from interface:TimeDiscretizationReturn a clone of this time discretization asdouble[].- Specified by:
- getAsDoubleArrayin interface- TimeDiscretization
- Returns:
- The time discretization as double[]
 
- 
getAsArrayListDescription copied from interface:TimeDiscretizationReturn a clone of this time discretization asArrayList<Double>. Note that this method is costly in terms of performance.- Specified by:
- getAsArrayListin interface- TimeDiscretization
- Returns:
- The time discretization as ArrayList<Double>
 
- 
getTimeShiftedTimeDiscretizationDescription copied from interface:TimeDiscretizationReturn a new time discretization where all time points have been shifted by a given time shift.- Specified by:
- getTimeShiftedTimeDiscretizationin interface- TimeDiscretization
- 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.
 
- 
filterDescription copied from interface:TimeDiscretizationCreate a newTimeDiscretizationwith a subset ofthistime discretization.- Specified by:
- filterin interface- TimeDiscretization
- Parameters:
- timesToKeep- True if the time point should belong to the new- TimeDiscretization
- Returns:
- A TimeDiscretizationwith a subset ofthistime discretization.
 
- 
unionDescription copied from interface:TimeDiscretizationReturns 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:
- unionin interface- TimeDiscretization
- 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.
 
- 
intersectDescription copied from interface:TimeDiscretizationReturns 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:
- intersectin interface- TimeDiscretization
- 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.
 
- 
getTickSizepublic double getTickSize()Description copied from interface:TimeDiscretizationReturns the smallest time span distinguishable in this time discretization.- Specified by:
- getTickSizein interface- TimeDiscretization
- Returns:
- A non-negative double containing the tick size.
 
- 
iterator
- 
toString
- 
hashCodepublic int hashCode()
- 
equals
 
-