我需要能够以与 EXCEL 函数相同的方式计算年利率速度然而我无法在任何地方找到其背后的数学原理。
我最好用 ruby 或 python 来实现它。
答案1
您可以在 Ruby 中使用 Exonio 库:
https://github.com/Noverde/exonio
像这样:
Exonio.rate(number_of_periods, payment_per_period, present_value)
答案2
答案3
这是一个非常简单的例子虚拟专用网络:
Function MyRATE(nper As Integer, pmt As Double, pv As Double, Optional fv As Double = 0, _
Optional PaymentEnd As Integer = 0, Optional guess As Double = 0.1)
Dim a As Double, b As Double, c As Double ' coefficients of the equation
Dim R As Double, RTmp As Double, i As Integer
' Initialize coefficients and R
R = 1 + guess
a = (pmt * (1 - PaymentEnd) - pv) / (pv + pmt * PaymentEnd)
b = (fv - pmt * PaymentEnd) / (pv + pmt * PaymentEnd)
c = (-pmt * (1 - PaymentEnd) - fv) / (pv + pmt * PaymentEnd)
' Iterate
For i = 1 To 20
RTmp = R - (R ^ (nper + 1) + a * R ^ nper + b * R + c) / ((nper + 1) * R ^ nper + a * nper * R ^ (nper - 1) + b)
If Abs(RTmp - R) < 0.0000001 Then Exit For
R = RTmp
Next i
If i <= 20 Then
MyRATE = RTmp - 1
Else
MyRATE = "N/A" ' Must try another guess
End If
End Function
使用该函数(在工作表单元格中):
请注意第三个参数的减号和乘以 12。