finMath lib documentation

net.finmath.time
Class TimeDiscretization

java.lang.Object
  extended by net.finmath.time.TimeDiscretization
All Implemented Interfaces:
Serializable, Iterable<Double>, TimeDiscretizationInterface
Direct Known Subclasses:
Tenor

public class TimeDiscretization
extends Object
implements 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.

Version:
1.5
Author:
Christian Fries
See Also:
Serialized Form

Nested Class Summary
static class TimeDiscretization.ShortPeriodLocation
           
 
Constructor Summary
TimeDiscretization(ArrayList<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(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] being for(i=0; i ≤ timeSteps; i++) timeDiscretization[i] = initial + i * deltaT;
 
Method Summary
 ArrayList<Double> getAsArrayList()
          Return a clone of this time discretization as ArrayList<Double>.
 double[] getAsDoubleArray()
          Return a clone of this time discretization as double[].
 int getNumberOfTimes()
           
 int getNumberOfTimeSteps()
           
 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. min(i : timeDiscretization[i] ≥ time where timeDiscretization[i] ≤ timeDiscretization[j]).
 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 : timeDiscretization[i] ≤ time where timeDiscretization[i] ≤ timeDiscretization[j]).
 TimeDiscretizationInterface 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.
 Iterator<Double> iterator()
           
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

TimeDiscretization

public TimeDiscretization(double... times)
Constructs a time discretization from a given set of doubles.

Parameters:
times - Given array or arguments list of discretization points.

TimeDiscretization

public TimeDiscretization(Double[] times)
Constructs a time discretization from a given set of Doubles.

Parameters:
times - Given array or arguments list of discretization points

TimeDiscretization

public TimeDiscretization(ArrayList<Double> timeDiscretization)
Constructs a time discretization from a given ArrayList of Doubles.

Parameters:
timeDiscretization - Given ArrayList of discretization points

TimeDiscretization

public TimeDiscretization(double initial,
                          int numberOfTimeSteps,
                          double deltaT)
Constructs an equi-distant time discretization with points timeDiscretization[i] being for(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:
getNumberOfTimes in interface TimeDiscretizationInterface
Returns:
Returns the number of time discretization points.

getNumberOfTimeSteps

public int getNumberOfTimeSteps()
Specified by:
getNumberOfTimeSteps in interface TimeDiscretizationInterface
Returns:
Returns the number of time steps (= number of discretization points-1).

getTime

public double getTime(int timeIndex)
Description copied from interface: TimeDiscretizationInterface
Returns the time for the given time index.

Specified by:
getTime in interface TimeDiscretizationInterface
Parameters:
timeIndex - Time index
Returns:
Returns the time for a given time index.

getTimeStep

public double getTimeStep(int timeIndex)
Description copied from interface: TimeDiscretizationInterface
Returns the time step from the given time index to the next one.

Specified by:
getTimeStep in interface TimeDiscretizationInterface
Parameters:
timeIndex - Time index
Returns:
Returns the time step

getTimeIndex

public int getTimeIndex(double time)
Description copied from interface: TimeDiscretizationInterface
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 TimeDiscretizationInterface
Parameters:
time - The time.
Returns:
Returns the time index for a given time.

getTimeIndexNearestLessOrEqual

public int getTimeIndexNearestLessOrEqual(double time)
Description copied from interface: TimeDiscretizationInterface
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 : timeDiscretization[i] ≤ time where timeDiscretization[i] ≤ timeDiscretization[j]).

Specified by:
getTimeIndexNearestLessOrEqual in interface TimeDiscretizationInterface
Parameters:
time - Given time.
Returns:
Returns a time index

getTimeIndexNearestGreaterOrEqual

public int getTimeIndexNearestGreaterOrEqual(double time)
Description copied from interface: TimeDiscretizationInterface
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 : timeDiscretization[i] ≥ time where timeDiscretization[i] ≤ timeDiscretization[j]).

Specified by:
getTimeIndexNearestGreaterOrEqual in interface TimeDiscretizationInterface
Parameters:
time - Given time.
Returns:
Returns a time index

getAsDoubleArray

public double[] getAsDoubleArray()
Description copied from interface: TimeDiscretizationInterface
Return a clone of this time discretization as double[].

Specified by:
getAsDoubleArray in interface TimeDiscretizationInterface
Returns:
The time discretization as double[]

getAsArrayList

public ArrayList<Double> getAsArrayList()
Description copied from interface: TimeDiscretizationInterface
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 TimeDiscretizationInterface
Returns:
The time discretization as ArrayList<Double>

getTimeShiftedTimeDiscretization

public TimeDiscretizationInterface getTimeShiftedTimeDiscretization(double timeShift)
Description copied from interface: TimeDiscretizationInterface
Return a new time discretization where all time points have been shifted by a given time shift.

Specified by:
getTimeShiftedTimeDiscretization in interface TimeDiscretizationInterface
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 Iterator<Double> iterator()
Specified by:
iterator in interface Iterable<Double>

toString

public String toString()
Overrides:
toString in class Object

Copyright © 2014 Christian P. Fries.

Copyright © 2014. All rights reserved.