Rust-powered collection of financial functions for Python.
Project description
PyXIRR
Rust-powered collection of financial functions.
Features:
- correct
- blazingly fast
- works with iterators
- works with unordered input
- no external dependencies
PyXIRR contains many functions from numpy-financial, such as IRR, NPV, etc.
Installation
pip install pyxirr
Benchmarks
Rust implementation has been tested against existing xirr package (uses scipy.optimize under the hood) and the implementation from the Stack Overflow (pure python).
PyXIRR is ~10-20x faster in XIRR calculation than another implementations.
Powered by github-action-benchmark and plotly.js.
Live benchmarks are hosted on Github Pages.
Examples
from datetime import date
from pyxirr import xirr
dates = [date(2020, 1, 1), date(2021, 1, 1), date(2022, 1, 1)]
amounts = [-1000, 1000, 1000]
# feed columnar data
xirr(dates, amounts)
# feed iterators
xirr(iter(dates), (x / 2 for x in amounts))
# feed an iterable of tuples
xirr(zip(dates, amounts))
# feed a dictionary
xirr(dict(zip(dates, amounts)))
Numpy and Pandas support
import numpy as np
import pandas as pd
# feed numpy array
xirr(np.array([dates, amounts]))
xirr(np.array(dates), np.array(amounts))
# feed DataFrame (columns names doesn't matter; ordering matters)
xirr(pd.DataFrame({"a": dates, "b": amounts}))
# feed Series with DatetimeIndex
xirr(pd.Series(amounts, index=pd.to_datetime(dates)))
# bonus: apply xirr to a DataFrame with DatetimeIndex:
df = pd.DataFrame(
index=pd.date_range("2021", "2022", freq="MS", closed="left"),
data={
"one": [-100] + [20] * 11,
"two": [-80] + [19] * 11,
},
)
df.apply(xirr) # Series(index=["one", "two"], data=[5.09623547168478, 8.780801977141174])
API reference
See the docs
Roadmap
- Improve docs, add more tests
- Other functions from numpy-financial
- Compile library for rust/javascript/python
- Vectorized versions of numpy-financial functions.
Development
Running tests with pyo3 is a bit tricky. In short, you need to compile your tests without extension-module
feature to avoid linking errors.
See the following issues for the details: #341, #771.
If you are using pyenv
, make sure you have the shared library installed (check for ${PYENV_ROOT}/versions/<version>/lib/libpython3.so
file).
$ PYTHON_CONFIGURE_OPTS="--enable-shared" pyenv install <version>
Install dev-requirements
$ pip install -r dev-requirements.txt
Building
$ maturin develop
Testing
$ LD_LIBRARY_PATH=${PYENV_ROOT}/versions/3.8.6/lib cargo test --no-default-features --features tests
Building and distribution
This library uses maturin to build and distribute python wheels.
$ docker run --rm -v $(pwd):/io konstin2/maturin build --release --manylinux 2010 --strip
$ maturin upload target/wheels/pyxirr-${version}*
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 Distributions
Hashes for pyxirr-0.6.2-cp39-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bd7f6c86286085f400c18a83d601f8b1c04cb22bfba7d8f232cfefb79ec8dd89 |
|
MD5 | 3bfe47ba1ecf74d0cfb52dbecde0c624 |
|
BLAKE2b-256 | 34db04889bee0bd2ca3cb8e3a0042dc0d1a123e3e655519804b18493aafbb09f |
Hashes for pyxirr-0.6.2-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 13dc70e575f1c6500f050eedc238da8c51d4896e5eaad795081a10b40f73ec7f |
|
MD5 | ebe98e7e36db62b61bbe239669832f13 |
|
BLAKE2b-256 | a948cf8f9da977ee77745604753049be4c06de6506e9808d90647013efa1d6de |
Hashes for pyxirr-0.6.2-cp39-cp39-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 496d71e6aa7a492c7bf412bfeda66dd02361d1f1bb6bf9c9459467d421651642 |
|
MD5 | 3fe7bca072dd0a44e47d27061ae6f1d7 |
|
BLAKE2b-256 | 4505e8d55922f4c75d58bc472e85ed815d53c61b694eed27390a5b9a2053ac55 |
Hashes for pyxirr-0.6.2-cp38-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 162fdb55c7e36e66e37fd17278f4eff8a65cb908bb3b46e9148b6facfff82dd3 |
|
MD5 | 3d6d1c420ddb9ffb89fc047c330c1795 |
|
BLAKE2b-256 | 44700415bc90dc1fca043f8ea7259d991bd91466255eaec970ff310383d67011 |
Hashes for pyxirr-0.6.2-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d7e81bbc213834e55b23a1a5f30917722f2ccf07cc78ac665ceff59161dfc2e5 |
|
MD5 | 8ffc7c4cce99eb8a4fe9933a6909a371 |
|
BLAKE2b-256 | 69732a3a716ee8767f9b4d7ff4e45541635e340592c8a3e925211d3e341ffbe3 |
Hashes for pyxirr-0.6.2-cp38-cp38-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | af2638f4b5db213e9d4b2b49c9058ed3236f7c6800e412b90f614a47742cafae |
|
MD5 | e418d067bfff6bf5822705d857e7c952 |
|
BLAKE2b-256 | cc1c5b99963aafa7b56ee1ae354a6530d508bca4346d82b898b47ff0f8951b24 |
Hashes for pyxirr-0.6.2-cp37-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 83ba624c3995c01b2d13e4f3f1f7865e730d632bb07690aa230f857cfd0fee8d |
|
MD5 | a76f98519567f12fbf87d63c28b0be1e |
|
BLAKE2b-256 | d92ea831aef1e4229f641bfb41e5fe5d0c3e6d23465c09ff64495a4c183d462d |
Hashes for pyxirr-0.6.2-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4b15c1bd7d0add20c8220fa714646c96e5d1b98d0059a2d17d82f745ca4c7b41 |
|
MD5 | 81c8fa180b25a93b0137975e694ddbf7 |
|
BLAKE2b-256 | 58f405a30baf74a7dd2768132c07f944dd60d4380684af839873d455a7fcbbea |
Hashes for pyxirr-0.6.2-cp37-cp37m-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fae814eb3b90535832ee10ad5295b3e77cd8037790bd021cf94d949becae8ebe |
|
MD5 | 0719371e52a48a58e30ab21c22d59ce1 |
|
BLAKE2b-256 | 1724f9357102c649c4a9636d362de5c7f51de0087197d37acbbe27dbb1a515ef |
Hashes for pyxirr-0.6.2-cp36-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | eb5c75a3daa8c20ed550194128eb9d0bf1d7fa286cf27897d83b31a981aa437e |
|
MD5 | 9cf3758071a5ac411c8702198c151e1c |
|
BLAKE2b-256 | 5059a7bff0063a9ab134f752bd9ff7c8f1a0dc5af0ce3a17e549b549840f3e2a |
Hashes for pyxirr-0.6.2-cp36-cp36m-manylinux_2_5_x86_64.manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a87e6b2a674105e47a131ecb7b605f863dbc2e801d9f9fce25e79131b4c2b20b |
|
MD5 | 7f9e9802f740c1373ba1ef2e7bd1c910 |
|
BLAKE2b-256 | f241058096921824f779c722535a615dc31f26c9b5eaa726570c5db52712c16e |
Hashes for pyxirr-0.6.2-cp36-cp36m-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3a2bab6840c7c7771f96b5781a33876d183c82ed795ba6227ef10ad27da92b12 |
|
MD5 | 7c5d812f97e8348dc71c1ca8da0c4c13 |
|
BLAKE2b-256 | 243592a734d619717f8c3b187a372738c1873852eaf0cf14c46f3fa87bd4ea06 |