Skip to main content

High-performance option pricing library powered by Rust + PyO3

Project description

QuantForge

日本語 | English

Python Version License: MIT Rust

Rust-Powered Option Pricing Library — Up to 1x Faster than NumPy+SciPy

FeaturesInstallationQuick StartBenchmarksDocumentation


📖 Overview

QuantForge is a high-performance option pricing library implemented in Rust with Python bindings via PyO3. It provides Black-Scholes based pricing, Greeks calculation, and implied volatility computation with Rust's performance while maintaining Python's ease of use.

📋 Features and Implementation

Option Pricing Models

QuantForge supports multiple option pricing models optimized for various asset classes:

  • Black-Scholes: European options on stocks
  • American Options: Early exercise options with Bjerksund-Stensland (2002) approximation
  • Merton: Options on dividend-paying assets
  • Black76: Commodity and futures options
  • Asian Options (coming soon): Path-dependent options
  • Spread Options (coming soon): Multi-asset options
  • Garman-Kohlhagen (coming soon): FX options

Core Features

  • High Performance: Up to 1x faster than NumPy+SciPy, 1x faster than Pure Python
  • 🎯 Machine Precision: erf-based implementation achieving <1e-15 accuracy
  • 📊 Complete Greeks: Delta, Gamma, Vega, Theta, Rho plus model-specific Greeks (Dividend Rho, Early Exercise Boundary)
  • 🔥 Implied Volatility: Newton-Raphson solver up to 170x faster than Pure Python
  • 🚀 Auto-Parallelization: Automatic Rayon parallelization for batches >30,000 elements
  • 📦 Zero-Copy Design: Direct NumPy array access eliminating memory copy overhead
  • Robustness: 250+ golden master tests with comprehensive coverage
  • 🔧 Production Ready: Input validation, edge case handling, Put-Call parity verified

📊 Performance Benchmark Results

Environment: Linux - 6 cores - 29.3GB RAM - Python 3.12.5 - 2025-09-12 12:47:56

Latest Benchmark Results

Benchmark data not found

Performance varies by environment. Values shown are medians of 5 runs. See benchmarks for details.

🔥 Implied Volatility Performance

Fair comparison using Newton-Raphson method (same algorithm and parameters):

Data Size QuantForge NumPy Newton Pure Python Max Speedup
Single 3.94 μs 180.86 μs 3.18 μs 45x
100 34.40 μs 937.50 μs 1.03 ms 30x
1,000 184.11 μs 1.33 ms 10.45 ms 56x
10,000 599.53 μs 4.28 ms 102.07 ms 170x

Maximum speedup: 170x vs Pure Python, 45x vs NumPy

📥 Installation

pip install quantforge

From Source (Development)

# Clone repository
git clone https://github.com/drillan/quantforge.git
cd quantforge

# Install Rust (if needed)
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

# Build and install
pip install maturin
maturin develop --release

Development Dependencies

# Using uv (recommended)
uv sync --group dev

# Or standard pip
pip install -e ".[dev]"

🚀 Quick Start

Basic Usage

import numpy as np
from quantforge.models import black_scholes

# Single option calculation
spot = 100.0   # Current price
strike = 110.0 # Strike price
time = 1.0     # Time to maturity (years)
rate = 0.05    # Risk-free rate
sigma = 0.2    # Volatility

# Call option price
call_price = black_scholes.call_price(spot, strike, time, rate, sigma)
print(f"Call Price: ${call_price:.4f}")

# Put option price
put_price = black_scholes.put_price(spot, strike, time, rate, sigma)
print(f"Put Price: ${put_price:.4f}")

# All Greeks calculation
greeks = black_scholes.greeks(spot, strike, time, rate, sigma, is_call=True)
print(f"Delta: {greeks.delta:.4f}")
print(f"Gamma: {greeks.gamma:.4f}")
print(f"Vega: {greeks.vega:.4f}")
print(f"Theta: {greeks.theta:.4f}")
print(f"Rho: {greeks.rho:.4f}")

Batch Processing (High Performance)

import numpy as np
from quantforge.models import black_scholes

# Generate 1 million random data points
n = 1_000_000
spots = np.random.uniform(80, 120, n)      # Uniform distribution 80-120
strikes = np.full(n, 100.0)                # Fixed strike
times = np.random.uniform(0.1, 2.0, n)     # 0.1-2 years
rates = np.full(n, 0.05)                   # Fixed rate
sigmas = np.random.uniform(0.1, 0.4, n)    # 10-40% volatility

# Batch processing (~56ms for 1M elements)
prices = black_scholes.call_price_batch(spots, strikes, times, rates, sigmas)

# Batch Greeks calculation
greeks = black_scholes.greeks_batch(spots, strikes, times, rates, sigmas, 
                                    is_call=np.full(n, True))

Implied Volatility Calculation

from quantforge.models import black_scholes

# Calculate implied volatility from market price
market_price = 12.50
iv = black_scholes.implied_volatility(
    price=market_price,
    s=100.0,  # Current price
    k=110.0,  # Strike price
    t=1.0,    # Time to maturity
    r=0.05,   # Risk-free rate
    is_call=True
)
print(f"Implied Volatility: {iv:.2%}")

🔄 Parallelization Optimization

QuantForge automatically balances computation and overhead by applying parallelization based on data size:

Data Size Processing Mode Notes
< 1,000 Single-threaded Avoid overhead
1,000 - 30,000 Multi-threaded (small) 2-4 threads
> 30,000 Fully parallel All available cores
import numpy as np
from quantforge.models import black_scholes

# Large data: Automatic parallelization (all cores)
large_spots = np.random.uniform(90, 110, 1_000_000)
large_prices = black_scholes.call_price_batch(large_spots, 100, 1.0, 0.05, 0.2)

# Small data: Single-threaded (avoid overhead)
small_spots = np.array([100, 105, 110])
small_prices = black_scholes.call_price_batch(small_spots, 100, 1.0, 0.05, 0.2)

📊 Benchmarks

Practical Scenario: Volatility Surface Construction (10×10 Grid)

Implementation Time vs QuantForge
QuantForge (parallel) 0.1 ms -
NumPy+SciPy (vectorized) 0.4 ms 4x slower
Pure Python (for loop) 5.5 ms 55x slower

Practical Scenario: 10,000 Option Portfolio Risk Calculation

Implementation Time vs QuantForge
QuantForge (parallel) 1.9 ms -
NumPy+SciPy (vectorized) 2.7 ms 1.4x slower
Pure Python (for loop, estimated) ~70 ms 37x slower

See performance benchmarks for detailed results.

🏗️ Architecture

quantforge/
├── src/                    # Rust core implementation
│   ├── models/            # Pricing models (Black-Scholes, Black76, Merton, etc.)
│   ├── math/              # Mathematical functions (erf, norm_cdf, etc.)
│   ├── validation.rs      # Input validation
│   └── traits.rs          # Batch processing traits
│
├── python/                 # Python bindings
│   └── quantforge/        # Python package
│       └── models/        # Model-specific modules
│
└── tests/                  # Test suite
    ├── unit/              # Unit tests
    ├── integration/       # Integration tests
    ├── golden_master/     # Golden master tests
    └── performance/       # Benchmark tests

Technology Stack

  • Rust 1.88+: Core computation engine
  • PyO3: Python-Rust bindings
  • Rayon: Data parallel processing
  • NumPy: Array interface
  • maturin: Build and packaging

📚 Documentation

🧪 Testing

# Run Python tests (450+ test cases)
pytest tests/

# Run Rust tests
cargo test --release

# Measure coverage
pytest tests/ --cov=quantforge --cov-report=html

# Run benchmarks
pytest tests/performance/ -m benchmark

🤝 Contributing

Pull requests are welcome! For major changes, please open an issue first to discuss what you would like to change.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

See Contributing Guide for details.

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.

🙏 Acknowledgments

  • QuantLib for implementation and validation data
  • Rayon project for high-speed parallel processing
  • PyO3 project for Python-Rust bindings

📮 Contact

For questions or suggestions, please open an issue or join our discussions.


Made with ❤️ by the QuantForge team

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

quantforge-0.1.0.tar.gz (110.9 kB view details)

Uploaded Source

Built Distributions

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

quantforge-0.1.0-cp312-abi3-win_amd64.whl (1.8 MB view details)

Uploaded CPython 3.12+Windows x86-64

quantforge-0.1.0-cp312-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.0 MB view details)

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

quantforge-0.1.0-cp312-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.7 MB view details)

Uploaded CPython 3.12+manylinux: glibc 2.17+ ARM64

quantforge-0.1.0-cp312-abi3-macosx_11_0_arm64.whl (1.6 MB view details)

Uploaded CPython 3.12+macOS 11.0+ ARM64

quantforge-0.1.0-cp312-abi3-macosx_10_12_x86_64.whl (1.9 MB view details)

Uploaded CPython 3.12+macOS 10.12+ x86-64

File details

Details for the file quantforge-0.1.0.tar.gz.

File metadata

  • Download URL: quantforge-0.1.0.tar.gz
  • Upload date:
  • Size: 110.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for quantforge-0.1.0.tar.gz
Algorithm Hash digest
SHA256 14db3f8379b7ff0aeef5f29724bf8cf91eeed352f14eaca7c3697ac58b7e9692
MD5 4a3675d908af23043e7d3b44a67087db
BLAKE2b-256 f7d988b4f5702a341c8d386084ee2c98353bf56c0dd7c955446c3a23271beae0

See more details on using hashes here.

Provenance

The following attestation bundles were made for quantforge-0.1.0.tar.gz:

Publisher: release.yml on drillan/quantforge

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

File details

Details for the file quantforge-0.1.0-cp312-abi3-win_amd64.whl.

File metadata

  • Download URL: quantforge-0.1.0-cp312-abi3-win_amd64.whl
  • Upload date:
  • Size: 1.8 MB
  • Tags: CPython 3.12+, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for quantforge-0.1.0-cp312-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 7c541505181682f0ba60db741424708618f807b6001d86e64300bdc8d52a278d
MD5 24d491eca18208a28edad387f43d3469
BLAKE2b-256 64887bb237f0db843ab9ff2e41f89ab2bf0cb61d38f093349678d105ab7f9247

See more details on using hashes here.

Provenance

The following attestation bundles were made for quantforge-0.1.0-cp312-abi3-win_amd64.whl:

Publisher: release.yml on drillan/quantforge

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

File details

Details for the file quantforge-0.1.0-cp312-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for quantforge-0.1.0-cp312-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 76303290abbd5d3ea38d19df7512893c7c99c4efafdd8fbfb88bff942b81b9ac
MD5 374f527b00e850d2e9495208c1723e37
BLAKE2b-256 e16b19002248f306e4df300756e695735b98de10817cde2994d390c64fff7664

See more details on using hashes here.

Provenance

The following attestation bundles were made for quantforge-0.1.0-cp312-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: release.yml on drillan/quantforge

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

File details

Details for the file quantforge-0.1.0-cp312-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for quantforge-0.1.0-cp312-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 377d880e239974c2ad3307ef8d65d3dca1a7b183820944f9829d9f7e7a8e5cc4
MD5 31e55f9707f6d38c0f359ca5bfc52f69
BLAKE2b-256 a8b471522a4f387fc8bbde70f75b62dcf4d3bf72a9d0bc06f5991478a0d8a48a

See more details on using hashes here.

Provenance

The following attestation bundles were made for quantforge-0.1.0-cp312-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: release.yml on drillan/quantforge

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

File details

Details for the file quantforge-0.1.0-cp312-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for quantforge-0.1.0-cp312-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 c527c7ae98d289e288090469f6f520e8e3c3f2ebe7110d6fb390ae2ababc64c7
MD5 bc51586b4b5406744b902475d368c0a0
BLAKE2b-256 5c0877ad07f1a3c66ce051f1bc208479be12601729ebe23571119847e62dd1ec

See more details on using hashes here.

Provenance

The following attestation bundles were made for quantforge-0.1.0-cp312-abi3-macosx_11_0_arm64.whl:

Publisher: release.yml on drillan/quantforge

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

File details

Details for the file quantforge-0.1.0-cp312-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for quantforge-0.1.0-cp312-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 00057c7e67b1bd798f52051b297fdcfd0fe0fb72bbe51e6e2afbec36b10bf447
MD5 c225962e8288a99fbed6d645b47af871
BLAKE2b-256 4793a1dc4d56dd71aa87d5bf6279726e1687ca07337c88e8984c8a1c78cb58f4

See more details on using hashes here.

Provenance

The following attestation bundles were made for quantforge-0.1.0-cp312-abi3-macosx_10_12_x86_64.whl:

Publisher: release.yml on drillan/quantforge

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