numpy financial function

Calculated final value

Import numpy AS NP
 Import matplotlib.pyplot AS plt 

# interest rate of 3%, the amount of each quarterly payment of 10, 5-year deposit period, 1000 to the present value of the parameter to calculate the final value 
Print (np.fv (0.03 / 4, 5 * 4, -10 -1000 ))
 # 1376.09633204 
# equivalent interest rate of 3% per quarter and 5-year deposit additional funds with 10 units
fvals = [] for i in the Range (1, 10 ): fvals.append (NP. Fv (. 03/4, I *. 4, -10, -1000 )) plt.plot (fvals, ' BO ' ) plt.show ()

inverse operation value # final
print (np.pv (0.03 / 4, 5 * 4, -10, 1376.09633204
# -999.999999999

 

Calculate the net present value

Import numpy NP AS 

# to generate five random numbers as values of cash flows, the input parameter is the final value, the output current value 
cashflows = np.random.randint (100, size =. 5 ) 
cashflows = np.insert (cashflows, 0, -100 )
 Print (cashflows)
 # [2 -100 11 92 93 36] 
# 11 into two 100 taken a three extraction removed 92 2 93 remove four five five 36 removed now need to take complete Q how much input Print (np.npv (0.03 , cashflows))
 # 112.911930303

 

Calculate the internal rate of return

Import numpy AS NP
 
# 100 put out a 38 Remove the two 48 three 90 four out five taken out 17 36
# to ask how much interest rates in order to support this out
Print (np.irr ([- 100, 38, 48, 90, 17, 36 ])) # 0.3734202268880209

 

Calculate installment

Import numpy AS NP 

# assume loans 1,000,000 annual interest rate of 10%, 30 years is also finished, and asked how much to pay each month 
Print (np.pmt (0.10 / 12, 12 * 30, 1 million ))
 # -8775.71570089

 

Calculation of installments

Import numpy AS NP 

# loans 900, annual interest rate of 10%, the monthly repayment 100 
# asked to repay a few months 
Print (np.nper (0.10 / 12, -100, 9000 ))
 # 167.047511801

 

Calculate interest rates

Import numpy AS NP 

# pay a total of 167, 100 each issue payment, credit 9000, the final value of 0 
# Q lending rates 
Print (12 * np.rate (167, -100, 9000 , 0))
 # .0999756420664

 

Guess you like

Origin www.cnblogs.com/draven123/p/11427097.html