常用現(xiàn)金流的計(jì)算
1.固定現(xiàn)金流現(xiàn)值計(jì)算函數(shù)表達(dá)式:
PresentVal=pv(Rate,NumPeriods,Payment,ExtraPayment,Due) Rate:貼現(xiàn)率 NumPeriods:貼現(xiàn)周期 Payment 周期現(xiàn)金流 ExtraPayment:最后一次非周期現(xiàn)金流,函數(shù)默認(rèn)為 0Due:現(xiàn)金流計(jì)息方式(0為周期末付息,1為周期初付息)PresentVal:現(xiàn)金流現(xiàn)值代碼如下:
1.固定現(xiàn)金流現(xiàn)值計(jì)算函數(shù)表達(dá)式:
PresentVal=pv(Rate,NumPeriods,Payment,ExtraPayment,Due) Rate:貼現(xiàn)率 NumPeriods:貼現(xiàn)周期 Payment 周期現(xiàn)金流 ExtraPayment:最后一次非周期現(xiàn)金流,函數(shù)默認(rèn)為 0Due:現(xiàn)金流計(jì)息方式(0為周期末付息,1為周期初付息)PresentVal:現(xiàn)金流現(xiàn)值代碼如下:
import numpy as np
Facevalue=1000
# 債券付息(面值*利率),假設(shè)每年付息一次
Payment=0.05*Facevalue
# 市場(chǎng)利率
Rate=0.06
# 到期還本,ExtraPayment額外現(xiàn)金流為本金
ExtraPayment=Facevalue
# 債券期現(xiàn)為10年
NumPeriods=10
# 每年年末付息
Due=0
PresentVal=abs(np.pv(Rate,NumPeriods,Payment,ExtraPayment,Due))
print(PresentVal) #該債券價(jià)格低于926.4,則被低估,高于926.4,則被高估
結(jié)果為:926.3991294858529
2.固定現(xiàn)金流終值計(jì)算函數(shù)
FutureVal=fv(Rate,NumPeriods,Payment,PresentVal,Due)Rate:貼現(xiàn)率
NumPeriods:貼現(xiàn)周期
Payment 周期現(xiàn)金流
Due:現(xiàn)金流計(jì)息方式(0為周期末付息,1為周期初付息)
PresentVal:現(xiàn)金流現(xiàn)值 # FutureVal:現(xiàn)金流終值
代碼如下:
import numpy as np
Facevalue=1000
# 債券付息(面值*利率),假設(shè)每年付息一次
Payment=0.05*Facevalue
# 市場(chǎng)利率
Rate=0.06
# 到期還本,ExtraPayment額外現(xiàn)金流為本金
ExtraPayment=Facevalue
# 債券期現(xiàn)為10年
NumPeriods=10
# 每年年末付息
Due=0
FutureVal=abs(np.fv(Rate,NumPeriods,Payment,PresentVal,Due))
print(FutureVal)
結(jié)果如下:2318.079494238091
3.變化現(xiàn)金流計(jì)算
凈現(xiàn)值法(NPV)將現(xiàn)金流用必要收益率貼現(xiàn)計(jì)算 NPV 值,若 NPV>0,則可行,否則不可行內(nèi)部收益率法假設(shè) NPV=0,計(jì)算必要貼現(xiàn)率,若 IRR 大于必要收益率則可行,反之不可行凈現(xiàn)值 NPV 計(jì)算函數(shù) PresentVal=npv(Rate,CashFlow)Rate:必要收益率CashFlow:現(xiàn)金流序列向量 PresentVal:現(xiàn)金流現(xiàn)值代碼如下:
import numpy as np
# 現(xiàn)金流
CashFlow=[-8000,2500.1500,3000,1000,2000]
# 利率
Rate=0.08
PresentVal1=-8000+2500/1.08+1500/1.08**2+3000/1.08**3+1000/1.08**4+2000/1.08**5
PresentVal1=np.npv(Rate,CashFlow)
print(PresentVal1)
結(jié)果如下:-849.137888777871
4. 內(nèi)部收益率計(jì)算函數(shù)
Return=irr(CashFlow)Return :內(nèi)部收益率代碼如下:
import numpy as np
CashFlow=[-8000,2500,1500,3000,1000,2000]
Return=np.round(np.irr(CashFlow),4) #round() 方法返回浮點(diǎn)數(shù)x的四舍五入值。如round(80.23456, 2) : 80.23
print(Return)
結(jié)果如下:0.0839
5. 年現(xiàn)金流計(jì)算
若投資100萬(wàn)買房,還款期20年,每月還6000元,則貸款利率為多少?若改為每月還8000,貸款利率不變,則還款期限為多長(zhǎng)?年金利率函數(shù) rate Rate=rate(NumPeriods,Payment,PresentValue,FutureValue,Due) NumPeriods:現(xiàn)金流周期 Payment:現(xiàn)金流支出 FutureValue:現(xiàn)金流終值,函數(shù)默認(rèn)為 0Due:現(xiàn)金流計(jì)息方式(0為周期末付息,1為周期初付息) PresentVal:現(xiàn)金流現(xiàn)值 Rate:利息率(貼現(xiàn)率)
代碼如下:
import numpy as np
# 貸款現(xiàn)值
PresentValue=1000000.0
# 每次還款金額
Payment=-6000.0
# 還款次數(shù)
NumPeriods=20*12
# 現(xiàn)金流終值為0
FutureValue=0
# 每周期還款一次,0為周期末付息
Due=0
# 調(diào)用rate函數(shù)
Rate=np.around(np.rate(NumPeriods,Payment,PresentValue,FutureValue),4)
print(Rate)
結(jié)果為:0.0032
繼續(xù)求解,
年金周期函數(shù) nper NumPeriods=nper(Rate,Payment,PresentValue,fv,Due)Rate:貼現(xiàn)率 Payment:現(xiàn)金流收入(支出) PresentValue:現(xiàn)金流現(xiàn)值fv:現(xiàn)金流終值,默認(rèn)值為 0Due:現(xiàn)金流計(jì)息方式 NumPeriods:現(xiàn)金流周期
import numpy as np
# 貸款現(xiàn)值
PresentValue=1000000.0
# 每次還款金額
Payment=-8000.0
# 現(xiàn)金流終值為0
FutureValue=0
# 每周期還款一次,0為周期末付息
Due=0
# 月利率,銀行的現(xiàn)行計(jì)息方式
Rate=0.0389/12
# 調(diào)用nper計(jì)算還款周期
NumPeriods=np.nper(Rate,Payment,PresentValue,fv=0,when='end')
print(NumPeriods/12)
結(jié)果如下:13.377524805437297