Fast options pricing and yield curve library written in Rust, usable from Python.
Price options and build yield curves instantly - optimized to price thousands of options in milliseconds.
- Options Pricing: European and American options with Black-Scholes and binomial trees
- Greeks: Delta, Gamma, Vega, Theta, Rho for risk management
- Yield Curves: Build interest rate curves from bond prices with multiple interpolation methods
- Batch Processing: Price thousands of options at once (very fast)
This project uses uv - a fast Python package manager that handles everything.
# 1. Install uv (if you don't have it)
curl -LsSf https://astral.sh/uv/install.sh | sh
# 2. Install Rust (needed to build the library)
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
# 3. Clone and setup
git clone https://github.com/aedan-chiari/rust-quant.git
cd rust-quant
# 4. Let uv do everything (creates venv, installs deps, builds Rust code)
uv syncThat's it! uv sync automatically:
- Creates a Python virtual environment
- Installs all Python dependencies
- Compiles the Rust extension
- Installs the library
# Run a quick test
uv run python -c "from rust_quant import EuroCallOption; print(EuroCallOption(100,100,1,0.05,0.2).price())"
# Should print: 10.450583572185565# Run Python scripts with uv
uv run python examples/01_basic_single_option.py
# Or activate the virtual environment
source .venv/bin/activate # macOS/Linux
python examples/01_basic_single_option.pyfrom rust_quant import EuroCallOption
# Price a European call option
call = EuroCallOption(
spot=100.0, # Stock price
strike=105.0, # Strike price
time_to_expiry=1.0, # 1 year
risk_free_rate=0.05, # 5%
volatility=0.2 # 20% volatility
)
print(f"Price: ${call.price():.2f}")
print(f"Delta: {call.delta():.4f}")
# Price many options at once (fast batch processing)
spots = [100.0] * 100000
strikes = [95.0] * 100000
times = [1.0] * 100000
rates = [0.05] * 100000
vols = [0.2] * 100000
prices = EuroCallOption.price_many(spots, strikes, times, rates, vols)from rust_quant import AmericanPutOption
# American options can be exercised early
put = AmericanPutOption(
spot=100.0,
strike=110.0,
time_to_expiry=1.0,
risk_free_rate=0.05,
volatility=0.3,
steps=100 # Tree steps (more = more accurate)
)
print(f"American Put: ${put.price():.2f}")from rust_quant import Security, ZeroCouponCurve
# Build a yield curve from bond prices
securities = [
Security(maturity=1.0, price=95.0), # 1-year bond
Security(maturity=2.0, price=90.0), # 2-year bond
Security(maturity=5.0, price=80.0), # 5-year bond
]
curve = ZeroCouponCurve(securities)
# Extract interest rates
rate_1y = curve.zero_rate(1.0)
rate_5y = curve.zero_rate(5.0)
print(f"1Y rate: {rate_1y * 100:.2f}%")
print(f"5Y rate: {rate_5y * 100:.2f}%")
# Get discount factors for pricing
discount_1y = curve.discount_factor(1.0)
discount_5y = curve.discount_factor(5.0)- Written in Rust: No Python overhead, compiled to native code
- SIMD: Uses CPU vector instructions to process 4 options at once
- Parallel: Spreads work across all CPU cores automatically
- Memory Efficient: No allocations in hot loops
Benchmark: Price 100,000 options
- Pure Python: ~5 seconds
- This library: ~50 milliseconds (100x faster)
See examples/ for complete working examples:
01_basic_single_option.py- Options pricing basics02_multiple_options_vectorized.py- Batch pricing05_american_options_example.py- American options07_zero_coupon_curve.py- Yield curves
MIT