A high-performance, professional-grade (i tried) quantitative option pricing library with Numba and Cython optimizations.
Project description
OptionPricer
A high-performance, professional-grade (to the best of my ability) quantitative finance library for option pricing, optimized heavily via NumPy vectorization, Numba JIT, and Cython AOT compilation.
Development Journey & Architecture
This package was built systematically through strict, high-performance architectural phases:
-
Phase 1: NumPy Vectorization
- Eliminated slow Python loops in the core hot paths.
- Replaced scalar stock price reconstructions with precomputed power arrays, yielding a 3.7x baseline speedup on the binomial lattice.
-
Phase 2: Advanced Monte Carlo & Variance Reduction
- Implemented Sobol Quasi-Random sequences to ensure superior space-filling over standard pseudo-random engines.
- Introduced Antithetic Variates ($Z$ and $-Z$) and Control Variates (using terminal spot price correlation) to achieve up to 800x variance reduction, allowing high precision at drastically lower path counts.
-
Phase 3: Numba JIT Compilation
- Compiled the sequential backward-induction algorithms into machine code via LLVM.
- Handled Python's GIL overhead by isolating numerical loops inside pure-C equivalents, dropping execution time from 48ms down to 5ms for large $N$.
-
Phase 4: Cython Extensions & Pre-compiled Wheels
- Statically typed the core mathematical functions (
cdef,double[:]memoryviews) into an AOT compiled C-extension to completely eliminate runtime compilation warmup.
- Statically typed the core mathematical functions (
-
Phase 5: Algorithmic Routing
- Engineered smart heuristics for implied volatility. Routes to Peter Jäckel's 'Let's Be Rational' for standard Euro options, falls back to Newton-Raphson for near-ATM scenarios, and seamlessly redirects to SciPy's robust
brentqfor deep OTM/ITM and American edge cases.
- Engineered smart heuristics for implied volatility. Routes to Peter Jäckel's 'Let's Be Rational' for standard Euro options, falls back to Newton-Raphson for near-ATM scenarios, and seamlessly redirects to SciPy's robust
-
Phase 6: Professional Software Engineering
- Enforced strict dependency boundaries.
- Fully annotated with Python Type Hints and Google-style docstrings.
- Prepared for distribution via PyPA
buildandtwineCI/CD standards.
Performance Benchmarks
- Black-Scholes (Analytical): ~0.028 ms
- Implied Volatility (Brentq Solver): ~0.144 ms
- Binomial Tree (American, N=1000): ~0.362 ms
- Monte Carlo (Optimized, N=32,768): ~0.519 ms
- Binomial Tree (American, N=5000): ~6.766 ms
Usage
pip install optionpricer
from optionpricer import build_tree, monte_carlo_prices, implied_vol
# Price a 5,000-step American Put via Cython
price = build_tree(S=100, K=100, T=1, r=0.05, sigma=0.2, N=5000, option_type="put", american=True)
# Generate 32,000 variance-reduced Monte Carlo paths
mc_price = monte_carlo_prices(S=100, K=100, T=1, r=0.05, sigma=0.2)
Painstakingly written manual code :sob:
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file optionpricer-0.1.7.tar.gz.
File metadata
- Download URL: optionpricer-0.1.7.tar.gz
- Upload date:
- Size: 163.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bbcc28e8b898f7745c4bdf493610ef760821f0ff032f15c62abd5bc424a30ef2
|
|
| MD5 |
cbe103f1a50a28c23c4308d741fcf08d
|
|
| BLAKE2b-256 |
0258e209e98076af410c1cc906e762f8b6c818c299aaae3910030ba2378e7fee
|
File details
Details for the file optionpricer-0.1.7-cp313-cp313-macosx_10_13_universal2.whl.
File metadata
- Download URL: optionpricer-0.1.7-cp313-cp313-macosx_10_13_universal2.whl
- Upload date:
- Size: 309.3 kB
- Tags: CPython 3.13, macOS 10.13+ universal2 (ARM64, x86-64)
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
15d07753ed68390cc9606f3f12c4ac03d7e1affd238c3eb0c86fa8333bfde02e
|
|
| MD5 |
c4a79d786356665502d1b4080a9d1efd
|
|
| BLAKE2b-256 |
b3cdfff413bb9831d5672cf79e04793a6e6f9dd7bb005186b7af119886fe119b
|