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.4.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.4.0-cp313-cp313-win_amd64.whl (4.7 MB view details)

Uploaded CPython 3.13Windows x86-64

pyquantlib-0.4.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (7.9 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

pyquantlib-0.4.0-cp313-cp313-macosx_11_0_arm64.whl (5.7 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

pyquantlib-0.4.0-cp312-cp312-win_amd64.whl (4.7 MB view details)

Uploaded CPython 3.12Windows x86-64

pyquantlib-0.4.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (7.9 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

pyquantlib-0.4.0-cp312-cp312-macosx_11_0_arm64.whl (5.7 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

pyquantlib-0.4.0-cp311-cp311-win_amd64.whl (4.7 MB view details)

Uploaded CPython 3.11Windows x86-64

pyquantlib-0.4.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (7.9 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

pyquantlib-0.4.0-cp311-cp311-macosx_11_0_arm64.whl (5.7 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

pyquantlib-0.4.0-cp310-cp310-win_amd64.whl (4.6 MB view details)

Uploaded CPython 3.10Windows x86-64

pyquantlib-0.4.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (7.9 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

pyquantlib-0.4.0-cp310-cp310-macosx_11_0_arm64.whl (5.7 MB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

File details

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

File metadata

  • Download URL: pyquantlib-0.4.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.4.0.tar.gz
Algorithm Hash digest
SHA256 749aed1f4cfb34d933e7d30cfedbc0969d4a3a0922b7f6d582431bc66f04ec60
MD5 9f64f5d9611c406c98cf091329d74dff
BLAKE2b-256 e3acaec42f1f77cb1085a43692b4b0daab49c47222f31e3db5b064a7f701b09f

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: pyquantlib-0.4.0-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 4.7 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.4.0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 8b70400f4e20d3575b3535cb61ec5d7b50f7384fc807ab0f21c6237f099433b1
MD5 0b81aa9d81c5e33258396ca8b0b38ef3
BLAKE2b-256 f15868101a74829f1b8af2cb828fa7ecf6c53392459ced4b5a2c9a07443dd0e1

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pyquantlib-0.4.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 161adfd88dc8cde16c6fbf53d624a354b510c64443a54192dff2a007fd515ac0
MD5 4d7cb1977d85541e0363489af47ebf7f
BLAKE2b-256 73fb2b6034e8c76ff281b47cfc7c4786f95ab96d26aca0f60badd73cd11e8ca4

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pyquantlib-0.4.0-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 10e17c766c4d171e7b615b1dfd92faa5cf0ad028c9de6d97fac849dfbf90ede3
MD5 207489da19b4de58f7384eccd40fb661
BLAKE2b-256 0d515566ed5568d1d682984a92c9aa45828522d8dfe369eb60569bfbf7721247

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: pyquantlib-0.4.0-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 4.7 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.4.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 0ff835666f476915a3f40c2bc8e42b700f353636762fd491bce9582a297afb76
MD5 e26b8cc279f079d3bc5c0423607c284c
BLAKE2b-256 7f5e1b2f898e683f33eb208b6e4a88d2369aac36daa30f4a20572b290de74336

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pyquantlib-0.4.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 6e9d23a7f230208337a4591a8370a8e077c129e86beeda514d1bbca36635b033
MD5 137e1bcfa8f29da19eb8b0433e8dc055
BLAKE2b-256 21676558f300a10beb630c67fd3e251ad118fb284e222efa12667ad38a6d3cc9

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pyquantlib-0.4.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 bd03af7dfdb374b1a7abdf4a7829cc3b0e524bf48a8a482b4e56f814439075e3
MD5 bb743cf265fe430d42fcd47f121c07ec
BLAKE2b-256 3729816205b0a0f524d487405fdd572ec836dddbc608b25d59252e9cbeece956

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: pyquantlib-0.4.0-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 4.7 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.4.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 207cb8504ea57098d32c52064363cb068b88fd3114f794cdb0d23d068df11aba
MD5 64ec03db9666a1285758580f0985fab2
BLAKE2b-256 ade25fd6b6ac6656b727ebde945f1ac0f6c6452c8bb5299e6f5cb13e0035cfbb

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pyquantlib-0.4.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 addfd3f57558aa792b407de71aa7c3d3fa1de7aa6d5a461aa7aba2fe4931b0f1
MD5 c77da19b22b731686959d0fcc7c16da9
BLAKE2b-256 c8c54e4d3808f81d8df43dd1a919048a60a1ce505dd6e2bd262ee5e96154e6e1

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pyquantlib-0.4.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 2ec77e4ad4509e48f720c3d291745e75c751cd6940272345c3daeabf969061d9
MD5 8734c7708b5043b87d60b81587612853
BLAKE2b-256 fb85126a1b6565768554ec3e25fe9572a243ff75950f977177ca0e0a3be7b782

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: pyquantlib-0.4.0-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 4.6 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.4.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 b1c0100d83648f870e252b5e39338a1b3e7967131887cdc745d7daac7be91235
MD5 a7bfc2baeded90deeeed16d834a844eb
BLAKE2b-256 970319b313a6bb1f72d4c2dccc3c5c9a6916003c7619bfe812364adb4b20de8c

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pyquantlib-0.4.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 d5c867ef56f7662ebc3dc24c12a11ddf3bdee3d74a37c6467e9ecb929421be1d
MD5 b974059e6acc5493d596905fe50defe2
BLAKE2b-256 213e78ee7f38298a20f0a85b04cdae789e47e646be75ef0da5a8a046d7808c9d

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pyquantlib-0.4.0-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 0a4d32b08e312f4cbd2116d24227fa94a76891db43a527ad1c8e160ead01f058
MD5 6776ff85a0c04cc0e712b8d22b7dd9bf
BLAKE2b-256 bbcbdbdc38da15d142b85480865538e7e1c34203dd27720eeba19c3629fc9adf

See more details on using hashes here.

Provenance

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