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.
pip install quantrsimport 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")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}")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
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/testsThis 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.
This project is licensed under either of:
at your option.
© Carlo Bortolan
Carlo Bortolan · GitHub carlobortolan · contact via carlobortolan@gmail.com