Foreword: Quantitative analysis of financial stocks must know more formula calculations, and hereby post a record of the formula knowledge learned.
1. Calculate the present value formula of future cash:
PV represents the performance value, FV represents the cash value obtained in the future, R refers to the discount rate, n refers to the cycle
def pv_f(fv,r,n):
return fv/(1+r)**n
print(pv_f(100,0.1,1))
2. Formula for calculating the present value of perpetual annuities
PV refers to the present value of perpetual annuities, C refers to the equivalent cash paid at the end of each period, and R refers to the discount rate.
def pv_perpetuity(c,r):
return c/r
print(pv_perpetuity(20,0.1)) #未来每年的年末收到20美元,年化折现率10%,那永续年金现值为200美元
3. The formula for calculating the present value of the growth perpetual annuity
g refers to a constant growth rate per period
def pv_growing_perpetuity(c,r,g):
if(r<g):
print('折现率r不能小于增长率g')
else:
return (c/(r-g))
print(pv_growing_perpetuity(20, 0.1, 0.08))
#4. Interest rate conversion
EAR effective annual rate (effective annual rate), APR given annual interest rate (annual percentage rate), m annual compound interest frequency
def EAR_rate(APR_rate, m):
return ((1+APR_rate/m)**m-1)
print(EAR_rate(0.005,2)) #银行提供按半年复利年利率为5%的贷款转换成有效年利率
print(EAR_rate(0.051,4)) #银行提供按季复利年利率为5.1%的贷款转换成有效年利率