处理贷款数据。我有一个包含列的数据框:
df_irr = df1[['id', 'funded_amnt_t', 'Expect_NoPayments','installment']]
贷款ID | 资助金额 | 预期付款次数 | 固定分期年金。
我用回归分析估计了付款次数。贷款期限为 36 或 60 个月。
现在我正在尝试计算预期的 irr(内部收益率)。
但我被困住了
我打算使用numpy.irr
但是,我从来没有机会使用它——因为我的日期格式不正确?
我尝试过 pandas pivot 和 reshape 函数。没运气。
现金流的时间序列: - 列:第 0 个月,...,60 - 行:每笔贷款的 ID - 第 0 个月的值 = - funded_amount - 第 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