我试图用python建立一个可以一次性计算outstanding_balance
的方程。使用迭代过程非常简单。例如:
for month in range(1, self.amortMonths + 1):
# Calculate intial and future interest payments
interest = self.originalPrin * self.rate / 12
# Calculate intial and future principal payments
principal_pmt = self.pmt - interest
# Outstanding balance is reduced by the principal_pmt
self.originalPrin = self.originalPrin - principal_pmt
因此self.amortMonths
基本上是每月必须还清贷款的期限,与self.rate
一起,他们将确定self.pmt
变量,即借款人必须支付的每月金额,以便在self.amortMonths
结束时将{0
。在
示例:
假设我有一笔1000美元的贷款,利率是10%,那么我第一个月的利息是1000*10%=100美元。为了找到self.pmt
金额,我使用了一个numpy.pmt
函数,该函数以未结余额prin、rate、amortMonths为参数来生成一个月付款值,该值将在分期付款月结束时将未付金额减少到0。假设self.pmt = $120
,然后principal_pmt = 120 - 100 = $20
。因此,下个月的未付款项是1000-20=$980
。然后这就变成了一个迭代过程。在
所以我需要一些帮助来确定一个方程,它可以在不需要迭代过程的情况下一次性完成。显然,我需要用线性代数,但我不是数学出身,所以我想知道有没有人有什么想法?在
编辑:
所以像这样:
Balance_i = Balance_i-1 - (pmt - Balance_i-1 * Rate)
。在
这是我的解决方案。在
我根据手工计算手工创建的数组值。下一步我要弄清楚如何根据期限、原始余额和利率自动生成它们。在
下面创建了一个设置了以下值的this Excel example的Python实现:
接下来,您可以使用NumPy的Financial functions来计算每个时期的利息和本金。请注意,这些并不取决于您的流动贷款余额。好在下面的结果是数组(付款计划):
^{pr2}$计算特定时间的未偿余额使用:
我们可以在下面定义。执行时要小心标志。在
另外,计算一个“恒定”的PMT值。这是利息加本金,在所有时期都是不变的。它是一个标量值,而不是数组。在
最后,将上述内容以表格形式汇总:
相关问题 更多 >
编程相关推荐