跳转到内容

金融原理/第 1 节/第 6 章/公司/计算

来自维基教科书,开放的书籍,面向开放的世界

IRR、计算、牛顿法

[编辑 | 编辑源代码]

项目估值可能需要找到内部收益率 (IRR),即项目未来现金流的现值等于零时的折现率。这是可实现的最大回报率,应该高于通货膨胀率。在项目估值章节中已经说明了一个简单的收敛猜测方法。牛顿法的使用留作练习,下面给出了可能的解决方案。牛顿法找到在近似 IRR 处找到的梯度线的 x 轴交点,这将给出更好的 IRR 尝试率,迭代将找到 NPV 足够小以等于零的可接受 IRR。

npv 导数函数的背景

  Axiom: for bxa , 
  
    d  ( bxa)  / dx  =  ab xa-1
  Hence, if,
  
    npv = CF0 / R0 + CF1 / R1 + .. + CFn / Rn,
  
    or npv = CF0 + CF1 x R-1 + CF2 x R-2 + .. + CFn x R-n,
  
  then , 
 
    d(npv)/dR = 0 x CF0 x R -1  + - CF1x R -2 + - 2 CF2x R -3 ... + -n x CFn x R-n - 1.
  
#copyright SJT, GNU  2014.

# Newton's method
# graph is y-axis NPV and x-axis is rate, so find where NPV = 0, or the project rate function crosses the x-axis.
# Do this by finding where the slope line of the function curve at any given R crosses the x-axis, which gives a 
# better R'  which is closer to where the function curve crosses the x-axis, and this is done iteratively until
# a close enough R' is found where the npv is practically 0.


def irr(cfs):

   def npv(cfs, r):
     R = 1. + r/100.
     return reduce( lambda x,(i,y): x + y * R**-i , enumerate(cfs), 0)

   

   def deriv_npv( cfs, r):
     R = 1. + r/ 100.
     return reduce ( lambda x, (i,y): x - i * y * R **(-i-1) , enumerate( cfs), 0)

   r = 10.
   lim = 0.1 # ten cents is practically zero

   while True:
      np_v = npv( cfs, r)
      print "np_v", np_v
      if abs(np_v ) < lim:
         break
      dnpv = deriv_npv( cfs, r)
      r =  r -  np_v / dnpv  
   return r


print irr( [ -30000, 3000, 4000, 16000, 15000, 5000] )
华夏公益教科书