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

标签 python algorithm numerical-methods

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/

相关文章:

python - pandas dataframe View 与复制,我如何区分?

找到最佳数量的拉米风格集的算法?

algorithm - 概念上简单的线性时间后缀树结构

python - numpy.sum 的实现方式是否避免了数值错误?

algorithm - 如何找到 3D 曲线和 3D 曲面的交点?

math - 相机远离环面时射线与环面方程相交的数值错误

python - 如何使用 Python 从 azure blob 读取 docx 文件

python - 如何在django模型中获取当前用户?

algorithm - Dinic 算法实现和一个 spoj 难题

python - 具有最小分数的作业