IRR 的实施中使用的数值方法是什么?
ActiveState Recipes 网站有一个在 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 检查的几个示例),但我想知道为什么。
- 它似乎不是牛顿法(无导数)或割线法(仅跟踪一次迭代)的实现。
- 特别是,投资变量作为第一个现金流要素(及其后续使用)的定义让我感到困惑。
有什么想法吗?
The ActiveState Recipes site has a function implementing Internal Rate of Return in 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
This code returns correct values (at least for the couple of examples that I have checked against Excel), but I would like to know why.
- It doesn't appear to be an implementation of Newton's Method (no derivative) or the Secant Method (only keeps track of one iteration).
- In particular, the definition of the investment variable as the first cashflow element (and it's subsequent use) confuses me.
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
该方法称为定点迭代;例如,参见 Wikipedia 文章 http://en.wikipedia.org/wiki/Fixed_point_iteration。
这个想法是,如果
rate
包含正确的值(即 IRR),则 NPV 为零,因此该语句不会更改
rate
。因此,一旦找到 IRR,迭代就不会改变它。定点迭代有时会收敛到正确的值,有时则不会。 @Gareth 和 @unutbu 的例子表明,这里它并不总是收敛。收敛的标准如下。将循环中的更新语句写为
现在,如果右侧相对于
rate
的导数在 1 和 -1 之间,则该方法收敛。我无法立即看出这是在什么情况下发生的。您可能想知道为什么迭代不能
没有奇怪的投资变量。确实,我也有同样的疑问;如果满足导数条件,这也是一种收敛到 IRR 的定点方法。我的猜测是,在某些情况下,您给出的方法会满足导数条件,而不是没有
投资
的方法。The method is called fixed point iteration; see for instance the Wikipedia article http://en.wikipedia.org/wiki/Fixed_point_iteration.
The idea is that if
rate
contains the correct value (that is, the IRR), then the NPV is zero, so the statementwill not change
rate
. Thus, once you find the IRR, the iteration will not change it. Fixed point iteration sometimes converges to the correct value and sometimes it does not. The examples of @Gareth and @unutbu show that here it does not always converge.The criterion for convergence is as follows. Write the update statement in the loop as
Now, if the derivative of the right-hand side with respect to
rate
is between 1 and -1, then the method converges. I cannot immediately see under what circumstances this is the case.You may wonder why the iteration does not do
without the weird
investment
variable. Indeed, I wondered the same; that would also be a fixed point method that converges to the IRR if the derivative condition is satisfied. My guess is that the derivative condition is satisfied in some circumstances for the method that you gave, and not for the method withoutinvestment
.对我来说这似乎是假的。收敛速度太慢,不适合实际使用。
It seems bogus to me. The convergence is too slow for practical use.
对我来说这似乎也是假的。
It seems bogus to me, too.