Class TimeDiscretizationFromArray

  • All Implemented Interfaces:
    Serializable, Iterable<Double>, TimeDiscretization
    Direct Known Subclasses:
    TenorFromArray

    public class TimeDiscretizationFromArray
    extends Object
    implements Serializable, TimeDiscretization
    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.
    Version:
    1.6
    Author:
    Christian Fries
    See Also:
    Serialized Form
    • Constructor Detail

      • TimeDiscretizationFromArray

        public TimeDiscretizationFromArray​(DoubleStream times,
                                           double tickSize,
                                           boolean allowDuplicates)
        Constructs a time discretization using the given tick size. The time discretization will be sorted. Duplicate entries are allowed if allowDuplicates 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

        public TimeDiscretizationFromArray​(DoubleStream times,
                                           double tickSize)
        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

        public TimeDiscretizationFromArray​(DoubleStream times,
                                           boolean allowDuplicates)
        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 if allowDuplicates 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

        public TimeDiscretizationFromArray​(DoubleStream times)
        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

        public TimeDiscretizationFromArray​(Stream<Double> times,
                                           double tickSize,
                                           boolean allowDuplicates)
        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

        public TimeDiscretizationFromArray​(Stream<Double> times,
                                           double tickSize)
        Constructs a time discretization using the given tick size. The time discretization will be sorted. Duplicate entries are allowed if allowDuplicates 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

        public TimeDiscretizationFromArray​(Stream<Double> times)
        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

        public TimeDiscretizationFromArray​(Iterable<Double> times,
                                           double tickSize)
        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

        public TimeDiscretizationFromArray​(Iterable<Double> times,
                                           boolean allowDuplicates)
        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

        public TimeDiscretizationFromArray​(Iterable<Double> times)
        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

        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 boxed array of discretization points.
      • TimeDiscretizationFromArray

        public TimeDiscretizationFromArray​(Double[] times,
                                           double tickSize)
        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] being for(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 Detail

      • getNumberOfTimes

        public int getNumberOfTimes()
        Specified by:
        getNumberOfTimes in interface TimeDiscretization
        Returns:
        Returns the number of time discretization points.
      • getNumberOfTimeSteps

        public int getNumberOfTimeSteps()
        Specified by:
        getNumberOfTimeSteps in interface TimeDiscretization
        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 interface TimeDiscretization
        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 interface TimeDiscretization
        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 interface TimeDiscretization
        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]).
        Specified by:
        getTimeIndexNearestLessOrEqual in interface TimeDiscretization
        Parameters:
        time - Given time.
        Returns:
        Returns a time index
      • 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]).
        Specified by:
        getTimeIndexNearestGreaterOrEqual in interface TimeDiscretization
        Parameters:
        time - Given time.
        Returns:
        Returns a time index
      • getAsDoubleArray

        public double[] getAsDoubleArray()
        Description copied from interface: TimeDiscretization
        Return a clone of this time discretization as double[].
        Specified by:
        getAsDoubleArray in interface TimeDiscretization
        Returns:
        The time discretization as double[]
      • getAsArrayList

        public ArrayList<Double> getAsArrayList()
        Description copied from interface: TimeDiscretization
        Return a clone of this time discretization as ArrayList<Double>. Note that this method is costly in terms of performance.
        Specified by:
        getAsArrayList in interface TimeDiscretization
        Returns:
        The time discretization as ArrayList<Double>
      • getTimeShiftedTimeDiscretization

        public TimeDiscretization getTimeShiftedTimeDiscretization​(double timeShift)
        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 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.
      • union

        public TimeDiscretization union​(TimeDiscretization that)
        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 example a.intersect(a.union(b)) might not be equal to a.
        Specified by:
        union in 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.
      • intersect

        public TimeDiscretization intersect​(TimeDiscretization that)
        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 example a.intersect(a.union(b)) might not be equal to a.
        Specified by:
        intersect in 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.
      • getTickSize

        public double getTickSize()
        Description copied from interface: TimeDiscretization
        Returns the smallest time span distinguishable in this time discretization.
        Specified by:
        getTickSize in interface TimeDiscretization
        Returns:
        A non-negative double containing the tick size.
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object