Class AbstractADI2D

java.lang.Object
net.finmath.finitedifference.solvers.adi.AbstractADI2D
All Implemented Interfaces:
FDMSolver
Direct Known Subclasses:
FDMAsianADI2D, FDMBarrierHestonADI2D, FDMBarrierSabrADI2D, FDMBatesADI2D, FDMHestonADI2D, FDMMultiAssetBlackScholesADI2D, FDMSabrADI2D

public abstract class AbstractADI2D extends Object implements FDMSolver
Generic two-dimensional alternating direction implicit finite-difference solver.

The solver acts on a two-dimensional state vector (x_0,x_1) and computes an approximation of the value function V(t,x_0,x_1) associated with a parabolic pricing equation of the form

\frac{\partial V}{\partial t} + \mathcal{A}_0 V + \mathcal{A}_1 V + \mathcal{A}_2 V = 0,

where the operator is split into:

  • \mathcal{A}_0: mixed derivative term together with discounting, treated explicitly,
  • \mathcal{A}_1: first-direction drift and diffusion terms, treated implicitly,
  • \mathcal{A}_2: second-direction drift and diffusion terms, treated implicitly.

The time stepping uses a stabilized Douglas-type ADI splitting. For a time step \Delta t, the algorithm first forms an explicit predictor and then performs successive implicit solves along the two spatial directions. To improve numerical stability, the implementation applies two half Douglas steps. This yields a scheme which is efficient for two-dimensional problems since each implicit stage reduces to a collection of tridiagonal linear systems along grid lines.

The flattening convention for a grid function is

k = i0 + i1 * n0

where i0 is the index in the first spatial direction and i1 is the index in the second spatial direction. Hence the first state direction is stored as the fastest varying index.

The solver supports:

  • terminal conditions depending on one or two state variables,
  • discrete exercise obstacles for Bermudan or American-style problems,
  • continuous obstacles applied after each backward step,
  • internal state constraints supplied by the product,
  • vector-level equity event conditions at prescribed event times,
  • Dirichlet boundary extraction from the model boundary conditions.
Author:
Alessandro Gnoatto
  • Constructor Details

  • Method Details

    • getValues

      public double[][] getValues(double time, DoubleUnaryOperator valueAtMaturity)
      Returns the full value surface for a terminal payoff depending on the first state variable.
      Specified by:
      getValues in interface FDMSolver
      Parameters:
      time - Maturity time.
      valueAtMaturity - Terminal payoff.
      Returns:
      Value surface indexed by flattened space index and time index.
    • getValues

      public double[][] getValues(double time, DoubleBinaryOperator valueAtMaturity)
      Returns the full value surface for a two-dimensional terminal payoff.
      Specified by:
      getValues in interface FDMSolver
      Parameters:
      time - Maturity time.
      valueAtMaturity - Terminal payoff.
      Returns:
      Value surface indexed by flattened space index and time index.
    • getValuesWithContinuousObstacle

      public double[][] getValuesWithContinuousObstacle(double time, DoubleBinaryOperator valueAtMaturity, AbstractADI2D.DoubleTernaryOperator continuousObstacleValue)
      Returns the full value surface under a continuous obstacle.
      Parameters:
      time - Maturity time.
      valueAtMaturity - Terminal payoff.
      continuousObstacleValue - Continuous obstacle value.
      Returns:
      Value surface indexed by flattened space index and time index.
    • getValueWithContinuousObstacle

      public double[] getValueWithContinuousObstacle(double evaluationTime, double time, DoubleBinaryOperator valueAtMaturity, AbstractADI2D.DoubleTernaryOperator continuousObstacleValue)
      Returns the values at a given evaluation time under a continuous obstacle.
      Parameters:
      evaluationTime - Evaluation time.
      time - Maturity time.
      valueAtMaturity - Terminal payoff.
      continuousObstacleValue - Continuous obstacle value.
      Returns:
      Value vector on the flattened space grid.
    • getValues

      public double[][] getValues(double time, DoubleBinaryOperator valueAtMaturity, AbstractADI2D.DoubleTernaryOperator exerciseValue)
      Returns the full value surface under a discrete exercise obstacle.
      Parameters:
      time - Maturity time.
      valueAtMaturity - Terminal payoff.
      exerciseValue - Exercise payoff.
      Returns:
      Value surface indexed by flattened space index and time index.
    • getValue

      public double[] getValue(double evaluationTime, double time, DoubleUnaryOperator valueAtMaturity)
      Returns the values at the specified evaluation time for a one-dimensional terminal payoff.
      Specified by:
      getValue in interface FDMSolver
      Parameters:
      evaluationTime - Evaluation time.
      time - Maturity time.
      valueAtMaturity - Terminal payoff.
      Returns:
      Value vector on the flattened space grid.
    • getValue

      public double[] getValue(double evaluationTime, double time, DoubleBinaryOperator valueAtMaturity)
      Returns the values at the specified evaluation time for a two-dimensional terminal payoff.
      Specified by:
      getValue in interface FDMSolver
      Parameters:
      evaluationTime - Evaluation time.
      time - Maturity time.
      valueAtMaturity - Terminal payoff.
      Returns:
      Value vector on the flattened space grid.
    • getValue

      public double[] getValue(double evaluationTime, double time, DoubleBinaryOperator valueAtMaturity, AbstractADI2D.DoubleTernaryOperator exerciseValue)
      Returns the values at the specified evaluation time under a discrete exercise obstacle.
      Parameters:
      evaluationTime - Evaluation time.
      time - Maturity time.
      valueAtMaturity - Terminal payoff.
      exerciseValue - Exercise payoff.
      Returns:
      Value vector on the flattened space grid.
    • performStableDouglasStep

      protected double[] performStableDouglasStep(double[] u, double currentTime, double dt)
      Performs one stabilized Douglas time step by splitting it into two half steps.
      Parameters:
      u - Current solution vector.
      currentTime - Current running time.
      dt - Time-step size.
      Returns:
      Updated solution vector.
    • performDouglasHalfStep

      protected double[] performDouglasHalfStep(double[] u, double currentTime, double dt)
      Performs one half Douglas step.
      Parameters:
      u - Current solution vector.
      currentTime - Current running time.
      dt - Time-step size.
      Returns:
      Updated solution vector.
    • applyFullExplicitOperator

      protected double[] applyFullExplicitOperator(double[] u, double time)
    • applyA0Explicit

      protected double[] applyA0Explicit(double[] u, double time)
    • applyA1Explicit

      protected double[] applyA1Explicit(double[] u, double time)
    • applyA2Explicit

      protected double[] applyA2Explicit(double[] u, double time)
    • solveFirstDirectionLines

      protected double[] solveFirstDirectionLines(double[] rhs, double time, double dt)
    • solveSecondDirectionLines

      protected double[] solveSecondDirectionLines(double[] rhs, double time, double dt)
    • applyOuterBoundaries

      protected void applyOuterBoundaries(double time, double[] u)
    • applyInternalConstraints

      protected void applyInternalConstraints(double time, double[] u)
    • applyExerciseObstacleIfNeeded

      protected void applyExerciseObstacleIfNeeded(double runningTime, double tau, double[] u, AbstractADI2D.DoubleTernaryOperator exerciseValue)
    • applyContinuousObstacleIfNeeded

      protected void applyContinuousObstacleIfNeeded(double runningTime, double[] u, AbstractADI2D.DoubleTernaryOperator continuousObstacleValue)
    • isInternalConstraintActive

      protected boolean isInternalConstraintActive(double time, double x0, double x1)
    • getLowerBoundaryValueForFirstDirection

      protected double getLowerBoundaryValueForFirstDirection(double time, int secondIndex, double fallback)
    • getUpperBoundaryValueForFirstDirection

      protected double getUpperBoundaryValueForFirstDirection(double time, int secondIndex, double fallback)
    • getLowerBoundaryValueForSecondDirection

      protected double getLowerBoundaryValueForSecondDirection(double time, int firstIndex, double fallback)
    • getUpperBoundaryValueForSecondDirection

      protected double getUpperBoundaryValueForSecondDirection(double time, int firstIndex, double fallback)
    • extractBoundaryValue

      protected double extractBoundaryValue(BoundaryCondition condition, double fallback)
    • overwriteBoundaryRow

      protected void overwriteBoundaryRow(TridiagonalMatrix m, double[] rhs, int row, double value)
    • flatten

      protected int flatten(int i0, int i1)
    • sanitize

      protected double[] sanitize(double[] values)
    • add

      protected double[] add(double[] a, double[] b)
    • subtract

      protected double[] subtract(double[] a, double[] b)
    • scale

      protected double[] scale(double[] a, double scalar)
    • applyProductEventConditionIfNeeded

      protected double[] applyProductEventConditionIfNeeded(double time, double[] valuesAfterEvent)
    • getStencilBuilder

      protected ADI2DStencilBuilder getStencilBuilder()
    • getN

      protected int getN()
    • getN1

      protected int getN1()
    • getN0

      protected int getN0()
    • getX1Grid

      protected double[] getX1Grid()
    • getX0Grid

      protected double[] getX0Grid()
    • getTheta

      protected double getTheta()
    • getExercise

      protected Exercise getExercise()
    • getSpaceTimeDiscretization

      protected SpaceTimeDiscretization getSpaceTimeDiscretization()
    • getProduct

      protected FiniteDifferenceEquityProduct getProduct()
    • getModel

      protected FiniteDifferenceEquityModel getModel()