Skip to main content

Rust-powered collection of financial functions for Python.

Project description

rust-lang.org License pypi versions

PyXIRR

Rust-powered collection of financial functions.

PyXIRR stands for "Python XIRR" (for historical reasons), but contains many other financial functions such as IRR, FV, NPV, etc.

Features:

  • correct
  • blazingly fast
  • works with different input data types (iterators, numpy arrays, pandas DataFrames)
  • no external dependencies

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).

bench

PyXIRR is ~10-20x faster in XIRR calculation than the other 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, 750, 500]

# 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)))
# dates as strings
xirr(['2020-01-01', '2021-01-01'], [-1000, 1200])

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])

Other financial functions:

import pyxirr

# Future Value
pyxirr.fv(0.05 / 12, 10 * 12, -100, -100)

# Net Present Value
pyxirr.npv(0, [-40_000, 5_000, 8_000, 12_000, 30_000])

# IRR
pyxirr.irr([-100, 39, 59, 55, 20])

# ... and more! Check out the docs.

API reference

See the docs

Roadmap

  • Implement all functions from numpy-financial
  • Improve docs, add more tests
  • Type hints
  • Vectorized versions of numpy-financial functions.
  • Compile library for rust/javascript/python

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

Benchmarks

$ pip install -r bench-requirements.txt
$ LD_LIBRARY_PATH=${PYENV_ROOT}/versions/3.8.6/lib cargo +nightly bench --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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyxirr-0.7.2.tar.gz (128.7 kB view hashes)

Uploaded Source

Built Distributions

pyxirr-0.7.2-cp311-none-win_amd64.whl (151.0 kB view hashes)

Uploaded CPython 3.11 Windows x86-64

pyxirr-0.7.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (221.0 kB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

pyxirr-0.7.2-cp311-cp311-manylinux_2_17_s390x.manylinux2014_s390x.whl (261.0 kB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ s390x

pyxirr-0.7.2-cp311-cp311-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (336.3 kB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ ppc64le

pyxirr-0.7.2-cp311-cp311-manylinux_2_17_ppc64.manylinux2014_ppc64.whl (340.5 kB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ ppc64

pyxirr-0.7.2-cp311-cp311-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (205.6 kB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ ARMv7l

pyxirr-0.7.2-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (203.2 kB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ ARM64

pyxirr-0.7.2-cp311-cp311-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl (388.1 kB view hashes)

Uploaded CPython 3.11 macOS 10.9+ universal2 (ARM64, x86-64) macOS 10.9+ x86-64 macOS 11.0+ ARM64

pyxirr-0.7.2-cp310-none-win_amd64.whl (161.9 kB view hashes)

Uploaded CPython 3.10 Windows x86-64

pyxirr-0.7.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (221.0 kB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

pyxirr-0.7.2-cp310-cp310-manylinux_2_17_s390x.manylinux2014_s390x.whl (261.0 kB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ s390x

pyxirr-0.7.2-cp310-cp310-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (336.3 kB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ ppc64le

pyxirr-0.7.2-cp310-cp310-manylinux_2_17_ppc64.manylinux2014_ppc64.whl (340.5 kB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ ppc64

pyxirr-0.7.2-cp310-cp310-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (205.6 kB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ ARMv7l

pyxirr-0.7.2-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (203.2 kB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ ARM64

pyxirr-0.7.2-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.whl (229.1 kB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.5+ x86-64

pyxirr-0.7.2-cp310-cp310-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl (406.5 kB view hashes)

Uploaded CPython 3.10 macOS 10.9+ universal2 (ARM64, x86-64) macOS 10.9+ x86-64 macOS 11.0+ ARM64

pyxirr-0.7.2-cp39-none-win_amd64.whl (161.9 kB view hashes)

Uploaded CPython 3.9 Windows x86-64

pyxirr-0.7.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (220.9 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

pyxirr-0.7.2-cp39-cp39-manylinux_2_17_s390x.manylinux2014_s390x.whl (274.0 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ s390x

pyxirr-0.7.2-cp39-cp39-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (326.4 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ ppc64le

pyxirr-0.7.2-cp39-cp39-manylinux_2_17_ppc64.manylinux2014_ppc64.whl (336.0 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ ppc64

pyxirr-0.7.2-cp39-cp39-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (216.5 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ ARMv7l

pyxirr-0.7.2-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (207.3 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ ARM64

pyxirr-0.7.2-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.whl (229.1 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.5+ x86-64

pyxirr-0.7.2-cp39-cp39-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl (406.4 kB view hashes)

Uploaded CPython 3.9 macOS 10.9+ universal2 (ARM64, x86-64) macOS 10.9+ x86-64 macOS 11.0+ ARM64

pyxirr-0.7.2-cp38-none-win_amd64.whl (162.0 kB view hashes)

Uploaded CPython 3.8 Windows x86-64

pyxirr-0.7.2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (221.1 kB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

pyxirr-0.7.2-cp38-cp38-manylinux_2_17_s390x.manylinux2014_s390x.whl (273.9 kB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ s390x

pyxirr-0.7.2-cp38-cp38-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (326.4 kB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ ppc64le

pyxirr-0.7.2-cp38-cp38-manylinux_2_17_ppc64.manylinux2014_ppc64.whl (336.0 kB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ ppc64

pyxirr-0.7.2-cp38-cp38-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (216.6 kB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ ARMv7l

pyxirr-0.7.2-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (207.3 kB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ ARM64

pyxirr-0.7.2-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.whl (229.1 kB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.5+ x86-64

pyxirr-0.7.2-cp38-cp38-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl (406.5 kB view hashes)

Uploaded CPython 3.8 macOS 10.9+ universal2 (ARM64, x86-64) macOS 10.9+ x86-64 macOS 11.0+ ARM64

pyxirr-0.7.2-cp37-none-win_amd64.whl (162.0 kB view hashes)

Uploaded CPython 3.7 Windows x86-64

pyxirr-0.7.2-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (221.1 kB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.17+ x86-64

pyxirr-0.7.2-cp37-cp37m-manylinux_2_17_s390x.manylinux2014_s390x.whl (273.9 kB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.17+ s390x

pyxirr-0.7.2-cp37-cp37m-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (326.4 kB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.17+ ppc64le

pyxirr-0.7.2-cp37-cp37m-manylinux_2_17_ppc64.manylinux2014_ppc64.whl (336.0 kB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.17+ ppc64

pyxirr-0.7.2-cp37-cp37m-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (216.6 kB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.17+ ARMv7l

pyxirr-0.7.2-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (207.3 kB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.17+ ARM64

pyxirr-0.7.2-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.whl (229.1 kB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.5+ x86-64

pyxirr-0.7.2-cp37-cp37m-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl (406.5 kB view hashes)

Uploaded CPython 3.7m macOS 10.9+ universal2 (ARM64, x86-64) macOS 10.9+ x86-64 macOS 11.0+ ARM64

pyxirr-0.7.2-cp36-none-win_amd64.whl (162.4 kB view hashes)

Uploaded CPython 3.6 Windows x86-64

pyxirr-0.7.2-cp36-cp36m-manylinux_2_17_s390x.manylinux2014_s390x.whl (273.4 kB view hashes)

Uploaded CPython 3.6m manylinux: glibc 2.17+ s390x

pyxirr-0.7.2-cp36-cp36m-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (326.1 kB view hashes)

Uploaded CPython 3.6m manylinux: glibc 2.17+ ppc64le

pyxirr-0.7.2-cp36-cp36m-manylinux_2_17_ppc64.manylinux2014_ppc64.whl (335.2 kB view hashes)

Uploaded CPython 3.6m manylinux: glibc 2.17+ ppc64

pyxirr-0.7.2-cp36-cp36m-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (216.2 kB view hashes)

Uploaded CPython 3.6m manylinux: glibc 2.17+ ARMv7l

pyxirr-0.7.2-cp36-cp36m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (207.4 kB view hashes)

Uploaded CPython 3.6m manylinux: glibc 2.17+ ARM64

pyxirr-0.7.2-cp36-cp36m-manylinux_2_5_x86_64.manylinux1_x86_64.whl (229.0 kB view hashes)

Uploaded CPython 3.6m manylinux: glibc 2.5+ x86-64

pyxirr-0.7.2-cp36-cp36m-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl (406.3 kB view hashes)

Uploaded CPython 3.6m macOS 10.9+ universal2 (ARM64, x86-64) macOS 10.9+ x86-64 macOS 11.0+ ARM64

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page