pandas 计算不同利率组的现值

ggazkfy8  于 2023-04-28  发布在  其他
关注(0)|答案(1)|浏览(99)

我想请你帮我找到一个解决办法。
我想使用类似df.groupby('Client ')的东西,并将其应用于计算每个客户所有现金流现值的自定义函数。在所附图像的Excel公式中提到了计算不同折扣率的PV的方法。问题是折扣率和付款不是恒定的。
你能帮帮忙吗?
下面是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'])

2ic8powd

2ic8powd1#

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

相关问题