Anexen / pyxirr

Rust-powered collection of financial functions.
https://anexen.github.io/pyxirr/
The Unlicense
172 stars 16 forks source link

XIRR for a pd.Series #39

Closed askmedov closed 1 year ago

askmedov commented 1 year ago

Currently XIRR calculates IRR (or YTM) for a single date. But it would be awesome if I could provide it (or a different function) with a pd.Series of a bond's or bill's prices across time to calculate XIRR for every point.

For example if we have:

import pandas as pd

prices = pd.Series({
    '2020-01-01': 100,
    '2020-08-01': 103
})
prices.index = pd.to_datetime(prices.index)

bond_schedule = pd.Series({
    '2020-07-01': 10,
    '2021-01-01': 110
})

then I would need to create a new arguments for dates and amounts for every date/price, i.e. ['2020-01-01', '2020-07-01'] and [-100, 10, 110] , ['2020-08-01', '2021-01-01'] and [-103, 110]. And it could be that I have not 2, but hundreds of dates. As you can see here, as date/prices grow newer, some of the amounts aren't relevant anymore as well. Would be awesome if it's implemented!

Anexen commented 1 year ago

Hi, @askmedov, It looks like a use case for a specific application, and I'm not sure if it would be useful for other users. The library is focused on a basic financial functions.

If you're experiencing performance issues with pandas, I'll be happy to help. If you know similar function in excel, I will implement it in PyXIRR.