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.1.tar.gz (123.5 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.1-cp312-abi3-win_amd64.whl (1.8 MB view details)

Uploaded CPython 3.12+Windows x86-64

quantforge-0.1.1-cp312-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.1 MB view details)

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

quantforge-0.1.1-cp312-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.8 MB view details)

Uploaded CPython 3.12+manylinux: glibc 2.17+ ARM64

quantforge-0.1.1-cp312-abi3-macosx_11_0_arm64.whl (1.7 MB view details)

Uploaded CPython 3.12+macOS 11.0+ ARM64

quantforge-0.1.1-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.1.tar.gz.

File metadata

  • Download URL: quantforge-0.1.1.tar.gz
  • Upload date:
  • Size: 123.5 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.1.tar.gz
Algorithm Hash digest
SHA256 73d6b271662b94a97c0918acf61d16d6afd6dc393eeccd0b3ba954ed7f7c5ce9
MD5 486dab5f918fb872c5b811b0d2a59964
BLAKE2b-256 bfc905191306790e648aa54984fc32f498871795a1a7a419f899b06d4c65b3b9

See more details on using hashes here.

Provenance

The following attestation bundles were made for quantforge-0.1.1.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.1-cp312-abi3-win_amd64.whl.

File metadata

  • Download URL: quantforge-0.1.1-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.1-cp312-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 b0d3117f9069d97255d5c4fa51dd457777ef0968375f8b4dde4b19eea53aae8c
MD5 b8cc17e17bc475610e24906f5e09d36f
BLAKE2b-256 6713d1daeed7971a6fcd7e676746ebe2ce725666e03f93e89910f4308be66e08

See more details on using hashes here.

Provenance

The following attestation bundles were made for quantforge-0.1.1-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.1-cp312-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for quantforge-0.1.1-cp312-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 ebb26f0648cb3d490f321356e27a98883513cb7891aa122e8e4848fd11436974
MD5 247c941e0e85f658678a038c5cb5e4c5
BLAKE2b-256 8eb7da3bf36b3c0d0553e10567608e5b029e7af5492781a5972b653c88ef6c2d

See more details on using hashes here.

Provenance

The following attestation bundles were made for quantforge-0.1.1-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.1-cp312-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for quantforge-0.1.1-cp312-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 59c1a3b42e650784fd5dba6817b54a8c41da94b2c1cdf70e76c027fe7e424ce5
MD5 8becbebf12adce5a86304d1d1fd8569a
BLAKE2b-256 e0e07bd05d5244853ac4133ce3bab1fe28f30dacbc53ebc0d9cffbfbc1f79e38

See more details on using hashes here.

Provenance

The following attestation bundles were made for quantforge-0.1.1-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.1-cp312-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for quantforge-0.1.1-cp312-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 60f02615743e660cca9db6de5d49cab284b56da1323755a12382b8682e299087
MD5 085c685ea2856ee26fc03abeb6833c77
BLAKE2b-256 95079de3683f50f9898037939bb5a4acf478420da951dabee599da6e1ba285b1

See more details on using hashes here.

Provenance

The following attestation bundles were made for quantforge-0.1.1-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.1-cp312-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for quantforge-0.1.1-cp312-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 fa2a8b656b860130607c6a4d0078585f61ff4b32f9369aa6358d1ab7f9c67694
MD5 9e882e58e75bace533400323641fc8d9
BLAKE2b-256 bdac9e8e551307c6b1decbbe34d07d51246c9cedcf1f30f6371686b01f4efad2

See more details on using hashes here.

Provenance

The following attestation bundles were made for quantforge-0.1.1-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