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.7.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.7.0-cp313-cp313-win_amd64.whl (10.1 MB view details)

Uploaded CPython 3.13Windows x86-64

pyquantlib-0.7.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (14.5 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

pyquantlib-0.7.0-cp313-cp313-macosx_11_0_arm64.whl (11.5 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

pyquantlib-0.7.0-cp312-cp312-win_amd64.whl (10.1 MB view details)

Uploaded CPython 3.12Windows x86-64

pyquantlib-0.7.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (14.5 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

pyquantlib-0.7.0-cp312-cp312-macosx_11_0_arm64.whl (11.5 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

pyquantlib-0.7.0-cp311-cp311-win_amd64.whl (10.0 MB view details)

Uploaded CPython 3.11Windows x86-64

pyquantlib-0.7.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (14.5 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

pyquantlib-0.7.0-cp311-cp311-macosx_11_0_arm64.whl (11.5 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

pyquantlib-0.7.0-cp310-cp310-win_amd64.whl (10.0 MB view details)

Uploaded CPython 3.10Windows x86-64

pyquantlib-0.7.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (14.5 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

pyquantlib-0.7.0-cp310-cp310-macosx_11_0_arm64.whl (11.4 MB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

File details

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

File metadata

  • Download URL: pyquantlib-0.7.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.7.0.tar.gz
Algorithm Hash digest
SHA256 3d9a5d6b117489075a9b6aac86d4a4dabdc11edd342e141786134d7fe1dec619
MD5 fe081d6f9e65807584cc801357b13c20
BLAKE2b-256 b3c2a6d7cdeaec7d91b9bd461042e108700cc443d6a379235b80657cdee55635

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: pyquantlib-0.7.0-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 10.1 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.7.0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 b734fd498f7db4771a6caf8a3e34b62acdffe84dd40fe3685cf499f1bb19e409
MD5 df047d8f4c5c8c8d9ed556a35d5474f2
BLAKE2b-256 fdff5f21ac8d352cc5d563e61419ae28ee707fb5d9589ab9a620e9cf1610da7e

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pyquantlib-0.7.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 0d31efc2644139b21a6d29d7e9d6529b95a97d1aa2d3807f78b1edf9b692a240
MD5 2e2f9f4522fe2e65b7693614ebb25813
BLAKE2b-256 f1d41412c280c898b7f64dcb8209eaf2d73701a5ccdde2b992f609c2e59c4262

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pyquantlib-0.7.0-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 452a751d32aef83abffcc4686faeb8d96406b137703b2f8e607e6f9f3c427dfb
MD5 86c4b602fc158da73b891817fe85de43
BLAKE2b-256 6668c71931af2b3c073ceddd853c9ca85e9abcc45622fe8417aae4cce14b262d

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: pyquantlib-0.7.0-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 10.1 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.7.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 57f84681849214b1d20d517bd8041da5b5fc21e10cc9562f4a9a2d854406fce6
MD5 962ae699ebb13e2525b70bf9b7fddcd7
BLAKE2b-256 47f26cb3da14761d180d77205a519da16219eabad19e41342f4068ed43f94543

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pyquantlib-0.7.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 8a4e6b00292ed8b7bf24a3ce2d730f24718ca93766ea4e653e5e1bb0e61639b8
MD5 bd55a5ff3ecc322a77131753d0198cf8
BLAKE2b-256 4e6830a7daba38d68ca1d16ced07016be53c7171c599d4f18ba4c794ffd8fa83

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pyquantlib-0.7.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 e6e54498ee2285231da2c7cccadf965398144818aed8e70b51c1dc55ab81eb8a
MD5 d06dd1e9d81dd834395a74c600018d63
BLAKE2b-256 4f21ffa7b766e325294ed86f201b967e5fc7910b74a16c254f046da9ab0901af

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: pyquantlib-0.7.0-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 10.0 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.7.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 e33eaf1ac66e58950763f7550d700d2516a375faf2ff1aa8c7455396f9df3462
MD5 796c121b606aa9a814afa01bc4038597
BLAKE2b-256 9a8b929e0a4bf28e366579cd59464d0aab55e6e2df501feee7837fceb8b9fbd2

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pyquantlib-0.7.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 1d4fa719812a91393c3af44ecccfc05985a595946276927a96f22b0600969a7d
MD5 4fd606f09ffcca8e5b94311c7322fd9f
BLAKE2b-256 80fe9d99bd26c48b340f6674b8dda66d98aa2133aff8254d76123424d216cf36

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pyquantlib-0.7.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 99056813fddf8f0f57e1286318ab5156d011986efa4a7e72ac66bcdbec6a79e3
MD5 bf1c96d2bf1555b7675e41203d27a533
BLAKE2b-256 46d99192c7af1acd1ab82d8f4827b5c2f8ce6feb626cf83813fdb88c4c65b617

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: pyquantlib-0.7.0-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 10.0 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.7.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 ac09e29e4c869a3ce7770fa25d69913f7a3ba5af0e3cc92c424b5021345e2243
MD5 ddd6f06eddbd849be118bea44e328bb2
BLAKE2b-256 6ece1ada0217cb088cb069e33f4cdba168043e516bb9b93ea9a03a723f712116

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pyquantlib-0.7.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 60dc932d6b757aa08ae86a50cbb1124a36cee7320ac64c306dc92db0dc7cf9a3
MD5 dd6d63f34a4ec81b9c2e841a298efcbb
BLAKE2b-256 d9e7f1b849b6f117c42d7f385288d108a823b8b7ae194ffb1ebf0e5392263bb2

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pyquantlib-0.7.0-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 e37b1c8fba4dcb0ffa0f32312be406ccfe0c52a51ef0f2c1c91a9c8c711a9c5c
MD5 4de475f6821874fb6f89851846845ac8
BLAKE2b-256 785eca42d98c94bdca56d7b44fc29ab61e3dbbaf262fd20015b081b448424564

See more details on using hashes here.

Provenance

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