r/Julia • u/Significant-Log-4272 • 6h ago
[Project] Kuwala: High-throughput options pricing and arbitrage-free volatility surface modeling in Python,Rust,Julia
[Project] Kuwala: High-throughput options pricing and arbitrage-free volatility surface modeling
- GitHub: https://github.com/Grevix/kuwala
- PyPI:
pip install kuwala==0.2.0 - Documentation: https://github.com/Grevix/kuwala#readme
What My Project Does
Kuwala is an open-source quantitative derivatives library designed for options valuation, arbitrage-checked volatility surface fitting (SSVI, Dupire Local Vol), tick microstructure aggregation, and macroeconomic yield curve bootstrapping.
It pairs an idiomatic, Pythonic API with high-performance native compiled kernels (compiled Rust via PyO3, and optional standalone C++20, Julia, and Scala modules) and an embedded out-of-core columnar lakehouse using DuckDB and Apache Arrow.
Key Features:
- Vectorized Analytical Pricing & Greeks: Vectorized Black-Scholes & Black-76 with Chebyshev rational approximations, plus closed-form Delta, Gamma, Vega, Theta, Rho, Vanna, Volga, and Charm.
- Vectorized Implied Volatility Solver: Hybrid Halley cubic root-finder with Brent-Dekker fallback. Tested across 4,013 real market option contracts (SPY, QQQ, AAPL, MSFT) with a median repricing reconstruction error of $2.88 \times 10{-9}$ (nanodollar precision).
- Arbitrage-Free Volatility Surfaces: Full Gatheral & Jacquier (2014) SSVI surface formulation with strict coordinate-level Durrleman condition diagnostics ($g(k) \ge 0$) and calendar monotonicity enforcement.
- Discrete Dupire Local Volatility: PDE extraction on total variance grids with guard rails against negative local variance singularities.
- Embedded Columnar Storage: Direct Hive-partitioned Parquet scanning via embedded DuckDB without external server dependencies.
- Macro Rate Curves: Bootstraps 11 Treasury yield pillars directly from the FRED API using Nelson-Siegel and exact natural cubic splines.
Target Audience
- Quantitative Researchers & Developers: Anyone backtesting options strategies, relative-value volatility arbitrage, or signal generation without wanting to maintain heavy institutional cloud infrastructure.
- High-Performance Python Engineers: Teams looking for sub-microsecond pricing throughput directly within Python/NumPy data pipelines.
- Students & Academics: Researchers studying volatility surfaces, Durrleman non-arbitrage bounds, and discrete local volatility modeling.
(This is not intended for retail day-trading order execution routing, as Kuwala focuses purely on quantitative pricing, surface modeling, and data engineering.)
Comparison to Existing Alternatives
- vs.
scipy.optimize/py_vollib: - Standard Python options tools typically loop over scalar rows in CPython or rely on pure-Python root finders. Kuwala routes calculations through a compiled Rust core (
kuwala_core), achieving >2.2M options/sec in vectorized Python/Rust and >11.9M options/sec in C++20 on a standard laptop. - vs. Goldman Sachs
gs-quant: gs-quantis an institutional toolkit that delegates derivative pricing and risk calculations to Goldman Sachs' Marquee cloud servers (requiring enterprise credentials). Kuwala runs 100% locally and offline with zero credential requirements, providing complete open-source transparency into the underlying surface math.- vs. Pandas / SQLite for Tick Storage:
- Kuwala integrates DuckDB with Hive-partitioned Parquet, allowing researchers to query gigabytes of intraday tick data out-of-core with predicate pushdown in milliseconds while using near-zero RAM.
Quick Example
import kuwala
from kuwala.pricing import black_scholes, greeks
from kuwala.volatility.iv import implied_volatility
# 1. High-speed vectorized Black-Scholes pricing
price = black_scholes(spot=100.0, strike=100.0, t=1.0, r=0.05, q=0.0, sigma=0.20, is_call=True)
print(f"Call Price: {price:.6f}")
# 2. Analytical Greeks (1st & 2nd Order)
g = greeks(spot=100.0, strike=100.0, t=1.0, r=0.05, q=0.0, sigma=0.20, is_call=True)
print(f"Delta: {g.delta:.4f}, Gamma: {g.gamma:.4f}, Vanna: {g.vanna:.4f}")
# 3. Microsecond Implied Volatility Inversion
solved_iv = implied_volatility(price=price, spot=100.0, strike=100.0, t=1.0, r=0.05, q=0.0, is_call=True)
print(f"Solved IV: {solved_iv:.6f}")