【发布时间】:2011-07-31 23:00:34
【问题描述】:
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 的几个示例),但我想知道为什么。
- 它似乎不是牛顿法(无导数)或正割法(仅跟踪一次迭代)的实现。
- 特别是,将投资变量定义为第一个现金流量元素(以及它的后续使用)让我感到困惑。
有什么想法吗?
【问题讨论】:
标签: python algorithm numerical-methods