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

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

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.6.0.tar.gz (1.2 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.6.0-cp313-cp313-win_amd64.whl (9.8 MB view details)

Uploaded CPython 3.13Windows x86-64

pyquantlib-0.6.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (14.0 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

pyquantlib-0.6.0-cp313-cp313-macosx_11_0_arm64.whl (11.2 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

pyquantlib-0.6.0-cp312-cp312-win_amd64.whl (9.8 MB view details)

Uploaded CPython 3.12Windows x86-64

pyquantlib-0.6.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (14.0 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

pyquantlib-0.6.0-cp312-cp312-macosx_11_0_arm64.whl (11.2 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

pyquantlib-0.6.0-cp311-cp311-win_amd64.whl (9.8 MB view details)

Uploaded CPython 3.11Windows x86-64

pyquantlib-0.6.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (14.0 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

pyquantlib-0.6.0-cp311-cp311-macosx_11_0_arm64.whl (11.1 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

pyquantlib-0.6.0-cp310-cp310-win_amd64.whl (9.8 MB view details)

Uploaded CPython 3.10Windows x86-64

pyquantlib-0.6.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (14.0 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

pyquantlib-0.6.0-cp310-cp310-macosx_11_0_arm64.whl (11.1 MB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

File details

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

File metadata

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

File hashes

Hashes for pyquantlib-0.6.0.tar.gz
Algorithm Hash digest
SHA256 e933d15a266feeb53069fb614b0d8a51dc745e9c0377b432e521d90e103b317e
MD5 27de07ca23e932640378da305eb540a1
BLAKE2b-256 5c0324563c2fb95026eeeaad59b84a467c77f0d884e6a767f72c7e85b3317566

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyquantlib-0.6.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.6.0-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: pyquantlib-0.6.0-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 9.8 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.6.0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 60e85cae81d89d5713558afa0035a394a47755c229b9ba5775d46b463c3f371f
MD5 87d1328384c5a8d4539c3ee336a6cccb
BLAKE2b-256 b69c8240d8b25db2af8d64ff8c7a26a3a2676cf9bb2ff16d5cb1e4fad316bb6b

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyquantlib-0.6.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.6.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyquantlib-0.6.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 5652be154e1642510b372d94a3ec9b7922f51758fece678417c57bcf35d6989f
MD5 7ad6bf2cb12f1cd295e233aaf19ff474
BLAKE2b-256 e9ee05f67b41f254ec91f6ae2abd2f797413278efd41ecf09298ace6f1f94a78

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyquantlib-0.6.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.6.0-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyquantlib-0.6.0-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 0e2b3377f5910cee56e8b33a4899ab7fee1eed342ebab19f26cba095e68e5037
MD5 0b4cbb769e545b1ee7b62e298383d53e
BLAKE2b-256 06a6f79857df1b60f486e542668cb34ea8f70f7551ee225475d5b7724e1b2117

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyquantlib-0.6.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.6.0-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: pyquantlib-0.6.0-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 9.8 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.6.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 a56f8e3ddf17bd97252c3978a716ec7afd38aff9435ac37d91d384be8a11c7c6
MD5 5b40700757f78187cf86143ea5e75631
BLAKE2b-256 f8774b7bfed27e818697325852f64a96f873e199210d1f1e9170fec3a16d568d

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyquantlib-0.6.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.6.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyquantlib-0.6.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 3666522de374d10886574dd90f5384ddf36e7c5ffc870bacae0c3ee0abcca41d
MD5 bf78ad121a5607122025da96a87e3f63
BLAKE2b-256 fe198ac189a70d5e439a983d9e215d481214330ce6ae05f39e9bde9cbf059313

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyquantlib-0.6.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.6.0-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyquantlib-0.6.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 9a2fe7a30a0b45bba3e941e5a85a8633d38d57048c697218c2e08db8a420a148
MD5 a894a689dc8264ab166b5a89031fb0ee
BLAKE2b-256 1c65b28b0f3fefe1af9147684a5e8f11f58fceccca438b6424224adaab5d6aee

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyquantlib-0.6.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.6.0-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: pyquantlib-0.6.0-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 9.8 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.6.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 96afbe94a8ea960be8918863bd1d27e9bee6c694f4476c50dca7e8bd6f3d963c
MD5 3c95a72c0c5202c20890c1486676602b
BLAKE2b-256 b8ca2636f03bb279b7ae1e206e98ea692e11852be41796671cc9f7eb6ca580a0

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyquantlib-0.6.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.6.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyquantlib-0.6.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 5936adcf0a0eae7ef273fef62bdf9f0aeeacc6735d6980c7d3037a4e474ad8cf
MD5 7d7c4c7fae8b463a56baf35dc9e78d25
BLAKE2b-256 34ccc684554c4adee87684c67701174aa5b5043d3c07053d798d0492f12431fa

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyquantlib-0.6.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.6.0-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyquantlib-0.6.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 7710ebab148e985b752581f8b09be2671a834926d5aea5ce556b46ce53d9a128
MD5 638fce264c2a671542864f1daf86971d
BLAKE2b-256 28f565ab90f2ed4e38582bc9e7d75d54bc25b935ca602e9baac7f0011faa6292

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyquantlib-0.6.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.6.0-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: pyquantlib-0.6.0-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 9.8 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.6.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 3ca505045a2436f36c584e637b28df4395fe530ae38f9bd8e004436105d72640
MD5 31ec0daeaab6b5b9f9129eee7e49a9d0
BLAKE2b-256 7fc2400a600d140451044bbc2ebf2dcb751f4002dcb7d72340cf67be42bbdb91

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyquantlib-0.6.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.6.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyquantlib-0.6.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 5f2fedddd818b2968bdfd740357b9852a5dadbaed86788c742fd47907a67ca76
MD5 3fac82bc993dca426ab9e73e2c03bcef
BLAKE2b-256 8cdf515f436498e799ee4be19fc459634222f2f0289886d1be629b1b4948959f

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyquantlib-0.6.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.6.0-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyquantlib-0.6.0-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 7c1d8b2a192d26ab00d23d92a46a4b1a60fd7a63eeb7ac9331d0f7b53bdc3edb
MD5 ad65081f465e681374d62c79ab5b7dbc
BLAKE2b-256 9f61a9c8e86b9c28d1a9db3c8b0e634e640857bfd0090a7776489de9749f565f

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyquantlib-0.6.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