Skip to main content

Module finite_difference

Module finite_difference 

Source
Expand description

Finite difference pricer for the backward pricing PDE in log-spot.

Features:

  • theta-scheme (Crank-Nicolson with a Rannacher fully-implicit start), cell-averaged terminal conditions (kinks and digital jumps), generic Dirichlet boundaries.
  • Per-node, per-step coefficient assembly: supports the Dupire local vol model (mc_model: "local_vol" applies to this engine too) and term-structure-consistent rates (each time step discounts and drifts at the curve’s forward rate for its own calendar interval). This assembly structure is the 1-D basis a stochastic vol (ADI) solver will extend.
  • American exercise via Brennan-Schwartz (projection inside the tridiagonal solve, swept from the out-of-the-money side).
  • Barrier options: knock-out via an absorbing boundary with the grid edge placed exactly at the barrier; knock-in by parity (European).
  • Greeks from the grid: delta/gamma from a local quadratic fit at the spot, theta from the last two time layers — one solve yields npv/delta/gamma/theta; vega and rho are bump-and-resolve.

Grid sizes are configurable per contract (fd_spot_steps, fd_time_steps in JSON).

Structs§

FdConfig
FdSolution
One solve returns the value and the grid Greeks.

Functions§

delta
gamma
npv
rho
solution
Value and grid Greeks in a single solve (two for knock-ins).
theta
thomas_algorithm
Solves a tridiagonal system A x = d where a is the sub-diagonal (a[i-1] multiplies x[i-1] in row i), b the diagonal and c the super-diagonal (c[i] multiplies x[i+1] in row i). https://en.wikipedia.org/wiki/Tridiagonal_matrix_algorithm
vega