Skip to main content

quantrs (python bindings)

tests MIT/Apache 2.0 licensed Crate docs.rs codecov-quantrs Crates.io MSRV Crates.io downloads

Quantrs is a tiny quantitative finance library for Rust. These are the Python bindings for it. It is designed to be as intuitive and easy to use as possible so that you can work with derivatives without the need to write complex code or have a PhD in reading QuantLib documentation. The library is still in the early stages of development and many features are not yet implemented.

Please check out the documentation for the original Rust crate here and at github.com/carlobortolan/quantrs.

Currently, the bindings only cover the FI module.

Installation

pip install quantrs

Usage

Day Count Conventions

import quantrs

# Create day count convention
day_count = quantrs.DayCount("ACT/365F")

# Calculate year fraction between dates
year_frac = day_count.year_fraction("2025-01-01", "2025-07-01")
print(f"Year fraction: {year_frac}")

# Calculate day count
days = day_count.day_count("2025-01-01", "2025-07-01")
print(f"Day count: {days}")

# Convenience function
year_frac = quantrs.calculate_year_fraction("2025-01-01", "2025-07-01", "ACT/365F")

Bond Pricing

import quantrs

# Create zero-coupon bond
bond = quantrs.ZeroCouponBond(face_value=1000.0, maturity="2030-12-31")

# Calculate bond price
price = bond.price(
    settlement="2025-06-19",
    ytm=0.04,  # 4% yield to maturity
    day_count=quantrs.DayCount("ACT/365F")
)
print(f"Bond price: ${price:.2f}")

Benchmarks

Compared to other popular and well-maintained (i.e., actively developed, well-documented, and feature-rich) options pricing libraries, quantrs (Rust) competes well in terms of performance: E.g., for pricing a European call with the Merton Black-Scholes model, quantrs is:

  • 87x faster than py_vollib
  • 29x faster than QuantLib (python bindings)
  • 15x faster than RustQuant
  • 3x faster than Q-Fin
  • 1.7x slower than QuantLib (cpp)
Library Mean Execution Time (μs) Median Execution Time (μs) Standard Deviation (μs) Operations / Second (OPS)
quantrs 0.0971 0.0970 0.0007 10,142,000
quantrs (py) TODO TODO TODO TODO
py_vollib 8.5341 8.5210 0.8129 117,176
QuantLib (py) 2.8551 2.8630 0.9391 350,250
RustQuant 1.4777 1.4750 0.0237 676,727
Q-Fin 0.2900 0.2906 0.0448 3,447,870
QuantLib (cpp) 0.0556 n.a. n.a. 17,958,600

You can find the benchmarks at quantrs.pages.dev/report.

Published benchmarks have been measured on a selfhosted VM with 32 GB RAM, AMD Ryzen 7 PRO 6850U @ 2.70GHz, and Manjaro Linux x86_64

Contributing

If you find any bugs or have suggestions for improvement, please open a new issue or PR. See OUTLOOK.md for a list of planned features and improvements.

You can generate and test the Python bindings with:

python -m venv .venv
source .venv/bin/activate
pip install maturin
# Build and install your package in editable mode
maturin develop --features python
# Run tests
pytest bindings/python/tests

Disclaimer

This library is not intended for professional use. It is a hobby project and should be treated as such.

The python bindings are automatically generated using PyO3 and may not cover all features of the Rust library.

License

This project is licensed under either of:

at your option.


© Carlo Bortolan

Carlo Bortolan  ·  GitHub carlobortolan  ·  contact via carlobortolan@gmail.com

Metadata

Release files for quantrs 0.0.1

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

Source distribution (sdist)

Source distribution for quantrs 0.0.1
File Size Uploaded
quantrs-0.0.1.tar.gz 108.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for quantrs 0.0.1
File Interpreter ABI Platform
quantrs-0.0.1-cp313-cp313-manylinux_2_34_x86_64.whl CPython 3.13 CPython 3.13 Linux glibc 2.34+ x86-64 Details

Total release size: 425.2 kB

Release files / quantrs-0.0.1.tar.gz

Download URL quantrs-0.0.1.tar.gz
Size 108.6 kB
Tags Source
SHA-256 checksum
How to use checksums
9bdbf82ca027af0463cf137835e164402e6d537c9f270e4dc7293bd00e9ad004
BLAKE2b-256 checksum
How to use checksums
dada888a6021938e312c2856dd256bd6a9b0734ce69e0d001db23e29469d3277
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.9.4

Release files / quantrs-0.0.1-cp313-cp313-manylinux_2_34_x86_64.whl

Download URL quantrs-0.0.1-cp313-cp313-manylinux_2_34_x86_64.whl
Size 316.6 kB
Tags CPython 3.13 Linux glibc 2.34+ x86-64
SHA-256 checksum
How to use checksums
cfefa98532987afec1885c021b98b23bbaf0fddada1f9825eaa358a5ae7366d1
BLAKE2b-256 checksum
How to use checksums
ab7003d53803369248062042b1bb4027c16fba5bb5c997825dd6d4914e2ab7da
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.9.4

Release history Release notifications | RSS feed

This release

0.0.1 This release

2 release files

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