gpt4 book ai didi

python - 这个 IRR 的实现中使用的数值方法是什么?

转载 作者:太空狗 更新时间:2023-10-29 22:23:43 26 4
gpt4 key购买 nike

ActiveState Recipes站点具有实现 Internal Rate of Return 的功能在 Python 中:

def irr(cashflows, iterations=100):
"""The IRR or Internal Rate of Return is the annualized effective
compounded return rate which can be earned on the invested
capital, i.e., the yield on the investment.

>>> irr([-100.0, 60.0, 60.0, 60.0])
0.36309653947517645
"""
rate = 1.0
investment = cashflows[0]
for i in range(1, iterations+1):
rate *= (1 - npv(rate, cashflows) / investment)
return rate

此代码返回正确的值(至少对于我根据 Excel 检查的几个示例而言),但我想知道为什么

  • 它似乎不是牛顿法(无导数)或正割法(仅跟踪一次迭代)的实现。
  • 尤其是,将投资变量定义为第一个现金流量元素(及其后续使用)让我感到困惑。

有什么想法吗?

最佳答案

该方法称为定点迭代;例如,参见维基百科文章 http://en.wikipedia.org/wiki/Fixed_point_iteration .

想法是,如果 rate 包含正确的值(即 IRR),则 NPV 为零,因此语句

rate *= (1 - npv(rate, cashflows) / investment)

不会改变费率。因此,一旦找到 IRR,迭代就不会改变它。不动点迭代有时会收敛到正确的值,有时不会。 @Gareth 和@unutbu 的例子表明它并不总是收敛。

收敛的标准如下。将循环中的更新语句写成

rate = rate * (1 - npv(rate, cashflows) / investment)

现在,如果右侧关于 rate 的导数介于 1 和 -1 之间,则该方法收敛。我无法立即看出在什么情况下会出现这种情况。

你可能想知道为什么迭代不做

rate *= (1 - npv(rate, cashflows))

没有奇怪的 investment 变量。确实,我也有同样的疑问;如果满足导数条件,这也将是一个收敛于 IRR 的不动点方法。我的猜测是,在某些情况下,您提供的方法满足派生条件,而不是没有投资的方法。

关于python - 这个 IRR 的实现中使用的数值方法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6892900/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com