Last updated: 2023-03-16.
tf_quant_finance.math.pde.steppers.douglas_adi.douglas_adi_scheme#
Applies Douglas time marching scheme (see [1] and Eq. 3.1 in [2]).
tf_quant_finance.math.pde.steppers.douglas_adi.douglas_adi_scheme(
theta
)
Time marching schemes solve the space-discretized equation
du_inner/dt = A(t) u_inner(t) + A_mixed u(t) + b(t),
where u, u_inner and b are vectors and A, A_mixed are matrices.
u_inner is u with all boundaries having Robin boundary conditions
trimmed and A_mixed are contributions of mixed derivative terms.
See more details in multidim_parabolic_equation_stepper.py.
In Douglas scheme (as well as other ADI schemes), the matrix A is
represented as sum A = sum_i A_i. A_i is the contribution of
terms with partial derivatives w.r.t. dimension i. The shift term is split
evenly between A_i. Similarly, inhomogeneous term is represented as sum
b = sum_i b_i, where b_i comes from boundary conditions on boundary
orthogonal to dimension i.
Given the current values vector u(t1), the step is defined as follows
(using the notation of Eq. 3.1 in [2]):
Y_0 = (1 + (A(t1) + A_mixed(t1)) dt) U_{n-1} + b(t1) dt,
Y_j = Y_{j-1} + theta dt (A_j(t2) Y_j - A_j(t1) U_{n-1} + b_j(t2) - b_j(t1))
for each spatial dimension j, and
U_n = Y_{n_dims-1}.
Here the parameter theta is a non-negative number, U_{n-1} = u(t1),
U_n = u(t2), and dt = t2 - t1.
Note: Douglas scheme is only first-order accurate if mixed terms are present. More advanced schemes, such as Craig-Sneyd scheme, are needed to achieve the second-order accuracy.
References:#
[1] Douglas Jr., Jim (1962), “Alternating direction methods for three space variables”, Numerische Mathematik, 4 (1): 41-63 [2] Tinne Haentjens, Karek J. in’t Hout. ADI finite difference schemes for the Heston-Hull-White PDE. https://arxiv.org/abs/1111.4087
Args:#
theta: Number between 0 and 1 (see the step definition above).theta = 0corresponds to fully-explicit scheme.
Returns:#
A callable consumes the following arguments by keyword:
inner_value_grid: Grid of solution values at the current time of the same
dtypeasvalue_gridand shape ofbatch_shape+[d_1 - 2 + n_def_i , ..., d_n -2 + n_def_i]whered_iis the number of space discretization points along dimensioniandn_def_iis the number of default boundaries along that dimension.n_def_itakes values 0, 1, 2 (default boundary),t1: Time before the step.
t2: Time after the step.
equation_params_fn: A callable that takes a scalar
Tensorargument representing time, and returns a tuple of two objects:First object is a nested list
Lsuch thatL[i][i]is a tuple of threeTensors, main, upper, and lower diagonal of the tridiagonal matrixAin a directioni. Each elementL[i][j]corresponds to the mixed terms and is either None (meaning there are no mixed terms present) or a tuple ofTensors representing contributions of mixed terms in directions (i + 1, j + 1), (i + 1, j - 1), (i - 1, j + 1), and (i - 1, j - 1).The second object is a tuple of inhomogeneous terms for each dimension. All of the
Tensors are of the samedtypeasinner_value_gridand of the shape broadcastable with the shape ofinner_value_grid.
A callable that accepts a
Tensorof shapeinner_value_gridand appends boundaries according to the boundary conditions, i.e. transformsu_innertou.n_dims: A Python integer, the spatial dimension of the PDE.
has_default_lower_boundary: A Python list of booleans of length
n_dims. List indices enumerate the dimensions withTruevalues marking default lower boundary condition along corresponding dimensions, andFalsevalues indicating Robin boundary conditions.has_default_upper_boundary: Similar to has_default_lower_boundary, but for upper boundaries. The callable returns a
Tensorof the same shape anddtypeavalues_gridand represents an approximate solutionu(t2).