pathwise
High-performance SDE simulation toolkit: Rust core, Python API.
Overview
pathwise provides composable, high-performance SDE simulation in Python backed by a Rust core. Paths are returned as NumPy arrays with shape (n_paths, n_steps+1) for scalar processes and (n_paths, n_steps+1, N) for N-dimensional processes. Built-in processes (bm, gbm, ou, cir, heston, corr_ou) execute in parallel via Rayon with the GIL released; custom Python callables run serially.
Key differentiator: pathwise ships a Taylor 1.5 (SRI) strong-order 1.5 scheme alongside standard Euler and Milstein, and extends to geodesic SDE simulation on Riemannian manifolds via the pathwise-geo crate.
Install
pip install pathwise-sde
Build from source:
git clone https://github.com/alejandro-soto-franco/pathwise.git
cd pathwise
pip install maturin
python -m venv .venv && source .venv/bin/activate
maturin develop
Quick start
import pathwise as pw
# 10,000 GBM paths, 252 daily steps, Euler-Maruyama
paths = pw.simulate(
pw.gbm(mu=0.05, sigma=0.2),
scheme=pw.euler(),
n_paths=10_000,
n_steps=252,
t1=1.0,
x0=100.0,
)
# paths: np.ndarray shape (10_000, 253), includes t=0
# Milstein scheme (strong order 1 on state-dependent diffusion)
paths = pw.simulate(
pw.gbm(0.05, 0.4),
pw.milstein(),
n_paths=5_000,
n_steps=500,
t1=1.0,
x0=1.0,
)
# SRI scheme (strong order 1.5, Kloeden-Platen Taylor 1.5)
paths = pw.simulate(
pw.gbm(0.05, 0.2),
pw.sri(),
n_paths=5_000,
n_steps=252,
t1=1.0,
x0=1.0,
)
# Cox-Ingersoll-Ross (requires Feller condition: 2*kappa*theta > sigma^2)
paths = pw.simulate(
pw.cir(kappa=1.0, theta=0.04, sigma=0.1),
pw.euler(),
n_paths=5_000,
n_steps=252,
t1=1.0,
x0=0.04,
)
# Heston stochastic volatility
# x0 = log(S0); initial variance defaults to theta
# returns shape (n_paths, n_steps+1, 2): [:,:,0] = log-price, [:,:,1] = variance
paths = pw.simulate(
pw.heston(mu=0.05, kappa=2.0, theta=0.04, xi=0.3, rho=-0.7),
pw.euler(),
n_paths=5_000,
n_steps=252,
t1=1.0,
x0=0.0, # log(S0) = log(1.0) = 0
)
log_price = paths[:, :, 0]
variance = paths[:, :, 1]
API reference
Processes
| Function | SDE | Notes |
|---|---|---|
pw.bm() |
$dX = dW$ | Standard Brownian motion |
pw.gbm(mu, sigma) |
$dX = \mu X,dt + \sigma X,dW$ | Geometric Brownian motion |
pw.ou(theta, mu, sigma) |
$dX = \theta(\mu - X),dt + \sigma,dW$ | Ornstein-Uhlenbeck |
pw.cir(kappa, theta, sigma) |
$dX = \kappa(\theta - X),dt + \sigma\sqrt{X},dW$ | Cox-Ingersoll-Ross; raises ValueError if Feller violated |
pw.heston(mu, kappa, theta, xi, rho) |
coupled log-price + CIR variance | Returns (n_paths, n_steps+1, 2) array |
pw.corr_ou(theta, mu_vec, sigma_flat) |
N-dim correlated OU | mu_vec: list of length N; sigma_flat: flattened N×N covariance; Python bindings: N=2 only |
pw.sde(drift, diffusion) |
$dX = f(X,t),dt + g(X,t),dW$ | Custom Python callables, runs serially |
Schemes
| Function | Strong order | Weak order | Notes |
|---|---|---|---|
pw.euler() |
$\tfrac{1}{2}$ | $1$ | Euler-Maruyama |
pw.milstein() |
$1$ | $1$ | Requires diffusion gradient |
pw.sri() |
$\tfrac{3}{2}$ | $2$ | Kloeden-Platen Taylor 1.5; not supported for Heston or CorrOU |
simulate
pw.simulate(
sde, # SDE object (bm, gbm, ou, cir, heston, corr_ou, or custom sde())
scheme, # euler(), milstein(), or sri()
n_paths, # number of independent paths (int)
n_steps, # time steps per path (int)
t1, # end time (float)
x0=0.0, # initial value (float)
# for Heston: x0 = log(S0); initial variance = theta
t0=0.0, # start time (float)
device="cpu", # "cpu" only in v0.2
) -> np.ndarray
# Scalar SDE: shape (n_paths, n_steps + 1)
# N-dim SDE: shape (n_paths, n_steps + 1, N)
# Heston N=2: [:,:,0] = log-price, [:,:,1] = variance
Parameter notes:
x0for Heston islog(S0), notS0. To simulate starting from price 100, passx0=math.log(100).sigma_flatforcorr_ouis the covariance matrix (not correlation) laid out in row-major order. For N=2 pass[var1, cov12, cov12, var2].- SRI raises
ValueErrorif used withhestonorcorr_ou. - CIR raises
ValueError(message contains "Feller") if2 * kappa * theta <= sigma ** 2.
Exceptions
pw.NumericalDivergence # reserved; non-finite values are stored as NaN
pw.ConvergenceError # raised on inference failures (future versions)
# ValueError # raised by cir (Feller), sri+heston, sri+corr_ou
Numerical validation
The test suite verifies convergence orders against analytic benchmarks:
- Euler strong order measured at 0.49 (expected $\tfrac{1}{2}$) on GBM via common-noise regression
- Milstein strong order measured at 0.98 (expected $1$) on GBM
- SRI strong order measured at ~1.5 (expected $\tfrac{3}{2}$) on GBM
- GBM mean/variance match $\mathbb{E}[X_T] = x_0 e^{\mu T}$ and the exact second moment formula
- OU conditional moments match analytic formulas
- CIR non-negativity verified; moments checked against closed-form
- BM increments pass Kolmogorov-Smirnov normality test ($\mathcal{N}(0, \Delta t)$)
- BM quadratic variation converges to $T$
- GBM log-normality verified via KS test on $\log X_T$
- European call price matches Black-Scholes within 1%
Run the full suite:
cargo test -p pathwise-core # Rust unit and integration tests
cargo test -p pathwise-core --test convergence
pytest tests/ # Python API and numerical tests
pathwise-geo (Rust only)
pathwise-geo is a companion crate for geodesic SDE simulation on Riemannian manifolds, backed by the cartan geometry library.
Supported manifolds: $S^n$ (hypersphere), $SO(n)$ (rotation group), $SPD(n)$ (symmetric positive-definite matrices).
Schemes: GeodesicEuler, GeodesicMilstein, GeodesicSRI.
Add to your Cargo.toml:
[dependencies]
pathwise-geo = "0.2"
Python bindings for pathwise-geo are planned for v0.3. See the crate docs for the Rust API.
Roadmap
| Version | Status | Items |
|---|---|---|
| v0.1 | released | Euler, Milstein; BM, GBM, OU; custom Python SDEs |
| v0.2 | released | SRI (Taylor 1.5); CIR, Heston, CorrOU; pathwise-geo (geodesic SDEs on S^n/SO(n)/SPD(n)) |
| v0.3 | planned | Python bindings for pathwise-geo; fractional BM; Volterra SDEs |
| v0.4 | planned | CUDA GPU acceleration |
| v0.5 | planned | MLE inference, particle filter |
| v0.6 | planned | Rough Heston / rough Bergomi surface calibration |
| v1.0 | planned | Stable API, JOSS paper |
License
MIT
Metadata
Release files for pathwise-sde 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| pathwise_sde-0.2.0.tar.gz | 39.4 kB | Details |
Built distributions (wheels)
| File | Reset | |||
|---|---|---|---|---|
| pathwise_sde-0.2.0-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl | PyPy 3.11 | PyPy 3.11 7.3 | Linux glibc 2.17+ x86-64 | Details |
| pathwise_sde-0.2.0-pp310-pypy310_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl | PyPy 3.10 | PyPy 3.10 7.3 | Linux glibc 2.17+ ARM64 | Details |
| pathwise_sde-0.2.0-cp310-abi3-win_amd64.whl | CPython 3.10 | abi3 | Windows x86-64 | Details |
| pathwise_sde-0.2.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl | CPython 3.10 | abi3 | Linux glibc 2.17+ x86-64 | Details |
| pathwise_sde-0.2.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl | CPython 3.10 | abi3 | Linux glibc 2.17+ ARM64 | Details |
| pathwise_sde-0.2.0-cp310-abi3-macosx_11_0_arm64.whl | CPython 3.10 | abi3 | macOS 11.0+ ARM64 | Details |
| pathwise_sde-0.2.0-cp310-abi3-macosx_10_12_x86_64.whl | CPython 3.10 | abi3 | macOS 10.12+ x86-64 | Details |
Total release size: 3.0 MB
Release files / pathwise_sde-0.2.0.tar.gz
| Download URL | pathwise_sde-0.2.0.tar.gz |
|---|---|
| Size | 39.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
25ae3b0a7724bd294d35479929ba6dcc3b1aa1aa43848ad4ef786e45591ed9fc
|
|
BLAKE2b-256 checksum How to use checksums |
add90611a0e36df0f111b47c56379fb1aaa5fef74b48d09eb37b964ae4a42447
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Mar 25, 2026.
Transparency logRelease files / pathwise_sde-0.2.0-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | pathwise_sde-0.2.0-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 455.1 kB |
| Tags | Linux glibc 2.17+ x86-64 PyPy 3.11 PyPy 3.11 7.3 |
|
SHA-256 checksum How to use checksums |
db1f389857501dc60ccf6e4a60cbf1f3c9aeb1e740f5b7ba01f984c6ef1f06ee
|
|
BLAKE2b-256 checksum How to use checksums |
3330f4b2ae5511ca3dc43d18775d04e4ec64e17d5d26c6ee67e94150750a1465
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Mar 25, 2026.
Transparency logRelease files / pathwise_sde-0.2.0-pp310-pypy310_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
| Download URL | pathwise_sde-0.2.0-pp310-pypy310_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl |
|---|---|
| Size | 448.8 kB |
| Tags | Linux glibc 2.17+ ARM64 PyPy 3.10 PyPy 3.10 7.3 |
|
SHA-256 checksum How to use checksums |
b0227c6b01bd61d96c17586328412e8cb8d277ca2eccf024cdee010b903df401
|
|
BLAKE2b-256 checksum How to use checksums |
a8509a1716a21b58747e2ef3a741a03fdfa83acdd86c853a6bc2239b172f09cd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Mar 25, 2026.
Transparency logRelease files / pathwise_sde-0.2.0-cp310-abi3-win_amd64.whl
| Download URL | pathwise_sde-0.2.0-cp310-abi3-win_amd64.whl |
|---|---|
| Size | 303.6 kB |
| Tags | CPython 3.10 Windows x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
7caa371dbc4ec4514006e4bd2c9c7b6f5d1cc75f1dafb2871f49b6c762014c00
|
|
BLAKE2b-256 checksum How to use checksums |
9dcd1021659e97031e398ce34db1ccc2d0988e3f00c54d637510a9b7a7e2e54a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Mar 25, 2026.
Transparency logRelease files / pathwise_sde-0.2.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | pathwise_sde-0.2.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 457.9 kB |
| Tags | CPython 3.10 Linux glibc 2.17+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
70893ef2a2e9c258293bc9a34835e22c244c4e45415b11fadac51bbeb04b5fb3
|
|
BLAKE2b-256 checksum How to use checksums |
72e802f36746301c48db72aa89e7a495ff08d002df4dbbbb7cc5d39c5b825d36
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Mar 25, 2026.
Transparency logRelease files / pathwise_sde-0.2.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
| Download URL | pathwise_sde-0.2.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl |
|---|---|
| Size | 448.5 kB |
| Tags | CPython 3.10 Linux glibc 2.17+ ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
3ca4b8459e035b9d38e471213fab678423e3a636e4b4d62cb7cd55d2f1e50c42
|
|
BLAKE2b-256 checksum How to use checksums |
6192b6936285bc34f364bcbad27ee9147f2364bf1950e8954f36151620ecb895
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Mar 25, 2026.
Transparency logRelease files / pathwise_sde-0.2.0-cp310-abi3-macosx_11_0_arm64.whl
| Download URL | pathwise_sde-0.2.0-cp310-abi3-macosx_11_0_arm64.whl |
|---|---|
| Size | 403.1 kB |
| Tags | CPython 3.10 abi3 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
345b362fa5fd0ed26a4db5485b1e96a499d35222544480e10988be7fdeb760c5
|
|
BLAKE2b-256 checksum How to use checksums |
a2716239d6b0c0e0f192a0d4432c6ecd9064857927813b54a4b02a3267aa9656
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Mar 25, 2026.
Transparency logRelease files / pathwise_sde-0.2.0-cp310-abi3-macosx_10_12_x86_64.whl
| Download URL | pathwise_sde-0.2.0-cp310-abi3-macosx_10_12_x86_64.whl |
|---|---|
| Size | 411.8 kB |
| Tags | CPython 3.10 abi3 macOS 10.12+ x86-64 |
|
SHA-256 checksum How to use checksums |
45c64c9fb33089847fa6b1f096e38e3ca5c0fd73a13f129b469405022de3f691
|
|
BLAKE2b-256 checksum How to use checksums |
645013e65c6061b452c39873268fd8e377ce34ca98594bdc736c4537f3e2dc82
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Mar 25, 2026.
Transparency log