I am trying to apply an XIRR Formula so that the percentage of each investment is calculated separately.
I Have data in excel file like:
https://i.stack.imgur.com/yqMiV.png
headers: Script,date,Values
result : Scrip and XIRR
Used Python library:
#pip install pyxirr
from pyxirr import xirr
I am Calculating for single script code like the below and appending it to a dataframe:
S1= df[["Date","Value"]][df["Script"]=="S1"]
S1= S1[["Date","Value"]]
S1_1= round(xirr(S1),2)*100
S1_1= pd.DataFrame({"Script": "S1","XIRR": S1_1},index=[1])
XIRR = XIRR.append(S1_1, ignore_index=True)
How can I apply a function/loop to calculate different scripts at one place and create a new dataframe of the results(image is attached).