Skip to main content

QuantForge

日本語 | English

Python Version License: MIT Rust

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

Features • Installation • Quick Start • Benchmarks • Documentation


📖 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

Metadata

Release files for quantforge 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for quantforge 0.1.1
File Size Uploaded
quantforge-0.1.1.tar.gz 123.5 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for quantforge 0.1.1
File
quantforge-0.1.1-cp312-abi3-win_amd64.whl CPython 3.12 abi3 Windows x86-64 Details
quantforge-0.1.1-cp312-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.12 abi3 Linux glibc 2.17+ x86-64 Details
quantforge-0.1.1-cp312-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl CPython 3.12 abi3 Linux glibc 2.17+ ARM64 Details
quantforge-0.1.1-cp312-abi3-macosx_11_0_arm64.whl CPython 3.12 abi3 macOS 11.0+ ARM64 Details
quantforge-0.1.1-cp312-abi3-macosx_10_12_x86_64.whl CPython 3.12 abi3 macOS 10.12+ x86-64 Details

Total release size: 9.3 MB

Release files / quantforge-0.1.1.tar.gz

Download URL quantforge-0.1.1.tar.gz
Size 123.5 kB
Tags Source
SHA-256 checksum
How to use checksums
73d6b271662b94a97c0918acf61d16d6afd6dc393eeccd0b3ba954ed7f7c5ce9
BLAKE2b-256 checksum
How to use checksums
bfc905191306790e648aa54984fc32f498871795a1a7a419f899b06d4c65b3b9
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 Sep 26, 2025.

Transparency log

Release files / quantforge-0.1.1-cp312-abi3-win_amd64.whl

Download URL quantforge-0.1.1-cp312-abi3-win_amd64.whl
Size 1.8 MB
Tags CPython 3.12 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
b0d3117f9069d97255d5c4fa51dd457777ef0968375f8b4dde4b19eea53aae8c
BLAKE2b-256 checksum
How to use checksums
6713d1daeed7971a6fcd7e676746ebe2ce725666e03f93e89910f4308be66e08
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 Sep 26, 2025.

Transparency log

Release files / quantforge-0.1.1-cp312-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL quantforge-0.1.1-cp312-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 2.1 MB
Tags CPython 3.12 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
ebb26f0648cb3d490f321356e27a98883513cb7891aa122e8e4848fd11436974
BLAKE2b-256 checksum
How to use checksums
8eb7da3bf36b3c0d0553e10567608e5b029e7af5492781a5972b653c88ef6c2d
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 Sep 26, 2025.

Transparency log

Release files / quantforge-0.1.1-cp312-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL quantforge-0.1.1-cp312-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 1.8 MB
Tags CPython 3.12 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
59c1a3b42e650784fd5dba6817b54a8c41da94b2c1cdf70e76c027fe7e424ce5
BLAKE2b-256 checksum
How to use checksums
e0e07bd05d5244853ac4133ce3bab1fe28f30dacbc53ebc0d9cffbfbc1f79e38
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 Sep 26, 2025.

Transparency log

Release files / quantforge-0.1.1-cp312-abi3-macosx_11_0_arm64.whl

Download URL quantforge-0.1.1-cp312-abi3-macosx_11_0_arm64.whl
Size 1.7 MB
Tags CPython 3.12 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
60f02615743e660cca9db6de5d49cab284b56da1323755a12382b8682e299087
BLAKE2b-256 checksum
How to use checksums
95079de3683f50f9898037939bb5a4acf478420da951dabee599da6e1ba285b1
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 Sep 26, 2025.

Transparency log

Release files / quantforge-0.1.1-cp312-abi3-macosx_10_12_x86_64.whl

Download URL quantforge-0.1.1-cp312-abi3-macosx_10_12_x86_64.whl
Size 1.9 MB
Tags CPython 3.12 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
fa2a8b656b860130607c6a4d0078585f61ff4b32f9369aa6358d1ab7f9c67694
BLAKE2b-256 checksum
How to use checksums
bdac9e8e551307c6b1decbbe34d07d51246c9cedcf1f30f6371686b01f4efad2
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 Sep 26, 2025.

Transparency log

Release history Release notifications | RSS feed

This release

0.1.1 This release

6 release files

0.1.0

6 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page