Calculate Present value for groups with different interest rates

Viewed 17

I would like to ask you to help me find a solution.

I would like to use something like df.groupby('Client') and apply to it custom function that calculates Present Value of all cash flows for each client. The method of calculation PV for different discount rates is mentioned in excel formula on attached image. The problem is that Discount rate and payments aren't constant.

Can you plase help?

Here comes the DataFrame:

pd.DataFrame([
    ['Ann',1,100,0.05],
     ['Ann',2,200,0.06],
     ['Ann',3,100,0.07],
     ['Tamara',1,300,0.05],
     ['Tamara',2,100,0.08],
     ['Tamara',3,200,0.09]],columns=['Client','Period','Payment','Discount rate'])

Excel formula shows the process of PV of cash flows caluclation for each client

1 Answers

def pv_custom_function(x):
discount1 = x['Payment'] / ((x['Discount rate'] + 1).cumprod())
return discount1.sum()
data.groupby('Client').apply(pv_custom_function)

Related