Cython-based Python bindings for the QuantLib C++ library.
This project is a fork of PyQL (originally developed by Enthought) that replaces SWIG wrappers with a more Pythonic API built on Cython. It provides comprehensive coverage of QuantLib's functionality, including term structures, instruments, pricing engines, short-rate and equity models, and more.
Beyond the core QuantLib bindings, lifelib-pyql is developing a portfolio submodule for processing a large number of instruments of the same type efficiently.
When working with thousands or millions of instruments, creating a separate Python object for each one is too slow. The portfolio submodule provides a set of new APIs that let you create a single Python object representing a large set of instruments of the same type, whose methods operate on all instruments in the set at once rather than one at a time.
Currently, the portfolio module includes:
Schedules-- A vectorized collection of payment schedules. It bulk-generates QuantLibScheduleobjects from arrays of parameters and stores the resulting dates in a compact 2D NumPydatetime64[D]array.
from lifelib_pyql.portfolio.api import Schedules
import numpy as np
schedules = Schedules(
effective_dates=np.array(['2024-01-15', '2024-03-01'], dtype='datetime64[D]'),
termination_dates=np.array(['2029-01-15', '2029-03-01'], dtype='datetime64[D]'),
tenors=np.array([6, 3]), # months
max_size=20,
)
schedules.dates # 2D datetime64[D] array, NaT-padded
schedules.size # number of dates per schedule
schedules[0] # returns a single Schedule object
schedules[0:1] # returns a new Schedules sliceFixedRateBonds-- A vectorized collection of fixed-rate bonds stored as parallel NumPy arrays. It bulk-stores bond parameters and reconstructs individual QuantLibFixedRateBondobjects on demand via indexing.
from lifelib_pyql.portfolio.api import Schedules, FixedRateBonds
from lifelib_pyql.time.daycounters.actual_actual import ActualActual
from lifelib_pyql.time.businessdayconvention import Following
import numpy as np
bonds = FixedRateBonds(
settlement_days=np.array([3, 3, 3]),
face_amounts=np.array([100.0, 100.0, 100.0]),
schedules=schedules, # a Schedules object
coupons=np.array([0.05, 0.04, 0.06]), # one coupon rate per bond
accrual_day_counter=ActualActual(ActualActual.ISMA),
payment_convention=Following,
redemptions=100.0, # scalar broadcasts to all
issue_dates=np.array(['2024-01-15', '2024-03-01', '2024-06-01'],
dtype='datetime64[D]'),
)
bonds[0] # returns a single FixedRateBond object
bonds[0:2] # returns a new FixedRateBonds slice
len(bonds) # number of bonds in the collection
bonds.coupons # 1D or 2D array of coupon rates# Build Cython extensions in-place
make build
# Run the test suite
make tests
# Build documentation (requires Sphinx, nbsphinx)
make docsSee the Getting started guide for full details.
BSD 3-Clause. See LICENSE.txt. The original PyQL license is preserved in LICENSE_ORIGINAL_PYQL.txt.