加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Python > 正文

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

发布时间:2020-12-16 23:22:30 所属栏目:Python 来源:网络整理
导读: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 capit
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])
       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的例子表明,它并不总是收敛.

收敛标准如下.将循环中的update语句写为

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

现在,如果右侧的导数相对于速率在1和-1之间,则该方法收敛.我不能立即看到在什么情况下是这样的.

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

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

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读