In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
Today, I would like to share with you what are the relevant knowledge points of python cash flow calculation method, the content is detailed, the logic is clear, I believe most people still know too much about this knowledge, so share this article for your reference, I hope you can get something after reading this article, let's take a look at it.
Calculation of common cash flow
1. Function expression for calculating the present value of fixed cash flow: PresentVal=pv (Rate,NumPeriods,Payment,ExtraPayment,Due) Rate: discount rate NumPeriods: discount cycle Payment periodic cash flow ExtraPayment: last aperiodic cash flow, function default is 0Due: cash flow interest bearing method (0 is the end of the cycle interest, 1 is the beginning of the cycle) PresentVal: cash flow present value code is as follows: interest paid on import numpy as npFacevalue=1000# bonds (face value * interest rate) Assuming that the Payment=0.05*Facevalue# market interest rate Rate=0.06# matures once a year, the ExtraPayment extra cash flow is the principal ExtraPayment=Facevalue# bond period is now 10 years NumPeriods=10# annual end-of-year interest payment Due=0PresentVal=abs (np.pv (Rate,NumPeriods,Payment,ExtraPayment,Due)) print (PresentVal) # if the price of the bond is less than 926.4, it is undervalued and higher than 926.4, it is overvalued
The result is: 926.3991294858529
two。 Fixed cash flow terminal value calculation function
FutureVal=fv (Rate,NumPeriods,Payment,PresentVal,Due)
Rate: discount rate
NumPeriods: discount cycle
Payment periodic cash flow
Due: interest bearing method of cash flow (0 is the end of the cycle, 1 is the beginning of the cycle)
PresentVal: present value of cash flow # FutureVal: final value of cash flow
The code is as follows:
Import numpy as npFacevalue=1000# bonds pay interest (par value * interest rate), assuming annual interest payment Payment=0.05*Facevalue# market interest rate Rate=0.06# maturing principal repayment, ExtraPayment extra cash flow is principal ExtraPayment=Facevalue# bond maturity is now 10 years NumPeriods=10# annual end-of-year interest payment Due=0FutureVal=abs (np.fv (Rate,NumPeriods,Payment,PresentVal,Due)) print (FutureVal)
The results are as follows: 2318.079494238091
3. Variable cash flow calculation
Net present value (NPV) discounts the cash flow to the necessary rate of return to calculate the NPV value. If NPV > 0, it is feasible. Otherwise, the internal rate of return method assumes NPV=0 and calculates the necessary discount rate. If IRR is greater than the necessary rate of return, it is feasible. Otherwise, it is not feasible to calculate the NPV function PresentVal=npv (Rate,CashFlow) Rate: necessary rate of return CashFlow: cash flow sequence vector PresentVal: cash flow present value code is as follows:
Import numpy as np# Cash flow CashFlow= [- 8000 Rate,CashFlow print [- 8000 Rate,CashFlow 2000] # interest rate print (PresentVal1)
The results are as follows:-849.137888777871
4. Internal rate of return calculation function
Return=irr (CashFlow) Return: the internal rate of return code is as follows:
The import numpy as npCashFlow= method Return=np.round (np.irr (CashFlow), 4) # round () returns the rounded value of the floating point number x. For example, round (80.23456, 2): 80.23print (Return)
The results are as follows: 0.0839
5. Annual cash flow calculation
If you invest 1 million to buy a house with a repayment period of 20 years and 6000 yuan a month, what is the loan interest rate? If the monthly repayment is changed to 8000 and the loan interest rate remains unchanged, how long will the repayment period be? Annuity interest rate function rate Rate=rate (NumPeriods,Payment,PresentValue,FutureValue,Due) NumPeriods: cash flow cycle Payment: cash flow expenditure FutureValue: cash flow final value, function default is 0Due: cash flow interest bearing method (0 is the end of the cycle, 1 is the beginning of the cycle) PresentVal: cash flow present value Rate: interest rate (discount rate)
The code is as follows:
Import numpy as np# loan present value PresentValue=1000000.0# each repayment amount Payment=-6000.0# repayment number NumPeriods=20*12# cash flow final value is 0FutureValue=0# repayment once per cycle, 0 is the end of the cycle interest payment Due=0# calls the rate function Rate=np.around (np.rate (NumPeriods,Payment,PresentValue,FutureValue), 4) print (Rate)
The result is: 0.0032
Continue to solve
Annuity cycle function nper NumPeriods=nper (Rate,Payment,PresentValue,fv,Due) Rate: discount rate Payment: cash flow income (expenditure) PresentValue: cash flow present value fv: cash flow final value, default value is 0Due: cash flow interest bearing method NumPeriods: cash flow cycle
Import numpy as np# loan present value PresentValue=1000000.0# each repayment amount Payment=-8000.0# cash flow final value is 0FutureValue=0# repayment once per cycle, 0 is the Due=0# monthly interest rate at the end of the cycle, the bank's current interest calculation method Rate=0.0389/12# calls nper to calculate the repayment cycle NumPeriods=np.nper (Rate,Payment,PresentValue,fv=0,when='end') print (NumPeriods/12)
The results are as follows: 13.377524805437297
These are all the contents of this article entitled "what are the methods of calculating python cash flow?" Thank you for reading! I believe you will gain a lot after reading this article. The editor will update different knowledge for you every day. If you want to learn more knowledge, please pay attention to the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.