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.
- 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.
Setting
-
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
-
Time step:
$h = T/N$ -
Space step:
$\delta = (x_{max} - x_{min})/M$
At each time step a tridiagonal system is solved:
with coefficients:
Two solvers are available:
- Thomas algorithm (hand-written,
solvers.py) - SciPy
solve_banded
.
├── 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
Run_experiments.py performs:
-
Execution-time benchmark of both solvers for several values of
$M$ at fixed$N$ . -
Convergence analysis over a grid of
$(M, N)$ pairs, with the absolute error against the analytical Black-Scholes price.
python Run_experiments.pyThe 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()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.
Alexandre R. - Université Paris Cité