Skip to content

Repository files navigation

Implicit Finite-Difference Scheme for the Black-Scholes PDE

Python Finance Tests Lint Status

📊 Description

Implementation of an implicit finite-difference scheme to solve the Black-Scholes partial differential equation (PDE) in log-price and price a European call. Two tridiagonal solvers are compared: a hand-written Thomas algorithm and SciPy's solve_banded.

🎯 Objectives

  • Solve the Black-Scholes PDE numerically in log-price coordinates.
  • Compare the execution time of the Thomas algorithm vs solve_banded.
  • Study the convergence towards the closed-form Black-Scholes price.

📐 Mathematical Model

Setting $x = \ln(S)$, the option price $u(t, x)$ satisfies the PDE:

$$\frac{\partial u}{\partial t} + \left(r - \frac{1}{2}\sigma^2\right)\frac{\partial u}{\partial x} + \frac{1}{2}\sigma^2 \frac{\partial^2 u}{\partial x^2} - r u = 0$$

Terminal and boundary conditions (Dirichlet)

  • Terminal condition: $$u(T, x) = \max\left(e^x - K, 0\right)$$
  • Lower boundary ($x \to x_{min}$): $u = 0$
  • Upper boundary ($x \to x_{max}$): $u = e^x - K e^{-r(T-t)}$

The space grid is centred on $\ln(S_0)$ and its half-width is set from a Gaussian quantile of the terminal log-price distribution, so the grid node $M/2$ corresponds exactly to $S_0$ ($M$ even).

🔧 Numerical Method

Discretisation

  • Time step: $h = T/N$
  • Space step: $\delta = (x_{max} - x_{min})/M$

Implicit scheme

At each time step a tridiagonal system is solved:

$$A,u_{i-1}^{n-1} + B,u_i^{n-1} + C,u_{i+1}^{n-1} = u_i^{n}$$

with coefficients:

$$A = \frac{h(r - 0.5\sigma^2)}{2\delta} - \frac{h\sigma^2}{2\delta^2}$$

$$B = 1 + rh + \frac{h\sigma^2}{\delta^2}$$

$$C = -\left(\frac{h(r - 0.5\sigma^2)}{2\delta} + \frac{h\sigma^2}{2\delta^2}\right)$$

Two solvers are available:

  • Thomas algorithm (hand-written, solvers.py)
  • SciPy solve_banded

📁 Project Structure

.
├── Black_Scholes.py     # Closed-form Black-Scholes call price
├── Solvers.py           # Thomas algorithm for tridiagonal systems
├── Implicit_scheme.py   # OptionParams, GridConfig, ImplicitScheme
├── Run_experiments.py   # Benchmark + convergence study
└── tests/
    └── Test_implicit_scheme.py

📈 Experiments

Run_experiments.py performs:

  1. Execution-time benchmark of both solvers for several values of $M$ at fixed $N$.
  2. Convergence analysis over a grid of $(M, N)$ pairs, with the absolute error against the analytical Black-Scholes price.

🚀 Usage

python Run_experiments.py

The program prints a summary table and displays the execution-time comparison plot.

Minimal pricing example:

from Implicit_scheme import GridConfig, ImplicitScheme, OptionParams

params = OptionParams(S0=100, K=100, T=1.0, r=0.05, sigma=0.2)
grid = GridConfig(M=800, N=20_000)
price = ImplicitScheme(params, grid, solver="banded").price()

✅ Tests

Six unit tests cover: the Thomas algorithm against a dense solver, agreement between the two solvers, convergence to the closed-form price, error reduction under grid refinement, no-arbitrage lower bound, and grid validation.

👨‍💻 Author

Alexandre R. - Université Paris Cité

About

Implicit finite-difference scheme for the Black-Scholes PDE (European call pricing), with Thomas vs SciPy solve_banded benchmark and convergence analysis

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages