金融原理/第 1 節/第 6 章/公司/計算
外觀
< 金融原理
專案估值可能需要找到內部收益率 (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] )