我正在使用 numpy 和我自己的代码计算 NPV,结果不同。我一定是在某个地方犯了错误。任何指针?
// Solution 1
r = .06
flows = {0:1200, 3:-450, 6:-450, 15:-450}
print sum([C/(1+r)**i for i,C in flows.iteritems()])
// => 317
// Solution using numpy's npv function
flows = zeros(16)
flows[0] = 1200
flows[3] = -450
flows[6] = -450
flows[15]= -450
print np.npv(r, flows)
// => 299
最佳答案
看起来(尽管它说的是 in the docs )np.npv
从 t = 1 开始求和,而不是 t = 0:
In [56]: r = 0.06
In [57]: R = r+1
In [58]: (1200/R**0 - 450/R**3 - 450/R**6 - 450/R**15)
Out[58]: 317.16980210661666
In [59]: (1200/R**0 - 450/R**3 - 450/R**6 - 450/R**15)/R
Out[59]: 299.21679444020435
In [64]: np.npv(r, flows)*(1+r)
Out[64]: 317.16980210661683
事实上,
np.npv
是 defined this way :def npv(rate, values):
values = np.asarray(values)
return (values / (1+rate)**np.arange(1,len(values)+1)).sum(axis=0)
关于python - Numpy 的 npv 计算,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/11923953/