贷款支付模型计算内部收益率

2024-10-04 01:27:20 发布

您现在位置:Python中文网/ 问答频道 /正文

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

df_irr = df1[['id', 'funded_amnt_t', 'Expect_NoPayments','installment']]

贷款ID |资金金额|预期付款次数|年金的固定分期付款。你知道吗

我用回归分析法估计了付款的次数。 这些贷款有36或60个月的到期日。你知道吗

现在我正试图计算预期的内部收益率(irr)。你知道吗

但我被困住了

我打算用numpy.irr 然而,我从来没有机会使用它-因为我的日期不是在正确的格式?你知道吗

我尝试过旋转和重塑功能。运气不好。你知道吗

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

我以前的状态代码是:

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

enter image description here


Tags: 数据id次数金额cfexpand资金贷款
1条回答
网友
1楼 · 发布于 2024-10-04 01:27:20

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'])

更多信息可以在这里找到numpy documentation。你知道吗

相关问题 更多 >