Skip to main content

Bismut-Elworthy-Li Malliavin weights for Monte Carlo Greeks: Rust core, Python API

Project description

elworthy

crates.io docs.rs license

A Rust JIT compiler that specialises Bismut-Elworthy-Li formulas into SIMD kernels for unbiased Monte Carlo Greeks on non-stationary SDEs.

Named after K. David Elworthy, co-author of the Bismut-Elworthy-Li integration-by-parts formula:

$$ \partial_x \mathbb{E}[f(X_T) \mid X_0 = x] = \mathbb{E}\left[ f(X_T) \cdot \frac{1}{T} \int_0^T \sigma^{-1}(X_s)^\top , \partial_x X_s , \mathrm{d}W_s \right]. $$

elworthy takes a symbolic SDE, symbolically differentiates its coefficients, synthesises the Malliavin weight for a requested Greek, and lowers the entire inner-loop body (state update + weight accumulation + payoff) to a single kernel via Cranelift. Each SIMD lane carries one independent Monte Carlo path.

Status

v0.1. Ships:

  • Full scalar Cranelift JIT with exp, log, sin, cos, sqrt via libm.
  • 2-lane SIMD VectorKernel (Cranelift F64X2) covering every Fun variant per lane; F64X4 scaffolded behind the simd_avx2 feature flag with runtime CPU detection.
  • In-memory structural-hash kernel cache + disk-persisted AST cache at $XDG_CACHE_HOME/elworthy/.
  • Euler-Maruyama and Milstein discretisations for scalar SDEs; multi-dimensional Euler driver with full-truncation clamping for CIR/variance-type components.
  • Greek drivers:
    • Delta, constant-flow Bismut-Elworthy-Li (GBM / ABM).
    • Delta, general tangent-flow Bismut-Elworthy-Li (any scalar SDE).
    • Delta, multi-dim pathwise tangent flow (Heston and friends).
    • Rho, vega, and arbitrary parameter Greeks, pathwise (smooth payoffs, any scalar SDE).
    • Rho and vega for GBM via the likelihood-ratio Malliavin weight, valid for non-smooth payoffs (digitals, barriers); derivation machine-checked with SymPy.

Architecture

elworthy/
├── elworthy-expr/      symbolic AST, canonicalisation, CSE
├── elworthy-diff/      automatic symbolic differentiation
├── elworthy-weight/    Bismut-Elworthy-Li weight synthesis
├── elworthy-codegen/   Expr -> Cranelift IR lowering + scalar interpreter
├── elworthy-rt/        kernel cache, SIMD RNG, Monte Carlo driver
└── elworthy/           CLI + examples

Each subcrate has its own README.

Performance

On a development laptop (x86_64, single core, release profile):

Scenario throughput (M path-steps/s) speedup vs interpreter
GBM price, tree-walking interpreter 6.8 1.0x
GBM price, scalar Cranelift JIT 150 22x
GBM price, 2-lane SIMD JIT 187 27x
GBM price + Bismut-Elworthy-Li delta 152 22x
Heston price (2-D) 55 8x
Heston price + pathwise delta (2-D, full Jacobian) 16 2.3x

Kernel cache hit: 64 ns per retrieval vs ~100 us for a cold Cranelift compile, a 1500x speedup on calibration inner loops.

Cross-validation. The JIT+BEL stack is cross-validated against Black-Scholes closed form (inline, libm::erf) and the independent blackscholes crate (v0.24). On a European call at S_0 = K = 100, r = 0.05, sigma = 0.2, T = 1, 200 000 Milstein paths x 512 steps, elworthy's Monte Carlo price and Bismut-Elworthy-Li delta agree with both analytic references within four Monte Carlo standard errors. Full table in BENCHMARK.md.

Reproduce with:

cargo test --release -p elworthy-rt --test benchmark -- --nocapture --ignored

See BENCHMARK.md for full methodology, caveats, and reproducibility notes.

Install

cargo add elworthy-rt elworthy-expr

Or the CLI:

cargo install elworthy

Quick start (CLI)

elworthy gbm       --backend jit --paths 10000
elworthy gbm-delta --paths 40000

Expected output for gbm-delta at default parameters:

price   ~ 105.12xx (stderr 0.14xx) | closed form 105.1271
delta   ~   1.05xx (stderr 0.02xx) | closed form 1.0513   [Bismut-Elworthy-Li]

SELinux note (Fedora / RHEL)

The JIT backend requires execmem permission so Cranelift can map newly generated code as executable. Under SELinux enforcing this is denied by default for user binaries and you will see

Error: cranelift module error: Backend error: unable to make memory readable+executable

Workarounds:

  • Run via cargo test (the test harness domain already grants execmem).
  • Temporarily relax policy with sudo setsebool -P selinuxuser_execheap 1.
  • Use --backend interp for a JIT-free run.

Ubuntu, Debian, macOS, and most CI runners do not hit this restriction.

Next milestones

  • VectorKernel4 (AVX2 F64X4) behind the simd_avx2 feature.
  • General-SDE Malliavin parameter weight (without relying on a closed-form transition density).
  • Gamma via second-order Bismut-Elworthy-Li.
  • QuantLib reference benchmarks for Heston delta.

Licence

Apache License 2.0. See LICENSE.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

elworthy-0.1.2.tar.gz (71.9 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

elworthy-0.1.2-cp310-abi3-win_amd64.whl (160.4 kB view details)

Uploaded CPython 3.10+Windows x86-64

elworthy-0.1.2-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (898.6 kB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ x86-64

elworthy-0.1.2-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (837.8 kB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ ARM64

elworthy-0.1.2-cp310-abi3-macosx_11_0_arm64.whl (262.0 kB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

elworthy-0.1.2-cp310-abi3-macosx_10_12_x86_64.whl (270.1 kB view details)

Uploaded CPython 3.10+macOS 10.12+ x86-64

File details

Details for the file elworthy-0.1.2.tar.gz.

File metadata

  • Download URL: elworthy-0.1.2.tar.gz
  • Upload date:
  • Size: 71.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for elworthy-0.1.2.tar.gz
Algorithm Hash digest
SHA256 48148efad78433c267c38e28477f5a7c73426b86cfe4f07bee06464b0b7e7e43
MD5 eb37f8fe52b0cb67c68b9ae92e16843f
BLAKE2b-256 c4afae9750b70c777226c93854bb11e4cbf489079434a8430bea911f9f4c6772

See more details on using hashes here.

Provenance

The following attestation bundles were made for elworthy-0.1.2.tar.gz:

Publisher: release.yml on alejandro-soto-franco/elworthy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file elworthy-0.1.2-cp310-abi3-win_amd64.whl.

File metadata

  • Download URL: elworthy-0.1.2-cp310-abi3-win_amd64.whl
  • Upload date:
  • Size: 160.4 kB
  • Tags: CPython 3.10+, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for elworthy-0.1.2-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 a88534e0175fbd4980caca35a75c1f300cbafa171d80c2aabb1e08a24b3c6046
MD5 4a8e5641362459528cf94e7efeb31ea0
BLAKE2b-256 77e11fbe2e54a2be58a1e3ca1d99cc84f705c84baf11262e9b9518466a1f4bac

See more details on using hashes here.

Provenance

The following attestation bundles were made for elworthy-0.1.2-cp310-abi3-win_amd64.whl:

Publisher: release.yml on alejandro-soto-franco/elworthy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file elworthy-0.1.2-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for elworthy-0.1.2-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 9905c92efb4bc1c3422b41f0aee4ac751e9c868195e64d5862332c3ae7577d6e
MD5 d4ba2a3dba01046abdccf27f6f448e61
BLAKE2b-256 144c3f67a04d0834a648f0e77501483b18db96be0d3da858b5b22f8caa35f4a6

See more details on using hashes here.

Provenance

The following attestation bundles were made for elworthy-0.1.2-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: release.yml on alejandro-soto-franco/elworthy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file elworthy-0.1.2-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for elworthy-0.1.2-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 c54d57cea62008c68a164394ed7569e9c84c53733a32b2c95cdca249e8e1ae54
MD5 849ae3dcfd6853dfa1eef529dd53a089
BLAKE2b-256 ca5ef630aa82bfb915e253fbc8134f362ee79e3eb8d4452709e6aec4178bf22d

See more details on using hashes here.

Provenance

The following attestation bundles were made for elworthy-0.1.2-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: release.yml on alejandro-soto-franco/elworthy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file elworthy-0.1.2-cp310-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for elworthy-0.1.2-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 aa7c8574756da85e13408633222f97909fa23668f06cb56b2e2a95566b805030
MD5 f38c06be215ecfcdfcc00b46d8a5839a
BLAKE2b-256 0f36018f3a2f70e985571eb110769d153eef16be4426c5cbd97cf37006e06eec

See more details on using hashes here.

Provenance

The following attestation bundles were made for elworthy-0.1.2-cp310-abi3-macosx_11_0_arm64.whl:

Publisher: release.yml on alejandro-soto-franco/elworthy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file elworthy-0.1.2-cp310-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for elworthy-0.1.2-cp310-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 99a857dc21d6e6879ff676ddfc198596c8569bac2d45b3d054816921bb42a5c4
MD5 13fffba1b125a3c6679e2ef24fc56d9b
BLAKE2b-256 3030541194a53a92375f12da50d298e7054355a29d6ae4c01fa84e55aaa53052

See more details on using hashes here.

Provenance

The following attestation bundles were made for elworthy-0.1.2-cp310-abi3-macosx_10_12_x86_64.whl:

Publisher: release.yml on alejandro-soto-franco/elworthy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page