Skip to content

Repository files navigation

PyQuantLib: Modern Python bindings for QuantLib

Documentation macOS Linux Windows codecov PyPI DOI License Python PRs Welcome

Overview

PyQuantLib provides Python bindings for QuantLib, the open-source library for quantitative finance. It is built on pybind11: every binding is written in standard C++, with no interface-definition language and no code-generation step between the caller and the QuantLib source.

As an independent project, PyQuantLib complements the official QuantLib-SWIG bindings, which remain the established and most widely used way to run QuantLib from Python.

Features

  • Pythonic API: pass quotes and term structures directly; handles are created internally. Plain Python types convert automatically, and None replaces Null<Real>().
  • Zero-copy NumPy: Array and Matrix use the buffer protocol, so np.array(arr, copy=False) shares memory with no marshalling.
  • Type hints: complete .pyi stubs ship in the wheel for autocomplete and type-checking.
  • Python subclassing: override QuantLib's abstract base classes via pybind11 trampolines, without C++ recompilation.
  • Modern build: scikit-build-core, CMake presets, cross-platform CI.

Installation

pip install pyquantlib

Pre-built wheels are available for Python 3.10 to 3.13 on Linux (x86_64), macOS (ARM), and Windows (x64). QuantLib is statically linked, so no separate installation is required.

From source

Building from source requires QuantLib 1.43+ compiled with specific CMake flags. Packages from Homebrew, vcpkg, and apt use shared builds and boost::shared_ptr, and are not compatible. See CONTRIBUTING.md for the required flags and full build instructions.

pip install git+https://github.com/quantales/pyquantlib.git

Quick start

import 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
process = ql.GeneralizedBlackScholesProcess(spot, dividend, risk_free, volatility)

# European call option, 1 year to expiry
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}")    # 10.4506
print(f"Delta: {option.delta():.4f}")  # 0.6368
print(f"Gamma: {option.gamma():.4f}")  # 0.0188
print(f"Vega:  {option.vega():.4f}")   # 37.5240
print(f"Theta: {option.theta():.4f}")  # -6.4140

Module organization

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.

Documentation

Full documentation is available at pyquantlib.readthedocs.io.

Section Contents
Quickstart Installation and a first pricing example
Concepts Term structures, observables, engines, calibration, and the binding patterns behind them
Cookbook Runnable recipes: curve bootstrapping, volatility surfaces, Heston calibration, NumPy interop
Examples Jupyter notebooks, also available in examples/
API Reference Every bound class, by module
Architecture Design rationale and internals
Changelog Release history

Development

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
pytest

License

BSD 3-Clause License. See LICENSE for details.

QuantLib is free software distributed under its own modified BSD license, and is copyright of its respective contributors.

About

Python bindings for QuantLib

Topics

Resources

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages