IRR 的实施中使用的数值方法是什么?

发布于 2024-11-27 11:28:35 字数 920 浏览 1 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

大海や 2024-12-04 11:28:35

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

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

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

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

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

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

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

您可能想知道为什么迭代不能

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

没有奇怪的投资变量。确实,我也有同样的疑问;如果满足导数条件,这也是一种收敛到 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 statement

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

will 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

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

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

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

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 without investment.

删除会话 2024-12-04 11:28:35

对我来说这似乎是假的。收敛速度太慢,不适合实际使用。

>>> irr([-100, 100]) # expecting answer 0
0.00990099009900991

It seems bogus to me. The convergence is too slow for practical use.

>>> irr([-100, 100]) # expecting answer 0
0.00990099009900991
兰花执着 2024-12-04 11:28:35

对我来说这似乎也是假的。

>>> irr([-100,50],100000)  # expecting answer -0.5
0.0

It seems bogus to me, too.

>>> irr([-100,50],100000)  # expecting answer -0.5
0.0
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文