Principles of Finance/Section 1/Chapter 6/Corp/Computation

IRR , computation , Newton's Method

edit

Project valuation may require finding the Internal Rate of Return, or the discount rate at which a project's present value of future cash flows equals to zero. This is the maximum rate of return achievable, and should be greater than the inflation rate. a simple converging guessing method has been illustrated under the Project Valuation chapter. The use of Newton's method was left as an exercise, and a possible solution is shown below. Newton's method finds the x-axis intersection of the gradient line found at an approximate IRR, which will give a better rate to try for IRR, and iterations will find an acceptable IRR where the NPV is small enough to be equal to zero.

background for derivative function of 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] )