Reputation: 39
I am trying to get XIRR for each customer with multiple entries with dates and payments in float. I want to find XIRR for each customer by grouping them with Unique ID
Code I am trying
import pandas as pd
from pyxirr import xirr
result = df.groupby("ID")[["date","payment"]].apply(xirr)`
where df id my dataframe and ID, date and payment are my columns
I am getting error as InvalidPaymentsError: negative and positive payments are required
Upvotes: 0
Views: 451
Reputation: 2918
In order to calculate XIRR, you need both positive and negative payments. This error means that some of the groups have only negative or only positive payments. You can suppress this exception by using silent=True
parameter (link).
df.groupby("ID")[["date","payment"]].apply(xirr, silent=True)
Upvotes: 0