Skip to main content

quantfinlab Library

quantfinlab is the reusable Python library extracted from the Quantitative Finance Lab project series. It covers the methods developed across 24 projects: fixed income, options pricing, portfolio construction, risk reporting, volatility modeling, hedging, fundamental equity research, corporate credit, real-time macro, dependence networks, ML/RL and financial analysis with a local LLM.

The test suite checks real model properties rather than notebook snapshots: weights summing to one, CVaR behavior, curve/discount consistency, American option engine fallbacks, implied-volatility diagnostics, and PSD matrix reconstruction. The current package checks pass with a clean ruff lint pass.

Installation

From PyPI:

pip install quantfinlab

For optional dependencies, install the extras you need. The source checkout defines:

pip install "quantfinlab[numerics]"   # JAX / Numba acceleration (autodiff Greeks, fast IV)
pip install "quantfinlab[volatility]" # arch, statsmodels (GARCH, HAR)
pip install "quantfinlab[hedging]"    # statsmodels (dynamic hedge ratios)
pip install "quantfinlab[ml]"         # PyTorch (sequence models, RL policies)
pip install "quantfinlab[network]"    # networkx (dependence networks)
pip install "quantfinlab[data]"       # PyArrow / DuckDB source readers
pip install "quantfinlab[credit]"     # LightGBM / statsmodels default models and source readers
pip install "quantfinlab[macro]"      # statsmodels state-space models and source readers
pip install "quantfinlab[analyst]"    # document retrieval and local financial analysis
pip install "quantfinlab[plotting]"   # matplotlib, seaborn
pip install "quantfinlab[all]"        # everything above

For development from the repository root:

pip install -e .

Source installs build the optional C++ extension (quantfinlab._kernels) automatically via scikit-build-core, CMake, and pybind11 when a C++ compiler is available. The extension accelerates the heaviest American-option, Fourier/COS, Monte Carlo, and calibration kernels, but the package also works from a pure-Python wheel when native builds are not available.

To disable native kernels during a source install:

pip install . --config-settings=cmake.define.quantfinlab_build_cpp=off

Functions that accept engine="auto" prefer C++ when available, then Numba when installed, then NumPy/SciPy fallback paths where implemented. If you explicitly request engine="cpp" without the extension installed, quantfinlab raises MissingKernelsError with installation and fallback guidance.

Most of the library works with just the core dependencies (NumPy, pandas, SciPy, cvxpy, and scikit-learn). Optional dependencies are checked at the point of use. Functions either fall back to a pure NumPy/SciPy implementation, or raise a clear, specific error telling you which extra to install, rather than failing on package import. Tests that need optional dependencies use pytest.importorskip and skip cleanly rather than fail when the dependency is absent.

Module map

Module Covers
quantfinlab.dataio Source-normalized data loading: yield curves, equity/ETF panels, option chains, SEC facts and filings, macro vintages and surveys; each source family returns a stable schema regardless of the underlying data vendor. See Data loading below.
quantfinlab.fixed_income Curve bootstrapping, discounting, forward rates, bond pricing and cashflows, duration/convexity/key-rate duration, short-rate/term-structure models, swaps, scenario generation, duration-targeted laddering, overnight-rate compounding.
quantfinlab.options Black–Scholes/Black-76 pricing, put-call parity, quote cleaning, implied volatility (Newton-bisection and "Let's Be Rational"-style solvers, with an optional Numba backend), analytic and autodiff Greeks (optional JAX), American option pricing (tree/PDE/LSM, C++ and numba backed), Fourier/COS pricing, Heston/SABR/SVI/SSVI/rough-volatility/Merton/variance-gamma models, local volatility, and model-risk diagnostics.
quantfinlab.portfolio Expected-return models, covariance estimation (sample/Ledoit-Wolf/OAS/EWMA), mean-variance/min-variance/max-Sharpe/ridge optimizers, constraints, transaction costs, walk-forward backtesting harness, Black-Litterman (with learned-confidence views and factor/regime conditioning), HRP/NCO clustering allocation, risk parity, CVaR and robust (box/ellipsoid/Wasserstein) optimization, factor construction, regime models, dependence-network construction and network-based signals, universe selection and position sizing.
quantfinlab.risk VaR/expected shortfall (historical, Cornish-Fisher, filtered historical simulation), VaR backtesting, drawdown analysis, performance metrics, CAPM beta, correlation diagnostics, stress testing, risk contribution/attribution.
quantfinlab.volatility Realized-volatility estimators, GARCH/HAR forecasting, rough-volatility estimation, variance risk premium analysis.
quantfinlab.hedging Dynamic hedge-ratio estimation, hedge policies, residual-spread construction, hedging performance metrics.
quantfinlab.macro Financial-conditions indicators and allocation; vintage/as-of transforms, completed-month GDP bridges, inflation components, MIDAS, grouped mixed-frequency DFM and Kalman news, monthly Minnesota BVAR, policy forecasts and release evaluation.
quantfinlab.fundamentals Point-in-time statement reconstruction, accounting ratios, corporate/financial-company diagnostics, peer scoring, stock selection and score validation.
quantfinlab.credit Filing-based default labels, logit/spline/LightGBM default models, Merton inversion, intensity curves, CDS valuation, credit portfolios and tranche losses.
quantfinlab.ml Feature engineering, forecasting evaluation (rank metrics, pinball loss, coverage), probabilistic/uncertainty models, release-aware validation and forecast combinations, sequence models (e.g. TCN-based forecasters), regime classifiers, RL environments, reward shaping (differential Sharpe ratio), and RL policies (PPO, recurrent PPO, SAC).
quantfinlab.backtest Shared backtesting engines for portfolios, fixed income, hedging, and options strategies, with cost models and overlay support.
quantfinlab.reports Risk and fundamental equity reports, combining outputs from risk, portfolio, and plotting into a single executive summary.
quantfinlab.numerics Finite-difference schemes, Fourier transforms, interpolation, Monte Carlo path generation, Gaussian and Student-t copulas. Shared numerical primitives used across pricing, portfolios and risk.
quantfinlab.calibration Model calibration. American option numerics, FFT/COS calibration, jump-diffusion model fitting, LSM regression.
quantfinlab.analyst Official documents, FTS5 retrieval, financial contexts, cached local GGUF inference and readable company, macro, market and daily reports.
quantfinlab.plotting Consistent plotting utilities per domain (curves, options, portfolio, risk, volatility, macro, regimes, ML, hedging, fixed income, fundamentals, credit) and explanatory diagrams.
quantfinlab.common Shared contracts/dataclasses (Curve, Bond, PortfolioState, BacktestResult, ...), error types, date utilities, cache identities, and input validation used across every other module.

The optional C++ pricing kernels (cpp/, exposed as quantfinlab._kernels) implement the LSM regression solver, the PSOR finite-difference PDE solver, the binomial tree, Monte Carlo paths, and the Fourier/COS pricer. They are written in C++ and bound via pybind11 for speed; pure-Python installs keep the public APIs importable and use automatic fallbacks where those methods exist.

Data loading

quantfinlab.dataio is what every notebook uses to turn a raw downloaded file into a clean, analysis-ready dataset. It is also the boundary the project series treats most carefully. see the project README and data README for how raw data is obtained in the first place, dataio is what runs after having the data files for turning them into analysis ready dataframes.

from quantfinlab.dataio import load_par_yield_curve, load_yfinance_panel

us_curve = load_par_yield_curve("data/us_treasury_yields.csv", source="us_treasury")
jp_curve = load_par_yield_curve("data/japan_mof_yields.csv", source="japan_mof")

panel = load_yfinance_panel(
    "data/core_cross_asset_etfs.csv", fields=("close", "volume"),
    source="yfinance_export", start="2010-01-01")

close, volume = panel["close"], panel["volume"]

Loaders normalize each source family to a consistent shape. par-yield curves come back as a DatetimeIndex-sorted DataFrame with standard tenor columns (1M...30Y) in decimal form. equities and prices come back as {field: DataFrame} with tickers as columns, numeric-coerced, deduplicated, sorted. This is what makes the "secondary market" repeat at the end of most notebooks possible with no extra glue code. swap the path/source, get the same schema back. SEC readers retain filing versions and availability dates; real-time macro readers retain observation dates separately from publication or snapshot dates. A vintage label is not automatically an exact release timestamp.

Examples

A few representative examples. See the notebooks for the full derivations behind each of these and the full repeat of each project completely using the library.

Mean-variance portfolio optimization with turnover control

from quantfinlab.portfolio import covariance, optimizers

cov_ann = covariance.estimate_covariance(returns_window, method="LedoitWolf", return_df=True)

weights = optimizers.mean_variance(
    mu_excess_ann=expected_excess_returns,
    cov_ann=cov_ann, mv_lambda=6.0,
    w_max=0.25, turnover_penalty_bps=10.0,
    long_only=True)

optimizers also exposes equal_weight, minimum_variance, ridge_mean_variance, max_sharpe_slsqp, and max_sharpe_frontier_grid with the same calling convention, plus a walkforward module that runs any of these through a full rolling rebalance/backtest loop given a returns panel and rebalance schedule.

Implied volatility from a market quote

from quantfinlab.options import iv

sigma = iv.implied_vol(
    option_type="call", price=4.35, forward=101.2,
    strike=100.0, tau=30 / 365,
    engine="auto", solver="lbr_lite")

For a full option-chain DataFrame at once, iv.compute_iv_table(quotes, ...) runs the same solver vectorized across all rows and returns solver-status diagnostics alongside the implied vols (used in the notebooks to check solver success rate and pricing residuals before trusting a fitted surface).

Risk parity and CVaR-aware allocation

from quantfinlab.portfolio import risk_parity, cvar

erc_weights = risk_parity.equal_risk_contribution_weights(cov_ann, tickers=cov_ann.index, w_max=0.40)
contrib_table = risk_parity.risk_contribution_table(erc_weights, cov_ann)

cvar_weights = cvar.min_cvar_weights(returns_window, alpha=0.95, w_max=0.40)
loss = cvar.portfolio_cvar_loss(returns_window, cvar_weights, alpha=0.95)

Yield curve construction and bond pricing

from quantfinlab.dataio import load_par_yield_curve
from quantfinlab.fixed_income import bootstrap, bond_pricing

curve = load_par_yield_curve("data/us_treasury_yields.csv", source="us_treasury")
discount_curve = bootstrap.bootstrap_discount_factors(curve.loc["2024-06-01"])

price = bond_pricing.bond_price(coupon=0.045, maturity_years=10.0, df_func=discount_curve, freq=2)

A full risk report

from quantfinlab.reports import risk_report

report = risk_report.risk_report(
    returns=strategy_returns, benchmark_returns=benchmark_returns,
    weights=weights_history, cov_ann=cov_ann)

This produces the same VaR/ES, drawdown, CAPM, and risk-contribution summary used throughout Project 03 and applied to every backtest in later projects — one call instead of re-deriving the report each time.

Default probabilities and CDS pricing

from quantfinlab.credit.curves import hazards_from_pd
from quantfinlab.credit.pricing import cds_spread
from quantfinlab.fixed_income.discounting import discount_from_zero

T = [0.25, 0.5, 1.0, 2.0]
lambda_q = hazards_from_pd([0.003, 0.006, 0.015, 0.035], T)
discount = discount_from_zero(T, [0.035, 0.034, 0.033, 0.032])
spread = cds_spread(lambda_q, T, discount, 2.0, R=0.4)

Rates, probabilities and recoveries are decimals; maturities are years. Pricing requires a risk-neutral hazard assumption, distinct from an empirical default forecast. The CDS functions use explicit cash-flow approximations, not the ISDA standard model; cds_cs01 bumps spreads and recalibrates the hazard curve, while risky_pv01 measures annuity sensitivity.

A historical macro information set

from quantfinlab.dataio.realtime import read_alfred
from quantfinlab.macro.realtime import vintage_asof, release_growth

releases = read_alfred("data/alfred_realtime.parquet", series=["INDPRO"])
known = vintage_asof(releases, "2020-04-15", wide=True)
first_growth = release_growth(releases, periods=1, scale=1200, max_delay=100)

Growth uses numerator and denominator from the same release vintage. Archive backfill is not automatically first-release truth; max_delay is a bound measured from the reference period's start. State-space news, factor-augmented forecasts and the monthly BVAR with a separate quarterly bridge remain distinct APIs; their assumptions and return values are documented in the functions.

Testing

pip install -e ".[dev,analyst]"
pytest

Tests are organized to mirror the package layout (tests/portfolio, tests/options, tests/cpp, ...) and use a small set of deterministic synthetic-data generators (tests/synthetic/generators.py) rather than real market data, so the suite is fast, reproducible, and has no external data dependency.

Metadata

Release files for quantfinlab 0.9.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for quantfinlab 0.9.0
File Size Uploaded Provenance Actions
quantfinlab-0.9.0.tar.gz 997.1 kB With provenance Details for quantfinlab-0.9.0.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for quantfinlab 0.9.0
File Actions
quantfinlab-0.9.0-py3-none-any.whl Python 3 none any Details for quantfinlab-0.9.0-py3-none-any.whl
quantfinlab-0.9.0-cp312-cp312-win_amd64.whl CPython 3.12 CPython 3.12 Windows x86-64 Details for quantfinlab-0.9.0-cp312-cp312-win_amd64.whl
quantfinlab-0.9.0-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl CPython 3.12 CPython 3.12 Linux glibc 2.24+ x86-64, Linux glibc 2.28+ x86-64 Details for quantfinlab-0.9.0-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
quantfinlab-0.9.0-cp312-cp312-macosx_11_0_arm64.whl CPython 3.12 CPython 3.12 macOS 11.0+ ARM64 Details for quantfinlab-0.9.0-cp312-cp312-macosx_11_0_arm64.whl
quantfinlab-0.9.0-cp311-cp311-win_amd64.whl CPython 3.11 CPython 3.11 Windows x86-64 Details for quantfinlab-0.9.0-cp311-cp311-win_amd64.whl
quantfinlab-0.9.0-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl CPython 3.11 CPython 3.11 Linux glibc 2.28+ x86-64, Linux glibc 2.24+ x86-64 Details for quantfinlab-0.9.0-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
quantfinlab-0.9.0-cp311-cp311-macosx_11_0_arm64.whl CPython 3.11 CPython 3.11 macOS 11.0+ ARM64 Details for quantfinlab-0.9.0-cp311-cp311-macosx_11_0_arm64.whl

Total release size: 8.9 MB

Release files / quantfinlab-0.9.0.tar.gz

Download URL quantfinlab-0.9.0.tar.gz
Size 997.1 kB
Tags Source
SHA-256 checksum
How to use checksums
a98d70981c94a26905e819f59ba19e538686547f1dc76d58a53f3e7747ced46f
BLAKE2b-256 checksum
How to use checksums
be96cd10bf4776a74d43e30307c6c917221ebe18c508d687c6f3a97a900fa18a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 11, 2026.

Transparency log

Release files / quantfinlab-0.9.0-py3-none-any.whl

Download URL quantfinlab-0.9.0-py3-none-any.whl
Size 916.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
bb6b10e1ed1142aaa8ca89c7bca0d80a1d79e9e09ddc70b10a5bc86c10c09dd4
BLAKE2b-256 checksum
How to use checksums
be5c66fa79213368faeabe5849e45824adf45f71d2a44b8fda8112bf6224d815
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 11, 2026.

Transparency log

Release files / quantfinlab-0.9.0-cp312-cp312-win_amd64.whl

Download URL quantfinlab-0.9.0-cp312-cp312-win_amd64.whl
Size 1.3 MB
Tags CPython 3.12 Windows x86-64
SHA-256 checksum
How to use checksums
a4bc647292b19ecc7d468bd02509bf77c6ca3ff7077f942d3d54409de5b04b2d
BLAKE2b-256 checksum
How to use checksums
beed5d3a24e2c88953a489004bbf06541c42c7a9601e6493220239ff2a7ba727
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 11, 2026.

Transparency log

Release files / quantfinlab-0.9.0-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl

Download URL quantfinlab-0.9.0-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Size 1.2 MB
Tags CPython 3.12 Linux glibc 2.24+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
ba5b239f0f59d52ca5efc12ca68dcfeb89221e025d3ff2074dfd9a3f8b26d55f
BLAKE2b-256 checksum
How to use checksums
6086e196043e67be7425af735163e5f095106000ce1dcb1106ad5179c0047dc4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 11, 2026.

Transparency log

Release files / quantfinlab-0.9.0-cp312-cp312-macosx_11_0_arm64.whl

Download URL quantfinlab-0.9.0-cp312-cp312-macosx_11_0_arm64.whl
Size 1.0 MB
Tags CPython 3.12 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
b425932477503ba8a2c9feecbc938d032d19d4b0cbca7b4fe97fa53f23f44ee4
BLAKE2b-256 checksum
How to use checksums
dab94c694cbd0a3618220ca3226858af035aa45e3e024a3ef7f771463a955bf6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 11, 2026.

Transparency log

Release files / quantfinlab-0.9.0-cp311-cp311-win_amd64.whl

Download URL quantfinlab-0.9.0-cp311-cp311-win_amd64.whl
Size 1.3 MB
Tags CPython 3.11 Windows x86-64
SHA-256 checksum
How to use checksums
1eca2af5d9bf24dab6210e85e23ef4a300cec5dfaaeb34f20fcd10054591c3dc
BLAKE2b-256 checksum
How to use checksums
fa2e28f47f98b52a254b00845ea492fc5cbc384dbdc157abd70c69fda1a0bce4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 11, 2026.

Transparency log

Release files / quantfinlab-0.9.0-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl

Download URL quantfinlab-0.9.0-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Size 1.2 MB
Tags CPython 3.11 Linux glibc 2.24+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
567589451261f87c3a1f1cdb0877e68d5ddb8fe196c58a9fb973a345a2c981e7
BLAKE2b-256 checksum
How to use checksums
a27e62c21a1d4fd4f616f9d8f737bcdebf5f044eacebc7746d9208a78a343690
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 11, 2026.

Transparency log

Release files / quantfinlab-0.9.0-cp311-cp311-macosx_11_0_arm64.whl

Download URL quantfinlab-0.9.0-cp311-cp311-macosx_11_0_arm64.whl
Size 1.0 MB
Tags CPython 3.11 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
612239e393f05a3f8330b1036a29b70b3fa03b8702826c02afb849e2e21db339
BLAKE2b-256 checksum
How to use checksums
a9d8d1512bdfb6419a8b5744e6d856148bcecef98aef5474c143d3d4ecbbf88f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 11, 2026.

Transparency log

Security for quantfinlab 0.9.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 8 files in this release have been uploaded with provenance metadata.

Select from 8 files

Attestation for quantfinlab-0.9.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 11, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.9.0 This release

8 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page