Rust-powered collection of financial functions.
Project description
PyXIRR
Rust-powered collection of financial functions.
Features:
- correct
- blazingly fast
- works with iterators
- 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).
Implementation | Sample size | Execution time |
---|---|---|
pyxirr (Rust) | 100 | 45.89 us |
xirr (scipy) | 100 | 790.76 us |
pure Python | 100 | 14.37 ms |
pyxirr (Rust) | 1000 | 404.03 us |
xirr (scipy) | 1000 | 3.47 ms |
pure Python | 1000 | 35.97 ms |
pyxirr (Rust) | 10000 | 3.58 ms |
xirr (scipy) | 10000 | 28.04 ms |
pure Python | 10000 | 24.23 s |
PyXIRR is ~10-20x faster than other solutions!
Usage
xirr
Function signature:
# You have two options:
# 1. Two iterables for dates and amounts
# 2. Single iterable of tuples (date, amount)
DateLike = Union[datetime.date, datetime.datetime]
Amount = Union[int, float, Decimal]
def xirr(
dates: Union[Iterable[DateLike], Iterable[Tuple[DateLike, Amount]]]
amounts Optional[Iterable[Amount]] = None
guess: Optional[float] = None
)
Example:
from datetime import date
from pyxirr import xirr
dates = [date(2020, 1, 1), date(2020, 2, 1)]
amounts = [-100, 125]
xirr(dates, amounts)
# list of tuples is also possible:
xirr(zip(dates, amounts))
xnpv
Function signature:
# similar to xirr: iterable of tuples or two iterables
def xnpv(
rate: float,
dates: Union[Iterable[DateLike], Iterable[Tuple[DateLike, Amount]]]
amounts Optional[Iterable[Amount]] = None
)
Example:
from pyxirr import xnpv
xnpv(0.1, dates, amounts)
xnpv(0.1, zip(dates, amounts))
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).
$ export PYO3_PYTHON_VERSION=3.8.6
$ PYTHON_CONFIGURE_OPTS="--enable-shared" pyenv install ${PYO3_PYTHON_VERSION}
# running tests
$ LD_LIBRARY_PATH=${PYENV_ROOT}/versions/${PYO3_PYTHON_VERSION}/lib cargo tests --no-default-features --features tests
# running benches
$ LD_LIBRARY_PATH=${PYENV_ROOT}/versions/${PYO3_PYTHON_VERSION}/lib cargo bench --no-default-features --features tests
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.2.1-cp39-cp39-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1427fcdd1cc278dbc80cf3e43d5bce9414ec09bf076c3fe7180ae5137f1e146c |
|
MD5 | 569db012ee97637d97ed919373e15641 |
|
BLAKE2b-256 | 8b674664d45a8b17728f0875d47b4ccb8177b7f5bac563942667e34ef6e17bdf |
Hashes for pyxirr-0.2.1-cp38-cp38-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4fd4be4371bdfd79f8962bb54b78d49553f6dade01efb54324e1f6751becd06f |
|
MD5 | 15bf0fd15c0f5bf9578d49532cc768de |
|
BLAKE2b-256 | f6c0e6ad8e01d127b9cf17d9ff3ab80596f650bc826f1579ae3627b1020486a9 |
Hashes for pyxirr-0.2.1-cp37-cp37m-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 482303b49105f20d066a47b1dfa6b26f07a6e23ce376a19b5bfd3cead1d8455f |
|
MD5 | d966ce3154360c1f37c4c45235004347 |
|
BLAKE2b-256 | 9dac4c1f3efcb51dd6eaf32a4b458533969ec281ea8c340c4d53520f6cf3f732 |
Hashes for pyxirr-0.2.1-cp36-cp36m-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b2ba9aecfaba849510839d802f0244136860594f4d1fd437d5e52cf0ad8674e4 |
|
MD5 | e6c2248ed7fd027b6ffeef5559d4562f |
|
BLAKE2b-256 | 189a5999abc61eb7d8f6513da24a9d61f9959a69ecd4cdc0e1a8b62a8e437c97 |