Research-grade quantum algorithms for production-grade quant finance.
Project description
qufin - Quantum Finance
Research-Grade Quantum Algorithms for Production-Grade Quant Finance
116 modules • 10 subpackages • 1149 tests • 8 backends • 4 QAE variants
Every quantum algorithm ships with a classical baseline. No hype -- just reproducible results.
Installation • Quickstart • Modules • Architecture • Backends • Benchmarks • Docs • Contributing
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 OptimizationClassical: Mean-Variance (CVXPY), Black-Litterman, Risk Parity, HRP, Multi-Period, ADMM, Hybrid, Factor Models Option PricingClassical: Black-Scholes (full Greeks + implied vol), Monte Carlo (European / Asian / Barrier, antithetic variates), CRR Binomial (European + American), American (LSM), Implied Vol Surface (SABR/SVI) Risk ManagementClassical: VaR (historical / parametric / MC), CVaR, stress testing, counterparty CVA/DVA |
HedgingClassical: Delta hedging, deep hedging (PyTorch) Machine LearningClassical: Standard classifiers Data & InfrastructureMarket Data: Yahoo Finance, FRED macroeconomic |
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)
cudaq_backend.py # CUDA-Q GPU-accelerated backend
auto_select.py # Backend auto-selection + fallback chain
transpiler.py # Finance circuit transpiler (QUBO-aware)
noise_models.py # Depolarizing, thermal, device-calibrated
error_mitigation.py # ZNE, TREX, readout calibration
dynamical_decoupling.py # XY4, CPMG, Uhrig DD sequences
m3_mitigation.py # Matrix-free measurement mitigation
noise_aware_optimizer.py # Noise-aware variational optimizer
options/
classical/ # Black-Scholes, CRR binomial, Monte Carlo
amplitude_estimation/ # Canonical, MLAE, IQAE, FQAE
path_dependent_qae.py # Path-dependent QAE pricing
american_qae.py # American option QAE (Quantum LSM)
implied_vol_surface.py # Implied vol surface (SABR/SVI)
portfolio/
classical/ # Mean-Variance, Black-Litterman, HRP, Risk Parity
factor_models.py # Factor-based portfolio models
optimizers/ # QAOA, VQE, warm-start, exhaustive, hybrid
multi_period.py # Multi-period portfolio optimization
robust.py # Robust CVaR QUBO optimizer
quantum_walk.py # Szegedy quantum walk optimizer
admm.py # ADMM decomposition optimizer
hybrid.py # Hybrid classical-quantum optimizer
sector_rotation.py # VQC-based sector rotation
qubo.py # QUBO builder with constraints
mixers.py # X, XY-ring, XY-full, Grover mixer circuits
risk/ # VaR, CVaR, stress, counterparty
quantum_stress.py # Quantum stress testing
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 |
CudaQBackend |
GPU-accelerated simulation, 30+ qubits |
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
- Finance circuit transpiler: QUBO-aware ZZ optimization, commuting gate parallelization, connectivity-aware routing
- Hardware benchmarks: QAOA/QAE benchmark runners, error mitigation comparison, IonQ cost analysis
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 (ZNE, TREX, PEC, CDR, DD, M3) | Stable |
| Backtesting Engine | Stable |
| Benchmarks & Leaderboard | Stable |
| Data Layer (Yahoo, FRED, synthetic) | Stable |
| Hedging (delta + deep) | Beta |
| ML (kernels, VQC, qGAN) | Beta |
| 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file qufin-0.3.0.tar.gz.
File metadata
- Download URL: qufin-0.3.0.tar.gz
- Upload date:
- Size: 368.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4c9f1f8517621aaced842cfcf44902710ec02bb5640dd4055b27a6e8da1de930
|
|
| MD5 |
ad21021e079ba5a466d067b2633824e2
|
|
| BLAKE2b-256 |
851ead55f794e06ce3061c04492cb5ffb0e9607ed8ba90c4d385ee93f3500efb
|
Provenance
The following attestation bundles were made for qufin-0.3.0.tar.gz:
Publisher:
ci.yml on anonymousAAK/qufin
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
qufin-0.3.0.tar.gz -
Subject digest:
4c9f1f8517621aaced842cfcf44902710ec02bb5640dd4055b27a6e8da1de930 - Sigstore transparency entry: 1534806030
- Sigstore integration time:
-
Permalink:
anonymousAAK/qufin@91a5ed0470edad28503e606a9a65eea49cf0ccb4 -
Branch / Tag:
refs/tags/v0.3.0 - Owner: https://github.com/anonymousAAK
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@91a5ed0470edad28503e606a9a65eea49cf0ccb4 -
Trigger Event:
push
-
Statement type:
File details
Details for the file qufin-0.3.0-py3-none-any.whl.
File metadata
- Download URL: qufin-0.3.0-py3-none-any.whl
- Upload date:
- Size: 271.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
856f2460b9cafff04fd2c16ad4878c688b8ce3baced132cf690bfdc9cb8ed387
|
|
| MD5 |
f5f10f2fc13a3c034421c4140086aacc
|
|
| BLAKE2b-256 |
343ba0208f943b4836ba9866d7770b176bf2f9d4ce931c15acc84de9db2936a4
|
Provenance
The following attestation bundles were made for qufin-0.3.0-py3-none-any.whl:
Publisher:
ci.yml on anonymousAAK/qufin
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
qufin-0.3.0-py3-none-any.whl -
Subject digest:
856f2460b9cafff04fd2c16ad4878c688b8ce3baced132cf690bfdc9cb8ed387 - Sigstore transparency entry: 1534806118
- Sigstore integration time:
-
Permalink:
anonymousAAK/qufin@91a5ed0470edad28503e606a9a65eea49cf0ccb4 -
Branch / Tag:
refs/tags/v0.3.0 - Owner: https://github.com/anonymousAAK
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@91a5ed0470edad28503e606a9a65eea49cf0ccb4 -
Trigger Event:
push
-
Statement type: