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

时间:2011-07-31 23:00:35

标签: python algorithm numerical-methods

ActiveState Recipes网站在Python中有一个实现Internal Rate of Return的功能:

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检查的几个示例),但我想知道为什么

  • 它似乎不是牛顿方法(无衍生物)或正​​割方法(仅跟踪一次迭代)的实现。
  • 特别是,将投资变量定义为第一个现金流元素(以及随后的使用)会使我感到困惑。

有什么想法吗?

3 个答案:

答案 0 :(得分:4)

该方法称为定点迭代;例如,参见维基百科文章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))

没有奇怪的investment变量。的确,我也想知道同样的事情。如果满足导数条件,这也是一个收敛于IRR的定点方法。我的猜测是,在某些情况下,对于您给出的方法,导数条件是满足的,而不是没有investment的方法。

答案 1 :(得分:3)

这对我来说似乎是假的。收敛对于实际使用来说太慢了。

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

答案 2 :(得分:2)

对我来说似乎也是假的。

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