net.finmath.time
Class TimeDiscretization
- java.lang.Object
-
- net.finmath.time.TimeDiscretization
-
- All Implemented Interfaces:
- java.io.Serializable, java.lang.Iterable<java.lang.Double>, TimeDiscretizationInterface
- Direct Known Subclasses:
- Tenor
public class TimeDiscretization extends java.lang.Object implements java.io.Serializable, TimeDiscretizationInterface
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") of 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). Objects of this class are immutable.- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class and Description static classTimeDiscretization.ShortPeriodLocation
-
Constructor Summary
Constructors Constructor and Description TimeDiscretization(java.util.ArrayList<java.lang.Double> timeDiscretization)Constructs a time discretization from a given ArrayList of Doubles.TimeDiscretization(double... times)Constructs a time discretization from a given set of doubles.TimeDiscretization(java.lang.Double[] times)Constructs a time discretization from a given set of Doubles.TimeDiscretization(double initial, double last, double deltaT, TimeDiscretization.ShortPeriodLocation shortPeriodLocation)Constructs an equi-distant time discretization with stub periods at start or end.TimeDiscretization(double initial, int numberOfTimeSteps, double deltaT)Constructs an equi-distant time discretization with points timeDiscretization[i] beingfor(i=0; i ≤ timeSteps; i++) timeDiscretization[i] = initial + i * deltaT;TimeDiscretization(java.util.Set<java.lang.Double> times)Constructs a time discretization from a given Set of Doubles.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description booleanequals(java.lang.Object obj)java.util.ArrayList<java.lang.Double>getAsArrayList()Return a clone of this time discretization asArrayList<Double>.double[]getAsDoubleArray()Return a clone of this time discretization asdouble[].intgetNumberOfTimes()intgetNumberOfTimeSteps()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.TimeDiscretizationInterfacegetTimeShiftedTimeDiscretization(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()java.util.Iterator<java.lang.Double>iterator()java.lang.StringtoString()
-
-
-
Constructor Detail
-
TimeDiscretization
public TimeDiscretization(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.
-
TimeDiscretization
public TimeDiscretization(java.lang.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.
-
TimeDiscretization
public TimeDiscretization(java.util.ArrayList<java.lang.Double> timeDiscretization)
Constructs a time discretization from a given ArrayList of Doubles. The given list does not need to be sorted.- Parameters:
timeDiscretization- Given ArrayList of discretization points
-
TimeDiscretization
public TimeDiscretization(java.util.Set<java.lang.Double> times)
Constructs a time discretization from a given Set of Doubles.- Parameters:
times- Given Set of discretization points
-
TimeDiscretization
public TimeDiscretization(double initial, int numberOfTimeSteps, double deltaT)Constructs an equi-distant time discretization with points timeDiscretization[i] beingfor(i=0; i ≤ timeSteps; i++) timeDiscretization[i] = initial + i * deltaT;- Parameters:
initial- First discretization point.numberOfTimeSteps- Number of time steps.deltaT- Time step size.
-
TimeDiscretization
public TimeDiscretization(double initial, double last, double deltaT, TimeDiscretization.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 Detail
-
getNumberOfTimes
public int getNumberOfTimes()
- Specified by:
getNumberOfTimesin interfaceTimeDiscretizationInterface- Returns:
- Returns the number of time discretization points.
-
getNumberOfTimeSteps
public int getNumberOfTimeSteps()
- Specified by:
getNumberOfTimeStepsin interfaceTimeDiscretizationInterface- Returns:
- Returns the number of time steps (= number of discretization points-1).
-
getTime
public double getTime(int timeIndex)
Description copied from interface:TimeDiscretizationInterfaceReturns the time for the given time index.- Specified by:
getTimein interfaceTimeDiscretizationInterface- Parameters:
timeIndex- Time index- Returns:
- Returns the time for a given time index.
-
getTimeStep
public double getTimeStep(int timeIndex)
Description copied from interface:TimeDiscretizationInterfaceReturns the time step from the given time index to the next one.- Specified by:
getTimeStepin interfaceTimeDiscretizationInterface- Parameters:
timeIndex- Time index- Returns:
- Returns the time step
-
getTimeIndex
public int getTimeIndex(double time)
Description copied from interface:TimeDiscretizationInterfaceReturns 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 interfaceTimeDiscretizationInterface- Parameters:
time- The time.- Returns:
- Returns the time index for a given time.
-
getTimeIndexNearestLessOrEqual
public int getTimeIndexNearestLessOrEqual(double time)
Description copied from interface:TimeDiscretizationInterfaceReturns 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 : timeDiscretization[i] ≤ time where timeDiscretization[i] ≤ timeDiscretization[j]).- Specified by:
getTimeIndexNearestLessOrEqualin interfaceTimeDiscretizationInterface- Parameters:
time- Given time.- Returns:
- Returns a time index
-
getTimeIndexNearestGreaterOrEqual
public int getTimeIndexNearestGreaterOrEqual(double time)
Description copied from interface:TimeDiscretizationInterfaceReturns 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 : timeDiscretization[i] ≥ time where timeDiscretization[i] ≤ timeDiscretization[j]).- Specified by:
getTimeIndexNearestGreaterOrEqualin interfaceTimeDiscretizationInterface- Parameters:
time- Given time.- Returns:
- Returns a time index
-
getAsDoubleArray
public double[] getAsDoubleArray()
Description copied from interface:TimeDiscretizationInterfaceReturn a clone of this time discretization asdouble[].- Specified by:
getAsDoubleArrayin interfaceTimeDiscretizationInterface- Returns:
- The time discretization as
double[]
-
getAsArrayList
public java.util.ArrayList<java.lang.Double> getAsArrayList()
Description copied from interface:TimeDiscretizationInterfaceReturn a clone of this time discretization asArrayList<Double>. Note that this method is costly in terms of performance.- Specified by:
getAsArrayListin interfaceTimeDiscretizationInterface- Returns:
- The time discretization as
ArrayList<Double>
-
getTimeShiftedTimeDiscretization
public TimeDiscretizationInterface getTimeShiftedTimeDiscretization(double timeShift)
Description copied from interface:TimeDiscretizationInterfaceReturn a new time discretization where all time points have been shifted by a given time shift.- Specified by:
getTimeShiftedTimeDiscretizationin interfaceTimeDiscretizationInterface- 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.
-
iterator
public java.util.Iterator<java.lang.Double> iterator()
- Specified by:
iteratorin interfacejava.lang.Iterable<java.lang.Double>
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equalsin classjava.lang.Object
-
-
DataMelt 3.0 © DataMelt by jWork.ORG