Skip to main content

Python bindings for QuantLib

Project description

PyQuantLib: Modern Python bindings for QuantLib

Documentation macOS Linux Windows codecov PyPI DOI License Python PRs Welcome

Beta Status: This project is under active development. API may change.

Overview

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.

Features

  • 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 .pyi stub files
  • Python subclassing: Extend QuantLib classes without C++ recompilation
  • Modern build: scikit-build-core, CMake presets, cross-platform CI/CD

Installation

pip install pyquantlib

Pre-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.

From Source

Building from source requires QuantLib built with specific CMake flags. See CONTRIBUTING.md for detailed instructions.

Prerequisites

  • Python 3.10+
  • CMake 3.18+
  • C++17 compatible compiler
  • Boost headers
  • QuantLib 1.40+ built with std::shared_ptr support (see below)

QuantLib Build Requirement

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.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 (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

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.

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

Documentation

Full documentation is available at pyquantlib.readthedocs.io. For the latest additions, see the changelog.

Examples

See the examples directory for Jupyter notebooks demonstrating PyQuantLib usage.

License

BSD 3-Clause License. See LICENSE for details.

Acknowledgments

Status

PyQuantLib is under active development. For broader QuantLib coverage today, use QuantLib-SWIG.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyquantlib-0.3.0.tar.gz (1.0 MB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

pyquantlib-0.3.0-cp313-cp313-win_amd64.whl (4.4 MB view details)

Uploaded CPython 3.13Windows x86-64

pyquantlib-0.3.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (7.4 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

pyquantlib-0.3.0-cp313-cp313-macosx_11_0_arm64.whl (5.4 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

pyquantlib-0.3.0-cp312-cp312-win_amd64.whl (4.4 MB view details)

Uploaded CPython 3.12Windows x86-64

pyquantlib-0.3.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (7.4 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

pyquantlib-0.3.0-cp312-cp312-macosx_11_0_arm64.whl (5.4 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

pyquantlib-0.3.0-cp311-cp311-win_amd64.whl (4.4 MB view details)

Uploaded CPython 3.11Windows x86-64

pyquantlib-0.3.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (7.4 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

pyquantlib-0.3.0-cp311-cp311-macosx_11_0_arm64.whl (5.4 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

pyquantlib-0.3.0-cp310-cp310-win_amd64.whl (4.4 MB view details)

Uploaded CPython 3.10Windows x86-64

pyquantlib-0.3.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (7.4 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

pyquantlib-0.3.0-cp310-cp310-macosx_11_0_arm64.whl (5.4 MB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

File details

Details for the file pyquantlib-0.3.0.tar.gz.

File metadata

  • Download URL: pyquantlib-0.3.0.tar.gz
  • Upload date:
  • Size: 1.0 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pyquantlib-0.3.0.tar.gz
Algorithm Hash digest
SHA256 e4d331d1ced497299ddcd9233a88f10e13e12dea7d94b5314222ca45d6d7eb22
MD5 bc078764074188ad56cbe8beb45f1855
BLAKE2b-256 1bc63245807b536f55003157f729c38e685afa763a148c02cc3d1d4a8133f751

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyquantlib-0.3.0.tar.gz:

Publisher: wheels.yml on quantales/pyquantlib

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pyquantlib-0.3.0-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: pyquantlib-0.3.0-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 4.4 MB
  • Tags: CPython 3.13, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pyquantlib-0.3.0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 3d43510ad657e076fbb2f3f52c6d62a8eaacb8ba66ed1e169fb3e6c198b57213
MD5 5b1b3aa8fc867d20ea19bab39a915cf1
BLAKE2b-256 f598fbdfd47ac1b3493d8515899cb3a60f6c03ac3eba4a852e6c0e5abc63fb34

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyquantlib-0.3.0-cp313-cp313-win_amd64.whl:

Publisher: wheels.yml on quantales/pyquantlib

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pyquantlib-0.3.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyquantlib-0.3.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 d6deb0bf5193b24403b34aa7f894023b81e2fec85fe204da327dabec5adf3bda
MD5 2af9c3f0f7f4f22b0e6bce524de09702
BLAKE2b-256 cf40c86dca6f982bf2bef2cc7eab6054c8f639c75c1a4d581b57d749b397dc1a

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyquantlib-0.3.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: wheels.yml on quantales/pyquantlib

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pyquantlib-0.3.0-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyquantlib-0.3.0-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 f934819f50833c43f9f963abc5e4657de534173ebdf648b78e263b63b8064ce1
MD5 eaf09d4b485e67a7c9f27d9ead06dc43
BLAKE2b-256 f5fe0c1068aafa3fe6f0f8a07317a089f6c62447ec9ad92ec4a94ba37fbfa261

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyquantlib-0.3.0-cp313-cp313-macosx_11_0_arm64.whl:

Publisher: wheels.yml on quantales/pyquantlib

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pyquantlib-0.3.0-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: pyquantlib-0.3.0-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 4.4 MB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pyquantlib-0.3.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 1f4213fecba74612ed2b24d89d7dd3653a2026f2fb7396715bddd4d74fe49357
MD5 6ecb2da80c2ceeadf203d3b5a7443c58
BLAKE2b-256 c241f7ce99f5464f3b1cbdb5b825fb3a7eadf4fcdfaca8401bca1827b9ad5fb4

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyquantlib-0.3.0-cp312-cp312-win_amd64.whl:

Publisher: wheels.yml on quantales/pyquantlib

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pyquantlib-0.3.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyquantlib-0.3.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 19294a9494d2afae178bac1edeac29c700a2152f702b39dad68553bc93065483
MD5 a704fd4df617235463aae78f088b0171
BLAKE2b-256 940f8fa1b789808fb6fb99655108a393413a850aa11fb64927fbde9295b5e451

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyquantlib-0.3.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: wheels.yml on quantales/pyquantlib

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pyquantlib-0.3.0-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyquantlib-0.3.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 67c33839437c1ee52dfbd26c2ed9c1bf682c1b8b37eec5a7495e2f5ab2ffd2d4
MD5 cf0b4bd018b58f6ceddf65b0cab6f8bd
BLAKE2b-256 4f01097e83216035d176ecaa9b58bbf296aa5ab87f89b8dd190d8b4e97ec1214

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyquantlib-0.3.0-cp312-cp312-macosx_11_0_arm64.whl:

Publisher: wheels.yml on quantales/pyquantlib

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pyquantlib-0.3.0-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: pyquantlib-0.3.0-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 4.4 MB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pyquantlib-0.3.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 8b6648b78843fb2436e6d9d983914b891151c13b725bc3da7f3748955f46c9d1
MD5 0a0f5d5c0f5c7ee8998ca5f21e40df71
BLAKE2b-256 6f753c056ba1e28ea4abfe6853eed4d5f1eec20b26a8a21069ddf0fddf67a20e

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyquantlib-0.3.0-cp311-cp311-win_amd64.whl:

Publisher: wheels.yml on quantales/pyquantlib

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pyquantlib-0.3.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyquantlib-0.3.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 bb3fcb26819f592e4106ed87adb6be9cbaad092f6dae7d3bcfb2bcbe0192d8ec
MD5 b048387c0b1b1ecbb7663b729d70ebc8
BLAKE2b-256 fd493d9f2392b6fcfe03e5cf45cb28e80b3e0d7023031acf73117b4ac0594f73

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyquantlib-0.3.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: wheels.yml on quantales/pyquantlib

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pyquantlib-0.3.0-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyquantlib-0.3.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 11d619c7a55648bd85f4c9299c53498a15cda3aa361c8a0efa769ebb43a1c9f1
MD5 f24c4d221601cfd28daf0f8a2a8d6c1a
BLAKE2b-256 cfa0f8aaa9fc926deb6226daa90fd82a4dd5f4cc72ff5da2cf587dc35e79e9a5

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyquantlib-0.3.0-cp311-cp311-macosx_11_0_arm64.whl:

Publisher: wheels.yml on quantales/pyquantlib

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pyquantlib-0.3.0-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: pyquantlib-0.3.0-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 4.4 MB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pyquantlib-0.3.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 84e48aea2380f741b631781fd5f612cef734a13f10e352701749e8121cbad129
MD5 d1c26be44ea78d64aa08b8485b2fb427
BLAKE2b-256 979a18b9772eed1bda9417f70b3719f650c16dcc5667767d323167a03703bb3d

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyquantlib-0.3.0-cp310-cp310-win_amd64.whl:

Publisher: wheels.yml on quantales/pyquantlib

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pyquantlib-0.3.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyquantlib-0.3.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 247cc2c8e5929fb73b20413b7af4d53cd769aa534d016f05b4716cad96651e3f
MD5 db169437f25012568a796f7b66e9530e
BLAKE2b-256 ee52224006dbc21fd02c220ea3358b23fad21d04ab8f0c0e5d0af8162e17768f

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyquantlib-0.3.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: wheels.yml on quantales/pyquantlib

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pyquantlib-0.3.0-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyquantlib-0.3.0-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 acb4756961d6fe684312fdcc40a0ad4aef2a79e7bb3c3e3b85e49d7d523807c9
MD5 9857ce3ec8f0d1627d1ba8d8ce11c15b
BLAKE2b-256 8463adef1f95ea19c5b076a665cc53ba4a566d54ef706d120991f1ee7103ef0c

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyquantlib-0.3.0-cp310-cp310-macosx_11_0_arm64.whl:

Publisher: wheels.yml on quantales/pyquantlib

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page