在负利率的 PV 公式中查找术语
Finding Term in PV formula with negative interest rate
我正在尝试复制 BA II Plus 在普通年金公式的现值中查找项 (N) 的精度。具体来说,负利率(我不能使用自然对数)。我的代码在下面,但它既慢又准确。有更好的方法吗?
# code to find term (n) in present value of annuity formula, where the
# interest rate is negative, i.e. -55.31257% in below example, as the
# general way to solve, i.e natural logarithms don't work with negative
# interest rates.
pv = 1559606.4
pp = 100
i = -.5531257
# below is the desired answer
# n = 11.251357
# where interest rate is negative
for num in range(1,100000000):
expn = num/1000000
temp3 = pv - pp*(1 - (1+i)**-expn)/i
#set level of precision, i.e. accurate to within
if temp3 <= 0.00000001:
n = num/1000000
print("The Number of periods is " + str(n))
n = float(n)
break
我会使用 numpy.nper()
,例如:
代码:
import numpy as np
np.nper(i, -pp, pv)
测试代码:
pv = 1559606.4
pp = 100
i = -.5531257
# below is the desired answer
# n = 11.251357
import numpy as np
print(np.nper(i, pp, -pv))
结果:
11.2513570023
我正在尝试复制 BA II Plus 在普通年金公式的现值中查找项 (N) 的精度。具体来说,负利率(我不能使用自然对数)。我的代码在下面,但它既慢又准确。有更好的方法吗?
# code to find term (n) in present value of annuity formula, where the
# interest rate is negative, i.e. -55.31257% in below example, as the
# general way to solve, i.e natural logarithms don't work with negative
# interest rates.
pv = 1559606.4
pp = 100
i = -.5531257
# below is the desired answer
# n = 11.251357
# where interest rate is negative
for num in range(1,100000000):
expn = num/1000000
temp3 = pv - pp*(1 - (1+i)**-expn)/i
#set level of precision, i.e. accurate to within
if temp3 <= 0.00000001:
n = num/1000000
print("The Number of periods is " + str(n))
n = float(n)
break
我会使用 numpy.nper()
,例如:
代码:
import numpy as np
np.nper(i, -pp, pv)
测试代码:
pv = 1559606.4
pp = 100
i = -.5531257
# below is the desired answer
# n = 11.251357
import numpy as np
print(np.nper(i, pp, -pv))
结果:
11.2513570023