PyQuantLib provides Python bindings for QuantLib, the open-source library for quantitative finance. Built with pybind11, it offers a more Pythonic API than existing alternatives.
- Pythonic API: Pass Python objects directly to functions (implicit conversion)
- Zero-copy NumPy: Buffer protocol for efficient, bidirectional data exchange
- Type hints: IDE-friendly with complete
.pyistub files - Python subclassing: Extend QuantLib classes without C++ recompilation
- Modern build: scikit-build-core, CMake presets, cross-platform CI/CD
pip install pyquantlibPre-built wheels are available for Python 3.10--3.13 on Linux (x86_64), macOS (ARM), and Windows (x64). QuantLib is statically linked -- no separate installation required.
Building from source requires QuantLib built with specific CMake flags. See CONTRIBUTING.md for detailed instructions.
- Python 3.10+
- CMake 3.18+
- C++17 compatible compiler
- Boost headers
- QuantLib 1.40+ built with
std::shared_ptrsupport (see below)
Important: PyQuantLib requires QuantLib built from source with specific settings.
Required CMake flags:
cmake -DBUILD_SHARED_LIBS=OFF \
-DCMAKE_POSITION_INDEPENDENT_CODE=ON \
-DQL_USE_STD_SHARED_PTR=ON \
-DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreadedDLL \ # Windows only
-DCMAKE_BUILD_TYPE=Release \
...| Flag | Why Required |
|---|---|
BUILD_SHARED_LIBS=OFF |
Static build prevents Settings singleton issues on Linux/macOS |
CMAKE_POSITION_INDEPENDENT_CODE=ON |
Required for static libs in Python modules |
QL_USE_STD_SHARED_PTR=ON |
pybind11 uses std::shared_ptr as default holder |
CMAKE_MSVC_RUNTIME_LIBRARY=MultiThreadedDLL |
Windows only: Python extensions require dynamic runtime (/MD) |
Note: Pre-built packages (Homebrew, vcpkg, apt) use shared builds and boost::shared_ptr -- they are not compatible. You must build QuantLib from source. See CONTRIBUTING.md for detailed build instructions.
pip install git+https://github.com/quantales/pyquantlib.gitimport pyquantlib as ql
# Set evaluation date
today = ql.Date(15, 6, 2025)
ql.Settings.evaluationDate = today
# Market data
spot = ql.SimpleQuote(100.0)
rate = ql.SimpleQuote(0.05)
vol = ql.SimpleQuote(0.20)
# Term structures (pass quotes directly, handles created internally)
dc = ql.Actual365Fixed()
risk_free = ql.FlatForward(today, rate, dc)
dividend = ql.FlatForward(today, 0.0, dc)
volatility = ql.BlackConstantVol(today, ql.TARGET(), vol, dc)
# Black-Scholes process (pass objects directly)
process = ql.GeneralizedBlackScholesProcess(spot, dividend, risk_free, volatility)
# European call option
payoff = ql.PlainVanillaPayoff(ql.Call, 100.0)
exercise = ql.EuropeanExercise(today + ql.Period("1Y"))
option = ql.VanillaOption(payoff, exercise)
# Price with analytic Black-Scholes
option.setPricingEngine(ql.AnalyticEuropeanEngine(process))
print(f"NPV: {option.NPV():.4f}")
print(f"Delta: {option.delta():.4f}")
print(f"Gamma: {option.gamma():.4f}")
print(f"Vega: {option.vega():.4f}")
print(f"Theta: {option.theta():.4f}")Output:
NPV: 10.4506
Delta: 0.6368
Gamma: 0.0188
Vega: 37.5240
Theta: -6.4140
import pyquantlib as ql # Concrete classes
from pyquantlib.base import ... # Abstract base classes (for subclassing)Coverage includes dates and calendars, market quotes, yield and volatility term structures, stochastic processes, instruments, and pricing engines. See the API Reference for the complete list.
See CONTRIBUTING.md for development setup and guidelines.
# Clone and install in development mode
git clone https://github.com/quantales/pyquantlib.git
cd pyquantlib
python -m venv venv
source venv/bin/activate # or venv\Scripts\activate on Windows
python -m pip install --upgrade pip
pip install -r requirements-dev.txt
pip install -e .
# Run tests
pytestFull documentation is available at pyquantlib.readthedocs.io. For the latest additions, see the changelog.
See the examples directory for Jupyter notebooks demonstrating PyQuantLib usage.
BSD 3-Clause License. See LICENSE for details.
- QuantLib - Quantitative finance library
- pybind11 - C++/Python bindings
- scikit-build-core - Build system