Python bindings for a tiny library for quantitative finance (powered by Rust)
Project description
quantrs (python bindings)
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
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 quantrs-0.0.1.tar.gz.
File metadata
- Download URL: quantrs-0.0.1.tar.gz
- Upload date:
- Size: 108.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.9.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9bdbf82ca027af0463cf137835e164402e6d537c9f270e4dc7293bd00e9ad004
|
|
| MD5 |
ab754b5d5c03f808215eabebc1e6fcb1
|
|
| BLAKE2b-256 |
dada888a6021938e312c2856dd256bd6a9b0734ce69e0d001db23e29469d3277
|
File details
Details for the file quantrs-0.0.1-cp313-cp313-manylinux_2_34_x86_64.whl.
File metadata
- Download URL: quantrs-0.0.1-cp313-cp313-manylinux_2_34_x86_64.whl
- Upload date:
- Size: 316.6 kB
- Tags: CPython 3.13, manylinux: glibc 2.34+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.9.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cfefa98532987afec1885c021b98b23bbaf0fddada1f9825eaa358a5ae7366d1
|
|
| MD5 |
468263cf7f1b3434781467196b93e950
|
|
| BLAKE2b-256 |
ab7003d53803369248062042b1bb4027c16fba5bb5c997825dd6d4914e2ab7da
|