生活随笔
收集整理的這篇文章主要介紹了
python分析财务报表
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
前言
其實(shí)這也是老師要求我們分析的一個(gè)項(xiàng)目,所以記錄下分析的過程。
財(cái)務(wù)大數(shù)據(jù)作為大數(shù)據(jù)方向的一個(gè)熱門方向,如果能學(xué)好,對于我們的今后工作是會(huì)有很大幫助的,同時(shí)目前市場人才需求也是很大的。
實(shí)驗(yàn)過程
import os,re,csv,math years=[
2017,
2016,
2015,
2014,
2013]
tot_retain_profits_ratio=[
0,
0,
0,
0,
0]
#----------------------------------------打開文件夾中對應(yīng)的三張Excel表-----------------------------------
path_root =
'F:\\data\\A股報(bào)表大全'
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年,目錄下的文件數(shù)少于5個(gè),獲得具體數(shù)量,為以下循環(huán)提供數(shù)據(jù)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股代碼以數(shù)字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'))
#----------------------------------------取出想分析的數(shù)據(jù)列進(jìn)行分析---------------------------------------------------- for j,row
in enumerate(file_lrb):
if j==
4:tot_revenue=
float(row[
8])
#總營業(yè)收入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股報(bào)表數(shù)據(jù)了,并進(jìn)行一些財(cái)務(wù)分析。
最后我構(gòu)建了3000多家公司的財(cái)務(wù)分析表,類似財(cái)報(bào)說(這是一個(gè)財(cái)務(wù)分析有名的網(wǎng)站)網(wǎng)站效果:
這里的0是由于一些報(bào)表信息的確實(shí)無法計(jì)算,所以統(tǒng)一用0代替。計(jì)算公式參考財(cái)報(bào)說的FAQ公式
具體代碼被我放到github上:https://github.com/1qweasdzxc/python
- 財(cái)務(wù)數(shù)據(jù)分析
這一塊可以進(jìn)一步分析是否為重資產(chǎn)企業(yè)、財(cái)務(wù)杠桿高低、毛利率高低、周轉(zhuǎn)率(翻桌率)等。
財(cái)務(wù)知識記錄
這些知識都源自于《不懂財(cái)報(bào)也能輕松選出賺錢績效股-李明樟》,有興趣可以看看。
- 三張財(cái)務(wù)報(bào)表必須一起看(資產(chǎn)負(fù)債表、損益表、現(xiàn)金流量表),而且最好看最近五年變化情況。
- 資產(chǎn)=負(fù)債+股東權(quán)益
- 財(cái)務(wù)杠桿越高代表公司狀況好,肥水不流外人田。
- 毛利率:這是不是一門好生意。
- 營業(yè)利潤率:這家公司是不是失去賺錢能力。
- 現(xiàn)金流量:長久發(fā)展的基礎(chǔ),越多越好。
- 經(jīng)營能力:翻桌率,越高越好。
- 獲利能力:這是不是一門好生意?
- 負(fù)債能力:你欠我的能還嗎?
- 假交易會(huì)增加營收,但無法變成現(xiàn)金。
- 存貨周轉(zhuǎn)完整周期=存貨在庫天數(shù)(平均銷貨日數(shù))+平均收現(xiàn)日數(shù)
總結(jié)
以上是生活随笔為你收集整理的python分析财务报表的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。