Skip to main content

finite-difference

Finite-difference option pricing for the SABR stochastic-volatility model via the Douglas-scheme ADI method of von Sydow et al. (2010).

von Sydow et al. (2010). ADI finite difference schemes for option pricing in the Heston model with correlation. International Journal of Numerical Analysis and Modeling, 7(2), 303–320.

What it solves

European call and put options under the SABR model — a four-parameter (α, β, ρ, ν) stochastic-volatility framework — whose pricing PDE is two-dimensional and has no closed form. The package solves that PDE on a Cartesian (S, v, t) grid using the Douglas Alternating Direction Implicit scheme: implicit sweeps in S and v are alternated each step, with the cross-derivative term handled explicitly. One-dimensional Black–Scholes solvers (explicit, implicit, Crank–Nicolson, American) ship as baselines and as the validation reference for the SABR limit.

Installation

pip install mafn-finite-difference

Version 0.2.0

This release adds SABR benchmark validation, automatic SABR grid-boundary selection, and an Extended Heston ADI solver with package-level tests.

Quick start

from finite_difference import price_sabr_option

# 1-year ATM SABR call: alpha=0.2, beta=1, rho=-0.3, nu=0.4
price, V, S, v = price_sabr_option(
    S0=100.0, K=100.0, T=1.0, r=0.05,
    alpha=0.2, beta=1.0, rho=-0.3, nu=0.4,
    option_type="call",
)
print(f"SABR call price: {price:.5f}")

API reference

price_sabr_option(S0, K, T, r, alpha, beta, rho, nu, ...) -> (price, V, S, v)

High-level pricer. Builds the (S, v, t) grid, runs the Douglas-ADI sweeps, and bilinearly interpolates the value at (S0, alpha).

Parameter Type Description
S0 float Initial asset price
K float Strike
T float Time to maturity (years)
r float Risk-free rate
alpha float Initial SABR vol level (>0)
beta float CEV exponent in [0, 1]
rho float Correlation in [-1, 1]
nu float Vol-of-vol (>0)
M, L, N int Grid points in S, v, t (default 80 / 40 / 80)
S_max, v_max float, optional Domain bounds (sensible defaults)
option_type str "call" or "put"
theta float ADI weight; 0.5 is second-order accurate
verbose bool Print per-step progress

Returns:

Field Type Description
price float Bilinearly-interpolated value at (S0, alpha)
V (M+1, L+1) array Full price surface at t = 0
S (M+1,) array Asset-price grid
v (L+1,) array Volatility grid

ADISolver(sabr, grid, K, r, T, option_type)

Lower-level access. Call solve(theta=0.5, verbose=False) to get the full (V, S, v) surface — useful when you need the surface, not just one interpolated price.

1-D Black–Scholes solvers

In finite_difference/solvers/. Each takes (S_max, K, r, sigma, T, M, N, option_type) and returns (S, V) at t = 0.

Function Module Notes
solve_explicit explicit CFL-limited; fastest per step
solve_implicit implicit Unconditionally stable, O(Δt)
solve_crank_nicolson crank_nicolson Unconditionally stable, O(Δt²)
solve_american american American put via projected CN

bs_price(S, K, T, r, sigma, option_type) -> float

Closed-form Black–Scholes price; the validation reference for the SABR solver in its β = 1, ν → 0 limit.

License

MIT.

Demo notebook

Full SABR/ADI tutorial — derivation, solver, surface plots, convergence study, parity check, parameter sensitivity, and the implied-volatility smile — is in notebooks/07_sabr_adi.ipynb.

Open In Colab

Metadata

Release files for mafn-finite-difference 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mafn-finite-difference 0.2.0
File Size Uploaded
mafn_finite_difference-0.2.0.tar.gz 22.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for mafn-finite-difference 0.2.0
File Interpreter ABI Platform
mafn_finite_difference-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 42.5 kB

Release files / mafn_finite_difference-0.2.0.tar.gz

Download URL mafn_finite_difference-0.2.0.tar.gz
Size 22.8 kB
Tags Source
SHA-256 checksum
How to use checksums
76177f31a13cfe970433dcf972f407396d0a495ea6f06b5e4b6ade002fb0c75d
BLAKE2b-256 checksum
How to use checksums
19691d3f9d11ee2acc6bdcc6a9768c265b8922bc1eb466636f13829086ad1573
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.3

Release files / mafn_finite_difference-0.2.0-py3-none-any.whl

Download URL mafn_finite_difference-0.2.0-py3-none-any.whl
Size 19.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
945c3fa9f6565b26ed6d94e94d3c45d1d7b66a636d4d761000c669f221e02cda
BLAKE2b-256 checksum
How to use checksums
1abd6cb511f34438e973b3e03411a4ac943e813a2e547741d26c032f09f9e380
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.3

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page