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
File details
Details for the file pyxirr-0.6.3.tar.gz
.
File metadata
- Download URL: pyxirr-0.6.3.tar.gz
- Upload date:
- Size: 117.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/0.11.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 96580f2c0a40f8b1db581ec2f7d84403ef467f8e46e57ca16274691f014f631d |
|
MD5 | 2b0286869b70da64aa620da0335c84a9 |
|
BLAKE2b-256 | 6f05efc05c3f662fac1871e6062405066ee397cad8156164c0d451a9a0f03451 |
File details
Details for the file pyxirr-0.6.3-cp39-none-win_amd64.whl
.
File metadata
- Download URL: pyxirr-0.6.3-cp39-none-win_amd64.whl
- Upload date:
- Size: 130.9 kB
- Tags: CPython 3.9, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/0.11.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3f38665e3a8c2dab686e5e5593df14aa141c11afbb552fc28f15c2bb462e4d8e |
|
MD5 | 4129ffed6f1b014e4e53697ef68fc5da |
|
BLAKE2b-256 | 0100ea3d4a4594a39aab4006a88889ad9f5a5695bf873514115c1852b4cf98ee |
File details
Details for the file pyxirr-0.6.3-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.whl
.
File metadata
- Download URL: pyxirr-0.6.3-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.whl
- Upload date:
- Size: 184.2 kB
- Tags: CPython 3.9, manylinux: glibc 2.5+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/0.11.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 64d689c47840f07cc29b50c6cc565749332fe197f059f5af819f5a7cbd5bac0a |
|
MD5 | 9d5ce3c3defa4887496712e3ad3f79ad |
|
BLAKE2b-256 | af7c21291a17747ac1bf9f5a28479c569b0a604cdadfe922ba3204f4d04b67e2 |
File details
Details for the file pyxirr-0.6.3-cp39-cp39-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
.
File metadata
- Download URL: pyxirr-0.6.3-cp39-cp39-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
- Upload date:
- Size: 341.9 kB
- Tags: CPython 3.9, macOS 10.9+ universal2 (ARM64, x86-64), macOS 10.9+ x86-64, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/0.11.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5a6f6c15d02d93ddee86066361733b5f109848125e904d3bcbf14fbf891eae2b |
|
MD5 | 182b2eb658939c3f4a6c1e15926f2201 |
|
BLAKE2b-256 | 9033b164618e20b6d9334811fc21a1531a3a5e83c238d1dc4fa860a4a513b9c8 |
File details
Details for the file pyxirr-0.6.3-cp38-none-win_amd64.whl
.
File metadata
- Download URL: pyxirr-0.6.3-cp38-none-win_amd64.whl
- Upload date:
- Size: 130.9 kB
- Tags: CPython 3.8, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/0.11.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 582b30ef4546e093b9cebfc3048b91db2c93431387fa73a90e4454ad1e6792ae |
|
MD5 | a901c6a2b6fe0ce6e0310251cadc5021 |
|
BLAKE2b-256 | 69bc862122e9a05565a2376043692bbab915f2481687c949eb86bdd09bd2966d |
File details
Details for the file pyxirr-0.6.3-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.whl
.
File metadata
- Download URL: pyxirr-0.6.3-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.whl
- Upload date:
- Size: 184.3 kB
- Tags: CPython 3.8, manylinux: glibc 2.5+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/0.11.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f736720d1a3a6b21661e25cb07f467fba938fccf7ef291576f1d9fd755d006cd |
|
MD5 | f93305f25719ba011cfcae26fd18b734 |
|
BLAKE2b-256 | 4bcf66e96f38c9e835ef28414a8f6f5b195d36221c78308a6be25a23adb2a36a |
File details
Details for the file pyxirr-0.6.3-cp38-cp38-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
.
File metadata
- Download URL: pyxirr-0.6.3-cp38-cp38-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
- Upload date:
- Size: 341.9 kB
- Tags: CPython 3.8, macOS 10.9+ universal2 (ARM64, x86-64), macOS 10.9+ x86-64, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/0.11.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | dea2a3f2a5c07dfb0dc7df471e7a76dd5a30b46e053eb3be22e7d66aca00e2b8 |
|
MD5 | 3042736f5a23ce7f8a019ee5dca4f3d0 |
|
BLAKE2b-256 | 59d8e15afed0ced980de2e36b37d1413ead3157b5b5a86e5664c3caad18e5001 |
File details
Details for the file pyxirr-0.6.3-cp37-none-win_amd64.whl
.
File metadata
- Download URL: pyxirr-0.6.3-cp37-none-win_amd64.whl
- Upload date:
- Size: 130.9 kB
- Tags: CPython 3.7, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/0.11.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ae30fa2709f98f7a3e0ca8bb71f36234756b664c1996d04eef66172f8c71262c |
|
MD5 | 0d020204df21ffd2358a6154a92275bc |
|
BLAKE2b-256 | 76bd28ff83e6ed9ccb8b424e7f70ca727df3a5065640d20398f495546b6209ba |
File details
Details for the file pyxirr-0.6.3-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.whl
.
File metadata
- Download URL: pyxirr-0.6.3-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.whl
- Upload date:
- Size: 184.2 kB
- Tags: CPython 3.7m, manylinux: glibc 2.5+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/0.11.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 57bd10e20f63c785923218cec0a8362bc612f9cde7d2f59310f8c5ab176a7b14 |
|
MD5 | a61108370771e2044075a310701b629b |
|
BLAKE2b-256 | 131c23b6f5fb97a1f7382724166f2429f66ed3cd8f927d696ad79d337bbb0168 |
File details
Details for the file pyxirr-0.6.3-cp37-cp37m-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
.
File metadata
- Download URL: pyxirr-0.6.3-cp37-cp37m-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
- Upload date:
- Size: 341.9 kB
- Tags: CPython 3.7m, macOS 10.9+ universal2 (ARM64, x86-64), macOS 10.9+ x86-64, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/0.11.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | cc92e548b03e45da2c306c2cf76ff563bb3a3d5683dd1e0fee58a87c6869b313 |
|
MD5 | e3b3bfee443510fcea1ccd0cfa585c4f |
|
BLAKE2b-256 | 2e7befd468e01946fafe3d5b4d82859794fff940420688d7fe2bb1a6c1c2954c |
File details
Details for the file pyxirr-0.6.3-cp36-none-win_amd64.whl
.
File metadata
- Download URL: pyxirr-0.6.3-cp36-none-win_amd64.whl
- Upload date:
- Size: 131.2 kB
- Tags: CPython 3.6, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/0.11.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 99992068120d73fa102a6afef94bbe93dfefa176c348699c11cf187c73fb342a |
|
MD5 | 67cfb045dd8d1b45006cad9c0af02753 |
|
BLAKE2b-256 | 8d40a13104faf70bae0352306f8b9a0735205596dc7dbcd672c4a6651fe996c0 |
File details
Details for the file pyxirr-0.6.3-cp36-cp36m-manylinux_2_5_x86_64.manylinux1_x86_64.whl
.
File metadata
- Download URL: pyxirr-0.6.3-cp36-cp36m-manylinux_2_5_x86_64.manylinux1_x86_64.whl
- Upload date:
- Size: 184.2 kB
- Tags: CPython 3.6m, manylinux: glibc 2.5+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/0.11.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5c794d83f0d84d1dccf67a6145eeb1304971276f7567828ae443f0b8bc5e521f |
|
MD5 | 99895204f20a6b16a8a11f3643afeb9b |
|
BLAKE2b-256 | 7aa1f355e7e61f16008bf0d25a6e85f3a008abaa51822b7248cd5b1ce040a8a4 |
File details
Details for the file pyxirr-0.6.3-cp36-cp36m-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
.
File metadata
- Download URL: pyxirr-0.6.3-cp36-cp36m-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
- Upload date:
- Size: 341.9 kB
- Tags: CPython 3.6m, macOS 10.9+ universal2 (ARM64, x86-64), macOS 10.9+ x86-64, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/0.11.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5119ef810b7a01e5045161fedefdf915a849b3dbd4ef5045bc4d12d3adfdebac |
|
MD5 | 775362c4b124d044f1136911094b86de |
|
BLAKE2b-256 | 2853aceb00d61df1a9846b6661fd19bd47ba8971cc162554d3eb025d164e088e |