生活随笔
收集整理的這篇文章主要介紹了
python分析财务报表
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
前言
其實這也是老師要求我們分析的一個項目,所以記錄下分析的過程。
財務大數據作為大數據方向的一個熱門方向,如果能學好,對于我們的今后工作是會有很大幫助的,同時目前市場人才需求也是很大的。
實驗目的
利用python構建財務報表,并進行一些財務分析。
實驗過程
import os,re,csv,math years=[
2017,
2016,
2015,
2014,
2013]
tot_retain_profits_ratio=[
0,
0,
0,
0,
0]
#----------------------------------------打開文件夾中對應的三張Excel表-----------------------------------
path_root =
'F:\\data\\A股報表大全'
dirs = os.listdir(path_root)
for dir
in dirs:path_stock=os.path.
join(path_root,dir)path_fzb=os.path.
join(path_stock,
'fzb')path_llb=os.path.
join(path_stock,
'llb')path_lrb=os.path.
join(path_stock,
'lrb')ls=dir.split(
'_')file_count =
0for fn
in os.listdir(path_fzb):
#部分公司上市少于5年,目錄下的文件數少于5個,獲得具體數量,為以下循環提供數據file_count = file_count +
1if file_count<len(years):years_cnt = file_count
else:years_cnt=len(years)
for i
in range(years_cnt):
if ls[
0].startswith(
'6'):
#滬市A股代碼以數字6打頭path_fzb_year=os.path.
join(path_fzb,
'sh_fzb_'+ls[
0]+
'_'+str(years[i])+
'.csv')path_llb_year=os.path.
join(path_llb,
'sh_llb_'+ls[
0]+
'_'+str(years[i])+
'.csv')path_lrb_year=os.path.
join(path_lrb,
'sh_lrb_'+ls[
0]+
'_'+str(years[i])+
'.csv')
else:path_fzb_year=os.path.
join(path_fzb,
'sz_fzb_'+ls[
0]+
'_'+str(years[i])+
'.csv')path_llb_year=os.path.
join(path_llb,
'sz_llb_'+ls[
0]+
'_'+str(years[i])+
'.csv')path_lrb_year=os.path.
join(path_lrb,
'sz_lrb_'+ls[
0]+
'_'+str(years[i])+
'.csv') file_llb=csv.reader(open(path_llb_year,
'r'))file_lrb=csv.reader(open(path_lrb_year,
'r'))
#----------------------------------------取出想分析的數據列進行分析---------------------------------------------------- for j,row
in enumerate(file_lrb):
if j==
4:tot_revenue=
float(row[
8])
#總營業收入tot_retain_profits=
float(row[
33])
#歸屬母公司凈利潤if tot_revenue>
0:tot_retain_profits_ratio[i]=tot_retain_profits/tot_revenue
#凈利潤率#print(tot_revenue,tot_retain_profits)elif j==
3 and years[i]==
2017:tot_revenue=
float(row[
8])tot_retain_profits=
float(row[
33])
if tot_revenue>
0:tot_retain_profits_ratio[i]=tot_retain_profits/tot_revenue
#print(tot_revenue,tot_retain_profits)else:pass
#and math.median(tot_retain_profits_ratio)> 0.15if math.fsum(tot_retain_profits_ratio)/
5 >
0.15 :print(dir,tot_retain_profits_ratio)
這樣就可以獲取不同公司A股報表數據了,并進行一些財務分析。
最后我構建了3000多家公司的財務分析表,類似財報說(這是一個財務分析有名的網站)網站效果:
這里的0是由于一些報表信息的確實無法計算,所以統一用0代替。計算公式參考財報說的FAQ公式
具體代碼被我放到github上:https://github.com/1qweasdzxc/python
- 財務數據分析
這一塊可以進一步分析是否為重資產企業、財務杠桿高低、毛利率高低、周轉率(翻桌率)等。
財務知識記錄
這些知識都源自于《不懂財報也能輕松選出賺錢績效股-李明樟》,有興趣可以看看。
- 三張財務報表必須一起看(資產負債表、損益表、現金流量表),而且最好看最近五年變化情況。
- 資產=負債+股東權益
- 財務杠桿越高代表公司狀況好,肥水不流外人田。
- 毛利率:這是不是一門好生意。
- 營業利潤率:這家公司是不是失去賺錢能力。
- 現金流量:長久發展的基礎,越多越好。
- 經營能力:翻桌率,越高越好。
- 獲利能力:這是不是一門好生意?
- 負債能力:你欠我的能還嗎?
- 假交易會增加營收,但無法變成現金。
- 存貨周轉完整周期=存貨在庫天數(平均銷貨日數)+平均收現日數
總結
以上是生活随笔為你收集整理的python分析财务报表的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。