Skip to main content

Research-grade quantum algorithms for production-grade quant finance.

Project description

qufin

Research-Grade Quantum Algorithms for Production-Grade Quant Finance

CI PyPI Python License Ruff Tests Downloads Coverage


90 modules10 subpackages635 tests7 backends4 QAE variants

Every quantum algorithm ships with a classical baseline. No hype -- just reproducible results.

InstallationQuickstartModulesArchitectureBackendsBenchmarksDocsContributing


Why qufin?

Most quantum finance libraries are either toy demos or tightly coupled to a single framework. qufin is different:

  • Honest benchmarking -- every quantum result is compared head-to-head against the best classical solver on the same problem instance. No cherry-picked examples.
  • Backend-agnostic -- swap between Qiskit Aer, IBM Runtime, PennyLane, Cirq, and Amazon Braket with one line. Your algorithms don't change.
  • Production patterns -- pluggable backends, typed configs, reproducibility manifests, noise-aware simulation with real device profiles, and error mitigation built in.
  • Research-ready -- implements algorithms from Brassard et al., Egger et al., and Farhi et al. with correct mathematical details (Grover global phase, IQAE multi-branch enumeration, canonical QPE).

Installation

pip install qufin
Optional extras
pip install "qufin[ibm]"        # IBM Quantum Runtime (Sampler/Estimator)
pip install "qufin[ml]"         # PyTorch for deep hedging and ML
pip install "qufin[viz]"        # Plotly interactive visualization
pip install "qufin[pennylane]"  # PennyLane Lightning backend
pip install "qufin[cirq]"       # Google Cirq backend
pip install "qufin[braket]"     # Amazon Braket backend
pip install "qufin[dev]"        # pytest, ruff, mypy, pre-commit
pip install "qufin[all]"        # Everything

Requires Python 3.10+


Quickstart

Price a European call with Black-Scholes

from qufin.options.classical.black_scholes import bs_price, bs_greeks

price = bs_price(s=100, k=105, sigma=0.2, r=0.05, T=1.0)
greeks = bs_greeks(s=100, k=105, sigma=0.2, r=0.05, T=1.0)
print(f"Price: {price:.4f}  Delta: {greeks['delta']:.4f}")
# Price: 8.0214  Delta: 0.5374

Price the same option with Quantum Amplitude Estimation

from qufin.options.amplitude_estimation.european_qae import european_qae_price
from qufin.options.amplitude_estimation.iqae import IQAEConfig
from qufin.backends.qiskit_backend import QiskitAerBackend

backend = QiskitAerBackend(shots=4096)
config = IQAEConfig(epsilon_target=0.01, shots_per_round=1024)
qae_price = european_qae_price(
    s=100, k=105, sigma=0.2, r=0.05, T=1.0,
    backend=backend, config=config
)
print(f"QAE Price: {qae_price:.4f}")

Optimize a portfolio with QAOA

from qufin.benchmarks.problems import make_benchmark
from qufin.portfolio.qubo import build_qubo
from qufin.portfolio.optimizers.qaoa import QAOAOptimizer
from qufin.backends.qiskit_backend import QiskitAerBackend

problem = make_benchmark(15)  # 15-asset benchmark
Q = build_qubo(problem.mu, problem.sigma, risk_aversion=0.5, k=5)
backend = QiskitAerBackend(shots=4096)
optimizer = QAOAOptimizer(backend=backend, p=2, mixer="xy_ring")
result = optimizer.solve(Q, n_assets=15, k=5)
print(f"Selected: {result.selected}  Objective: {result.objective:.4f}")

Run a backtest

from qufin.backtesting.engine import BacktestEngine
from qufin.backtesting.metrics import compute_metrics

engine = BacktestEngine(rebalance_freq="monthly", window=252)
portfolio_values = engine.run(prices_df, strategy_fn)
metrics = compute_metrics(portfolio_values)
print(f"Sharpe: {metrics['sharpe']:.2f}  Max DD: {metrics['max_drawdown']:.2%}")

Generate synthetic market data

from qufin.data.synthetic import gbm_paths, heston_paths, merton_jump_paths

# Geometric Brownian Motion
paths = gbm_paths(s0=100, mu=0.08, sigma=0.2, T=1.0, n_steps=252, n_paths=10_000)

# Heston stochastic volatility
from qufin.data.synthetic import HestonParams
params = HestonParams(v0=0.04, kappa=2.0, theta=0.04, xi=0.3, rho=-0.7)
paths = heston_paths(s0=100, mu=0.08, params=params, T=1.0, n_steps=252, n_paths=10_000)

Modules

Portfolio Optimization

Classical: Mean-Variance (CVXPY), Black-Litterman, Risk Parity, HRP
Quantum: QAOA (X / XY-ring / XY-full / Grover mixers), VQE, Warm-Start
Features: CVaR objective, Dicke state init, QUBO with cardinality + sector + turnover + transaction cost constraints

Option Pricing

Classical: Black-Scholes (full Greeks + implied vol), Monte Carlo (European / Asian / Barrier, antithetic variates), CRR Binomial (European + American)
Quantum: Canonical QAE, IQAE, MLAE, FQAE
Exotics: Bermudan (LSM), lookback, cliquet, autocallable, basket, path-dependent

Risk Management

Classical: VaR (historical / parametric / MC), CVaR, stress testing, counterparty CVA/DVA
Quantum: Quantum VaR, Egger credit-risk
Credit: Gaussian copula, NIG copula models

Hedging

Classical: Delta hedging, deep hedging (PyTorch)
Quantum: Quantum deep hedging, RL-quantum hedging

Machine Learning

Classical: Standard classifiers
Quantum: Kernel methods, VQC, qGAN, reservoir computing

Data & Infrastructure

Market Data: Yahoo Finance, FRED macroeconomic
Synthetic: GBM, Heston stochastic vol, Merton jump-diffusion
Backtesting: Walk-forward engine, 15+ performance metrics
Benchmarks: Standardized problem sets (15 / 25 / 50 assets), reproducibility manifests, leaderboard


Architecture

src/qufin/
    backends/                  # Pluggable backend abstraction
        base.py                #   Backend ABC + registry
        mock.py                #   MockBackend (deterministic, no simulator)
        qiskit_backend.py      #   QiskitAerBackend + NoisyAerBackend
        ibm_runtime.py         #   IBM Quantum Runtime (Sampler/Estimator)
        noise_models.py        #   Depolarizing, thermal, device-calibrated
        error_mitigation.py    #   ZNE, TREX, readout calibration
    options/
        classical/             #   Black-Scholes, CRR binomial, Monte Carlo
        amplitude_estimation/  #   Canonical, MLAE, IQAE, FQAE
    portfolio/
        classical/             #   Mean-Variance, Black-Litterman, HRP, Risk Parity
        optimizers/            #   QAOA, VQE, warm-start, exhaustive, hybrid
        qubo.py                #   QUBO builder with constraints
        mixers.py              #   X, XY-ring, XY-full, Grover mixer circuits
    risk/                      #   VaR, CVaR, stress, counterparty
        credit/                #   Egger quantum credit, Gaussian/NIG copula
    hedging/                   #   Delta, deep hedging, quantum RL
    ml/                        #   Quantum kernels, VQC, qGAN, reservoir
    derivatives/               #   Basket, autocallable, Bermudan LSM
    data/                      #   Yahoo Finance, FRED, synthetic generators
    backtesting/               #   Walk-forward engine + metrics
    benchmarks/                #   Problem sets, runner, leaderboard, manifests
    utils/                     #   Settings, logging, visualization, encoders

Backends

All quantum algorithms accept any backend implementing the Backend protocol. Swap backends without changing algorithm code:

from qufin.backends.qiskit_backend import QiskitAerBackend, NoisyAerBackend
from qufin.backends.mock import MockBackend

# Noiseless simulation
backend = QiskitAerBackend(shots=4096)

# Noisy simulation with a real device profile
backend = NoisyAerBackend(shots=4096, profile="melbourne")

# Deterministic mock for testing
backend = MockBackend()
Backend Use Case
MockBackend Unit tests, CI, deterministic results
QiskitAerBackend Local simulation, research
NoisyAerBackend Noise-aware development (4 device profiles)
IBMRuntimeBackend Real quantum hardware via IBM Quantum
PennyLaneBackend PennyLane ecosystem
CirqBackend Google Cirq ecosystem
BraketBackend Amazon Braket / AWS hardware

Benchmarks

qufin includes standardized benchmark suites for honest quantum-vs-classical comparison:

  • Problem sets: 15, 25, and 50 asset portfolios with real covariance matrices
  • Metrics: Solution quality, time-to-solution, circuit depth, approximation ratio vs exact classical optimum
  • Reproducibility: Every run generates a manifest recording hardware, software versions, and random seeds
  • Leaderboard: Track and compare results across backends and algorithm configurations
from qufin.benchmarks.runner import BenchmarkRunner
from qufin.benchmarks.problems import make_benchmark

runner = BenchmarkRunner()
results = runner.run(make_benchmark(15), algorithms=["qaoa", "vqe", "mean_variance"])
runner.summary(results)

Testing

# Run all tests
pytest

# Run specific suites
pytest tests/unit/              # Unit tests
pytest tests/integration/       # Integration tests (requires Qiskit Aer)
pytest tests/property/          # Property-based tests (Hypothesis)
pytest tests/stress/            # Stress tests
pytest -m "not slow"            # Skip slow tests
pytest -m "not hardware"        # Skip IBM hardware tests

Project Status

Component Status
Portfolio Optimization (classical + QAOA/VQE) Stable
Option Pricing (BS + QAE) Stable
Risk Management (VaR/CVaR + quantum) Stable
Noise Models + Error Mitigation Stable
Backtesting Engine Stable
Benchmarks & Leaderboard Stable
Data Layer (Yahoo, FRED, synthetic) Stable
Hedging (delta + deep) Alpha
ML (kernels, VQC, qGAN) Alpha
Documentation Site Planned

Contributing

Contributions are welcome. See CONTRIBUTING.md for guidelines on code style, testing, and pull request process.


License

Apache 2.0. See LICENSE for details.


Citation

@software{qufin,
  author       = {Adarsh Keshri},
  title        = {qufin: Research-Grade Quantum Algorithms for Quant Finance},
  year         = {2025},
  url          = {https://github.com/anonymousAAK/qufin},
  license      = {Apache-2.0}
}

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

qufin-0.2.0.tar.gz (300.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

qufin-0.2.0-py3-none-any.whl (228.6 kB view details)

Uploaded Python 3

File details

Details for the file qufin-0.2.0.tar.gz.

File metadata

  • Download URL: qufin-0.2.0.tar.gz
  • Upload date:
  • Size: 300.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for qufin-0.2.0.tar.gz
Algorithm Hash digest
SHA256 b6cc3e6cde1592a70f67c154252291702b134a8fa5bb5353435ffa3faa0783b8
MD5 8bedd9d399816ec623aa583fc0be0ce8
BLAKE2b-256 2793acf466b37782dbe72b1d578505fe8699a08afc59f5585bf3972f1982f422

See more details on using hashes here.

Provenance

The following attestation bundles were made for qufin-0.2.0.tar.gz:

Publisher: ci.yml on anonymousAAK/qufin

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file qufin-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: qufin-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 228.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for qufin-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3d69cc0378a024db448cb3c35de5acb16142c9d631f988db5ef977311fbf73c3
MD5 fd34eed8db0ff16d64beb1363a5dced9
BLAKE2b-256 0b0b15112cd4fbe06f389f93263c59304119ac43aa659866865faaf44fc47ad7

See more details on using hashes here.

Provenance

The following attestation bundles were made for qufin-0.2.0-py3-none-any.whl:

Publisher: ci.yml on anonymousAAK/qufin

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