Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/318.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 贷款支付建模-计算内部收益率_Python_Pandas_Pivot_Reshape_Irr - Fatal编程技术网

Python 贷款支付建模-计算内部收益率

Python 贷款支付建模-计算内部收益率,python,pandas,pivot,reshape,irr,Python,Pandas,Pivot,Reshape,Irr,处理贷款数据。 我有一个包含以下列的数据框: df_irr = df1[['id', 'funded_amnt_t', 'Expect_NoPayments','installment']] 贷款ID |供资金额|预期付款次数|固定年金分期付款 我用回归分析估计了付款的数量。 贷款期限为36或60个月 现在我正试图计算预期的内部收益率(irr) 但是我被卡住了 我计划使用numpy.irr 然而,我从来没有机会使用它——因为我的约会格式不对 我尝试过旋转和重塑功能。不走运 现金流量的时间序列:

处理贷款数据。 我有一个包含以下列的数据框:

df_irr = df1[['id', 'funded_amnt_t', 'Expect_NoPayments','installment']]
贷款ID |供资金额|预期付款次数|固定年金分期付款

我用回归分析估计了付款的数量。 贷款期限为36或60个月

现在我正试图计算预期的内部收益率(irr)

但是我被卡住了

我计划使用
numpy.irr
然而,我从来没有机会使用它——因为我的约会格式不对

我尝试过旋转和重塑功能。不走运

现金流量的时间序列: -列:第0,…,60个月 -行:每个贷款的ID -第0个月的值=-资助金额 -第0-60个月的值:分期付款(如果预期)\付款次数>个月

我的旧Stata代码是:

keep id installment funded_amnt expectednumberofpayments
sort id
expand 61, generate(expand)
bysort id : gen month = _n      
gen cf = 0
replace cf = installment if (expectednumberofpayments+1)>=month
replace cf = funded_amnt*-1 if month==1

numpy。irr
是一个错误的公式。该公式适用于不定期付款(例如,第1个月为100美元,第2个月为0美元,第3个月为400美元)。相反,您希望使用
numpy.rate
。我正在对此解决方案的数据进行一些假设:

 import numpy as np
 df_irr['rate'] = np.rate(nper=df_irr['Expect_NoPayments'],
                          pmt=df_irr['installment'],
                          pv=df_irr['funded_amnt_t'])

更多信息可以在这里找到。

你的问题是什么?:-)需要重塑/构建数据框架的代码。我现在试过的东西:df_irr2=pd.dataframe(data=df_irr,index='id',columns='funded_amnt''Expect_NoPayments''instance')df_irr3=df_irr.groupby(by=df_irr['id'])df_irr.pivot(index='id',columns='Expect\u NoPayments',values='instance')不,不是解决方案。我仍然需要重塑我的数据集。为什么这不是解决方案?你所说的“重塑数据集”是什么意思如果你算一下,
IRR
与付款和
rate
相等,你会得到同样的结果。你能更具体地回答你的问题吗?如果你为这个问题添加了你想要的结果,这可能会很有用。亲爱的@Polkaguy6000我尽了最大的努力写了一个excel文件来解释想要的结果。不,我已经试过了表示范围(0,60)内的i:如果i==0:df_irrT['i']=df_irr[['funded_amnt_t']]如果i