Class FiniteDifferenceValueInterpolator
java.lang.Object
net.finmath.finitedifference.utilities.FiniteDifferenceValueInterpolator
Interpolation utilities for finite-difference value vectors and surfaces.
The methods in this class operate on the standard finite-difference output format used by products:
double[]for one time slice, indexed by flattened spatial index,double[][]for full value surfaces, indexed by flattened spatial index and solver time index.
Spatial interpolation is multilinear and supports any number of spatial dimensions. Coordinates outside the grid domain are extrapolated constantly by clamping to the nearest boundary grid point.
- Author:
- Alessandro Gnoatto
-
Method Summary
Modifier and TypeMethodDescriptionstatic intgetTimeIndexNearestLessOrEqual(SpaceTimeDiscretization discretization, double evaluationTime, double maturity, double[][] values) Returns the nearest previous solver time index for an evaluation time.static double[]getTimeSlice(double[][] values, SpaceTimeDiscretization discretization, double evaluationTime, double maturity) Extracts a value vector at an evaluation time.static double[]getTimeSlice(double[][] values, SpaceTimeDiscretization discretization, int timeIndex) Extracts a value vector at a solver time index.static doubleinterpolateSurface(double[][] values, SpaceTimeDiscretization discretization, double evaluationTime, double maturity, double... coordinates) Interpolates a value surface at an evaluation time and spatial coordinate.static doubleinterpolateTimeIndex(double[][] values, SpaceTimeDiscretization discretization, int timeIndex, double... coordinates) Interpolates a value surface at a given solver time index and spatial coordinate.static doubleinterpolateValue(double[] values, SpaceTimeDiscretization discretization, double... coordinates) Interpolates a value vector at a spatial coordinate.
-
Method Details
-
interpolateValue
public static double interpolateValue(double[] values, SpaceTimeDiscretization discretization, double... coordinates) Interpolates a value vector at a spatial coordinate.- Parameters:
values- The value vector indexed by flattened spatial index.discretization- The space-time discretization defining the spatial grids.coordinates- The spatial coordinates.- Returns:
- The interpolated value.
-
interpolateSurface
public static double interpolateSurface(double[][] values, SpaceTimeDiscretization discretization, double evaluationTime, double maturity, double... coordinates) Interpolates a value surface at an evaluation time and spatial coordinate.The method converts the calendar evaluation time to solver backward time by using
tau = maturity - evaluationTime. The nearest previous time index is used.- Parameters:
values- The value surface indexed by flattened spatial index and time index.discretization- The space-time discretization.evaluationTime- The evaluation time.maturity- The product maturity.coordinates- The spatial coordinates.- Returns:
- The interpolated value.
-
interpolateTimeIndex
public static double interpolateTimeIndex(double[][] values, SpaceTimeDiscretization discretization, int timeIndex, double... coordinates) Interpolates a value surface at a given solver time index and spatial coordinate.- Parameters:
values- The value surface indexed by flattened spatial index and time index.discretization- The space-time discretization.timeIndex- The solver time index.coordinates- The spatial coordinates.- Returns:
- The interpolated value.
-
getTimeSlice
public static double[] getTimeSlice(double[][] values, SpaceTimeDiscretization discretization, double evaluationTime, double maturity) Extracts a value vector at an evaluation time.- Parameters:
values- The value surface indexed by flattened spatial index and time index.discretization- The space-time discretization.evaluationTime- The evaluation time.maturity- The product maturity.- Returns:
- The value vector at the nearest previous solver time index.
-
getTimeSlice
public static double[] getTimeSlice(double[][] values, SpaceTimeDiscretization discretization, int timeIndex) Extracts a value vector at a solver time index.- Parameters:
values- The value surface indexed by flattened spatial index and time index.discretization- The space-time discretization.timeIndex- The solver time index.- Returns:
- The value vector at the requested time index.
-
getTimeIndexNearestLessOrEqual
public static int getTimeIndexNearestLessOrEqual(SpaceTimeDiscretization discretization, double evaluationTime, double maturity, double[][] values) Returns the nearest previous solver time index for an evaluation time.- Parameters:
discretization- The space-time discretization.evaluationTime- The evaluation time.maturity- The product maturity.values- The value surface used for time-index bounds.- Returns:
- The nearest previous solver time index.
-