siat 3.0.10__py3-none-any.whl → 3.0.20__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- siat/capm_beta2.py +51 -22
- siat/common.py +136 -9
- siat/financials_china.py +83 -47
- siat/financials_china2.py +272 -119
- siat/grafix.py +130 -62
- siat/markowitz2.py +27 -3
- siat/risk_adjusted_return2.py +136 -62
- siat/security_trend2.py +39 -25
- siat/stock.py +127 -47
- siat/stock_china.py +160 -53
- siat/stock_technical.py +1 -1
- siat/valuation.py +34 -7
- {siat-3.0.10.dist-info → siat-3.0.20.dist-info}/METADATA +1 -1
- {siat-3.0.10.dist-info → siat-3.0.20.dist-info}/RECORD +16 -16
- {siat-3.0.10.dist-info → siat-3.0.20.dist-info}/WHEEL +0 -0
- {siat-3.0.10.dist-info → siat-3.0.20.dist-info}/top_level.txt +0 -0
siat/financials_china2.py
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
本模块功能:计算财务报表指标,基于东方财富,仅限于中国大陆上市的企业
|
5
5
|
所属工具包:证券投资分析工具SIAT
|
6
6
|
SIAT:Security Investment Analysis Tool
|
7
|
-
创建日期:
|
7
|
+
创建日期:2024年4月21日
|
8
8
|
最新修订日期:2022年5月18日
|
9
9
|
作者:王德宏 (WANG Dehong, Peter)
|
10
10
|
作者单位:北京外国语大学国际商学院
|
@@ -21,6 +21,7 @@ import akshare as ak
|
|
21
21
|
# 这条语句似乎有时失灵!?
|
22
22
|
from siat.stock_china import *
|
23
23
|
from siat.financials_china import *
|
24
|
+
from siat.translate import *
|
24
25
|
#==============================================================================
|
25
26
|
#==============================================================================
|
26
27
|
if __name__=='__main__':
|
@@ -212,7 +213,7 @@ def get_fin_stmt_ak_multi(tickers,fsdates):
|
|
212
213
|
df.rename(columns={'endDate_期初':'endDate_上期'},inplace=True)
|
213
214
|
|
214
215
|
#标注股票简称,去掉其中的(A股)字样
|
215
|
-
df["股票简称"]=df['ticker'].apply(lambda x: ticker_name(x).replace("(A股)",''))
|
216
|
+
df["股票简称"]=df['ticker'].apply(lambda x: ticker_name(x,'stock').replace("(A股)",''))
|
216
217
|
|
217
218
|
"""
|
218
219
|
# 替换nan为-
|
@@ -382,7 +383,9 @@ if __name__=='__main__':
|
|
382
383
|
foot_center=False
|
383
384
|
foot_start=4
|
384
385
|
|
385
|
-
def
|
386
|
+
def df_directprint_original(dfp,title_txt,footnote, \
|
387
|
+
title_break=True,foot_break=True,foot_center=False,foot_start=1, \
|
388
|
+
facecolor='papayawhip'):
|
386
389
|
"""
|
387
390
|
功能:对dfp直接打印,让标题居中,让脚注居中或指定开始位置。
|
388
391
|
"""
|
@@ -417,7 +420,7 @@ def df_directprint(dfp,title_txt,footnote,title_break=True,foot_break=True,foot_
|
|
417
420
|
colalign=['left']+['right']*(len(list(dfp)) - 1)
|
418
421
|
print(dfp.to_markdown(tablefmt='Simple',index=False,colalign=colalign))
|
419
422
|
|
420
|
-
|
423
|
+
#解析脚注各行并打印
|
421
424
|
if foot_break: print('')
|
422
425
|
footnote1=footnote+'\n'
|
423
426
|
pos,pos_new=0,0
|
@@ -440,8 +443,98 @@ def df_directprint(dfp,title_txt,footnote,title_break=True,foot_break=True,foot_
|
|
440
443
|
|
441
444
|
return
|
442
445
|
|
443
|
-
|
444
|
-
|
446
|
+
#==============================================================================
|
447
|
+
"""
|
448
|
+
def df_directprint(dfp,title_txt,footnote, \
|
449
|
+
title_break=True,foot_break=True,foot_center=False,foot_start=1, \
|
450
|
+
decimals=2,facecolor='papayawhip'):
|
451
|
+
"""
|
452
|
+
def df_directprint(dfp,title_txt,footnote,decimals=2,facecolor='papayawhip'):
|
453
|
+
"""
|
454
|
+
功能:对dfp直接打印,使用pandas style打印
|
455
|
+
"""
|
456
|
+
#替换nan和inf
|
457
|
+
import pandas as pd
|
458
|
+
import numpy as np
|
459
|
+
dfp.replace([np.inf, -np.inf],'-', inplace=True)
|
460
|
+
dfp.replace([np.nan],'-', inplace=True)
|
461
|
+
|
462
|
+
print('') #空一行
|
463
|
+
|
464
|
+
"""
|
465
|
+
#解析标题各行并居中打印
|
466
|
+
title_txt1=title_txt+'\n'
|
467
|
+
pos,pos_new=0,0
|
468
|
+
while pos_new != -1:
|
469
|
+
pos_new=title_txt1.find('\n',pos)
|
470
|
+
linetxt=title_txt1[pos:pos_new]
|
471
|
+
#print(linetxt)
|
472
|
+
|
473
|
+
blanknum=title_position(linetxt,dfp)
|
474
|
+
|
475
|
+
if linetxt != '\n':
|
476
|
+
print(' '*blanknum,linetxt)
|
477
|
+
|
478
|
+
pos=pos_new+1
|
479
|
+
"""
|
480
|
+
disph=dfp.style.hide() #不显示索引列
|
481
|
+
dispp=disph.format(precision=decimals) #设置带有小数点的列精度调整为小数点后2位
|
482
|
+
|
483
|
+
#设置标题/列名
|
484
|
+
dispt=dispp.set_caption(title_txt).set_table_styles(
|
485
|
+
[{'selector':'caption', #设置标题对齐
|
486
|
+
'props':[('color','black'),('font-size','18px'),('font-weight','bold')]}, \
|
487
|
+
{'selector':'th.col_heading', #设置列名对齐
|
488
|
+
'props':[('color','black'),('background-color',facecolor), \
|
489
|
+
('font-size','17px'),('text-align','center'),('margin','auto')]}])
|
490
|
+
|
491
|
+
#设置数据对齐
|
492
|
+
dispt1=dispt.set_properties(**{'font-size':'17px'})
|
493
|
+
dispf=dispt1.set_properties(**{'text-align':'center'})
|
494
|
+
|
495
|
+
#设置前景背景颜色
|
496
|
+
try:
|
497
|
+
dispf2=dispf.set_properties(**{'background-color':facecolor,'color':'black'})
|
498
|
+
except:
|
499
|
+
print(" #Warning(df_directprint): unknown color",facecolor,"\b, changed to default one")
|
500
|
+
dispf2=dispf.set_properties(**{'background-color':'papayawhip','color':'black'})
|
501
|
+
|
502
|
+
#打印数据框本身
|
503
|
+
from IPython.display import display
|
504
|
+
display(dispf2)
|
505
|
+
|
506
|
+
"""
|
507
|
+
#print(dfp.to_string(index=False))
|
508
|
+
colalign=['left']+['right']*(len(list(dfp)) - 1)
|
509
|
+
print(dfp.to_markdown(tablefmt='Simple',index=False,colalign=colalign))
|
510
|
+
"""
|
511
|
+
|
512
|
+
#解析脚注各行并打印
|
513
|
+
"""
|
514
|
+
if foot_break: print('')
|
515
|
+
footnote1=footnote+'\n'
|
516
|
+
pos,pos_new=0,0
|
517
|
+
while pos_new != -1:
|
518
|
+
pos_new=footnote1.find('\n',pos)
|
519
|
+
linetxt=footnote1[pos:pos_new]
|
520
|
+
#print(linetxt)
|
521
|
+
if foot_center:
|
522
|
+
blanknum=title_position(linetxt,dfp)
|
523
|
+
else:
|
524
|
+
blanknum=foot_start-1
|
525
|
+
|
526
|
+
if linetxt != '\n':
|
527
|
+
if blanknum >2:
|
528
|
+
print(' '*blanknum,linetxt)
|
529
|
+
else:
|
530
|
+
print(linetxt)
|
531
|
+
|
532
|
+
pos=pos_new+1
|
533
|
+
"""
|
534
|
+
#print('') #空一行
|
535
|
+
print(footnote,'\n')
|
536
|
+
|
537
|
+
return
|
445
538
|
#==============================================================================
|
446
539
|
|
447
540
|
if __name__=='__main__':
|
@@ -458,7 +551,7 @@ if __name__=='__main__':
|
|
458
551
|
items=["货币资金","应收票据","应收账款"]
|
459
552
|
dfp=fs_item_analysis_1(df,ticker,fsdate,items)
|
460
553
|
|
461
|
-
def fs_item_analysis_1(df,ticker,fsdate,items,title_txt='',notes=''):
|
554
|
+
def fs_item_analysis_1(df,ticker,fsdate,items,title_txt='',notes='',facecolor='papayawhip'):
|
462
555
|
"""
|
463
556
|
功能:比较给定财报日期的资产项目、期初数、期末数、变动额和变动幅度%
|
464
557
|
"""
|
@@ -504,8 +597,8 @@ def fs_item_analysis_1(df,ticker,fsdate,items,title_txt='',notes=''):
|
|
504
597
|
|
505
598
|
#无序号打印
|
506
599
|
if title_txt=='':
|
507
|
-
|
508
|
-
title_txt=
|
600
|
+
tname=ticker_name(ticker,'stock').replace("(A股)",'')
|
601
|
+
title_txt=tname+"财报分析:重要项目的变动情况\n(截至"+fsdate+")"
|
509
602
|
import datetime; today=datetime.date.today()
|
510
603
|
#footnote="*单位:亿元,数据来源:新浪财经,"+str(today)
|
511
604
|
footnote="*单位:亿元,本期报表日期:"+fsdate+',数据来源:新浪财经'
|
@@ -515,8 +608,11 @@ def fs_item_analysis_1(df,ticker,fsdate,items,title_txt='',notes=''):
|
|
515
608
|
else:
|
516
609
|
foottext=notes+'\n'+footnote
|
517
610
|
|
518
|
-
df_directprint(dfp,title_txt,foottext)
|
519
|
-
|
611
|
+
#df_directprint(dfp,title_txt,foottext,facecolor=facecolor)
|
612
|
+
df_display_CSS(df=dfp,titletxt=title_txt,footnote=foottext, \
|
613
|
+
first_col_align='left', \
|
614
|
+
facecolor=facecolor,decimals=2)
|
615
|
+
|
520
616
|
return dfp
|
521
617
|
|
522
618
|
|
@@ -534,7 +630,7 @@ if __name__=='__main__':
|
|
534
630
|
|
535
631
|
dfp=fs_item_analysis_2(df,ticker,fsdates,items)
|
536
632
|
|
537
|
-
def fs_item_analysis_2(df,ticker,fsdates,items,title_txt='',notes=''):
|
633
|
+
def fs_item_analysis_2(df,ticker,fsdates,items,title_txt='',notes='',facecolor='papayawhip'):
|
538
634
|
"""
|
539
635
|
功能:比较给定财报日期的报表项目、最近几年fsdates、占比%
|
540
636
|
"""
|
@@ -565,8 +661,8 @@ def fs_item_analysis_2(df,ticker,fsdates,items,title_txt='',notes=''):
|
|
565
661
|
|
566
662
|
#无序号打印
|
567
663
|
if title_txt=='':
|
568
|
-
|
569
|
-
title_txt=
|
664
|
+
tname=ticker_name(ticker,'stock').replace("(A股)",'')
|
665
|
+
title_txt=tname+"财报分析:重要项目占比的变动趋势"
|
570
666
|
import datetime; today=datetime.date.today()
|
571
667
|
footnote="*数据来源:新浪财经,"+str(today)
|
572
668
|
|
@@ -575,8 +671,11 @@ def fs_item_analysis_2(df,ticker,fsdates,items,title_txt='',notes=''):
|
|
575
671
|
else:
|
576
672
|
foottext=notes+'\n'+footnote
|
577
673
|
|
578
|
-
df_directprint(dfp,title_txt,foottext)
|
579
|
-
|
674
|
+
#df_directprint(dfp,title_txt,foottext,facecolor=facecolor)
|
675
|
+
df_display_CSS(df=dfp,titletxt=title_txt,footnote=foottext, \
|
676
|
+
first_col_align='left', \
|
677
|
+
facecolor=facecolor,decimals=2)
|
678
|
+
|
580
679
|
return dfp
|
581
680
|
|
582
681
|
#==============================================================================
|
@@ -590,7 +689,7 @@ if __name__=='__main__':
|
|
590
689
|
|
591
690
|
dfp=fs_item_analysis_3(df,ticker,fsdates)
|
592
691
|
|
593
|
-
def fs_item_analysis_3(df,ticker,fsdates,title_txt='',notes=''):
|
692
|
+
def fs_item_analysis_3(df,ticker,fsdates,title_txt='',notes='',facecolor='papayawhip'):
|
594
693
|
"""
|
595
694
|
功能:比较给定财报日期的流动比率、最近几年fsdates
|
596
695
|
"""
|
@@ -620,8 +719,8 @@ def fs_item_analysis_3(df,ticker,fsdates,title_txt='',notes=''):
|
|
620
719
|
|
621
720
|
#无序号打印
|
622
721
|
if title_txt=='':
|
623
|
-
|
624
|
-
title_txt=
|
722
|
+
tname=ticker_name(ticker,'stock').replace("(A股)",'')
|
723
|
+
title_txt=tname+"财报分析:流动比率的变动趋势"
|
625
724
|
import datetime; today=datetime.date.today()
|
626
725
|
footnote="*数据来源:新浪财经,"+str(today)
|
627
726
|
|
@@ -630,7 +729,10 @@ def fs_item_analysis_3(df,ticker,fsdates,title_txt='',notes=''):
|
|
630
729
|
else:
|
631
730
|
foottext=notes+'\n'+footnote
|
632
731
|
|
633
|
-
df_directprint(dfp,title_txt,foottext)
|
732
|
+
#df_directprint(dfp,title_txt,foottext,facecolor=facecolor)
|
733
|
+
df_display_CSS(df=dfp,titletxt=title_txt,footnote=foottext, \
|
734
|
+
first_col_align='left', \
|
735
|
+
facecolor=facecolor,decimals=2)
|
634
736
|
|
635
737
|
return dfp
|
636
738
|
|
@@ -645,7 +747,7 @@ if __name__=='__main__':
|
|
645
747
|
|
646
748
|
dfp=fs_item_analysis_4(df,ticker,fsdates)
|
647
749
|
|
648
|
-
def fs_item_analysis_4(df,ticker,fsdates,title_txt='',notes=''):
|
750
|
+
def fs_item_analysis_4(df,ticker,fsdates,title_txt='',notes='',facecolor='papayawhip'):
|
649
751
|
"""
|
650
752
|
功能:比较给定财报日期的流动比率、最近几年fsdates
|
651
753
|
"""
|
@@ -695,8 +797,8 @@ def fs_item_analysis_4(df,ticker,fsdates,title_txt='',notes=''):
|
|
695
797
|
|
696
798
|
#无序号打印
|
697
799
|
if title_txt=='':
|
698
|
-
|
699
|
-
title_txt=
|
800
|
+
tname=ticker_name(ticker,'stock').replace("(A股)",'')
|
801
|
+
title_txt=tname+"财报分析:速动比率的变动趋势"
|
700
802
|
import datetime; today=datetime.date.today()
|
701
803
|
footnote="*数据来源:新浪财经,"+str(today)
|
702
804
|
|
@@ -705,8 +807,10 @@ def fs_item_analysis_4(df,ticker,fsdates,title_txt='',notes=''):
|
|
705
807
|
else:
|
706
808
|
foottext=notes+'\n'+footnote
|
707
809
|
|
708
|
-
df_directprint(dfp,title_txt,foottext)
|
709
|
-
|
810
|
+
#df_directprint(dfp,title_txt,foottext,facecolor=facecolor)
|
811
|
+
df_display_CSS(df=dfp,titletxt=title_txt,footnote=foottext, \
|
812
|
+
first_col_align='left', \
|
813
|
+
facecolor=facecolor,decimals=2)
|
710
814
|
return dfp
|
711
815
|
|
712
816
|
#==============================================================================
|
@@ -720,7 +824,7 @@ if __name__=='__main__':
|
|
720
824
|
|
721
825
|
dfp=fs_item_analysis_5(df,ticker,fsdates)
|
722
826
|
|
723
|
-
def fs_item_analysis_5(df,ticker,fsdates,title_txt='',notes=''):
|
827
|
+
def fs_item_analysis_5(df,ticker,fsdates,title_txt='',notes='',facecolor='papayawhip'):
|
724
828
|
"""
|
725
829
|
功能:比较给定财报日期的流动比率、最近几年fsdates
|
726
830
|
"""
|
@@ -750,8 +854,8 @@ def fs_item_analysis_5(df,ticker,fsdates,title_txt='',notes=''):
|
|
750
854
|
|
751
855
|
#无序号打印
|
752
856
|
if title_txt=='':
|
753
|
-
|
754
|
-
title_txt=
|
857
|
+
tname=ticker_name(ticker,'stock').replace("(A股)",'')
|
858
|
+
title_txt=tname+"财报分析:资产负债率的变动趋势"
|
755
859
|
import datetime; today=datetime.date.today()
|
756
860
|
footnote="*数据来源:新浪财经,"+str(today)
|
757
861
|
|
@@ -760,8 +864,10 @@ def fs_item_analysis_5(df,ticker,fsdates,title_txt='',notes=''):
|
|
760
864
|
else:
|
761
865
|
foottext=notes+'\n'+footnote
|
762
866
|
|
763
|
-
df_directprint(dfp,title_txt,foottext)
|
764
|
-
|
867
|
+
#df_directprint(dfp,title_txt,foottext,facecolor=facecolor)
|
868
|
+
df_display_CSS(df=dfp,titletxt=title_txt,footnote=foottext, \
|
869
|
+
first_col_align='left', \
|
870
|
+
facecolor=facecolor,decimals=2)
|
765
871
|
return dfp
|
766
872
|
|
767
873
|
#==============================================================================
|
@@ -811,8 +917,8 @@ def fs_item_analysis_6_original(df,ticker,fsdates,items,title_txt='',notes=''):
|
|
811
917
|
|
812
918
|
#无序号打印
|
813
919
|
if title_txt=='':
|
814
|
-
|
815
|
-
title_txt=
|
920
|
+
tname=ticker_name(ticker,'stock').replace("(A股)",'')
|
921
|
+
title_txt=tname+"财报分析:重要关联项目的增幅对比"
|
816
922
|
import datetime; today=datetime.date.today()
|
817
923
|
footnote="*数据来源:新浪财经,"+str(today)
|
818
924
|
|
@@ -836,7 +942,7 @@ if __name__=='__main__':
|
|
836
942
|
|
837
943
|
dfp=fs_item_analysis_6(df,ticker,fsdates,items)
|
838
944
|
|
839
|
-
def fs_item_analysis_6(df,ticker,fsdates,items,title_txt='',notes=''):
|
945
|
+
def fs_item_analysis_6(df,ticker,fsdates,items,title_txt='',notes='',facecolor='papayawhip'):
|
840
946
|
"""
|
841
947
|
功能:比较给定财报日期的应收账款与营业收入增幅、最近几年fsdates
|
842
948
|
"""
|
@@ -870,8 +976,8 @@ def fs_item_analysis_6(df,ticker,fsdates,items,title_txt='',notes=''):
|
|
870
976
|
|
871
977
|
#无序号打印
|
872
978
|
if title_txt=='':
|
873
|
-
|
874
|
-
title_txt=
|
979
|
+
tname=ticker_name(ticker,'stock').replace("(A股)",'')
|
980
|
+
title_txt=tname+"财报分析:重要关联项目的增幅对比"
|
875
981
|
import datetime; today=datetime.date.today()
|
876
982
|
if yiyuan_foot:
|
877
983
|
footnote="*单位:亿元,数据来源:新浪财经,"+str(today)
|
@@ -883,8 +989,10 @@ def fs_item_analysis_6(df,ticker,fsdates,items,title_txt='',notes=''):
|
|
883
989
|
else:
|
884
990
|
foottext=notes+'\n'+footnote
|
885
991
|
|
886
|
-
df_directprint(dfp,title_txt,foottext)
|
887
|
-
|
992
|
+
#df_directprint(dfp,title_txt,foottext,facecolor=facecolor)
|
993
|
+
df_display_CSS(df=dfp,titletxt=title_txt,footnote=foottext, \
|
994
|
+
first_col_align='left', \
|
995
|
+
facecolor=facecolor,decimals=2)
|
888
996
|
return dfp
|
889
997
|
|
890
998
|
#==============================================================================
|
@@ -919,7 +1027,7 @@ def fs_item_analysis_7_original(df,tickers,fsdate,items,title_txt=''):
|
|
919
1027
|
yiyuan_foot=False
|
920
1028
|
|
921
1029
|
for t in tickers:
|
922
|
-
tname=ticker_name(t).replace("(A股)",'')
|
1030
|
+
tname=ticker_name(t,'stock').replace("(A股)",'')
|
923
1031
|
row_list=[tname]
|
924
1032
|
for i in items:
|
925
1033
|
i_value,_,_=select_item(df,t,fsdate,i)
|
@@ -939,8 +1047,8 @@ def fs_item_analysis_7_original(df,tickers,fsdate,items,title_txt=''):
|
|
939
1047
|
if title_txt=='':
|
940
1048
|
title_txt="=== 重要指标的同行业对比 ==="
|
941
1049
|
ticker=tickers[0]
|
942
|
-
|
943
|
-
title_txt=
|
1050
|
+
tname=ticker_name(ticker,'stock').replace("(A股)",'')
|
1051
|
+
title_txt=tname+"财报分析:重要指标的同行业对比\n(截至"+fsdate+")"
|
944
1052
|
import datetime; today=datetime.date.today()
|
945
1053
|
if yiyuan_foot:
|
946
1054
|
footnote="*单位:亿元,数据来源:新浪财经,"+str(today)
|
@@ -961,7 +1069,7 @@ if __name__=='__main__':
|
|
961
1069
|
|
962
1070
|
dfp=fs_item_analysis_7(df,tickers,fsdate,items)
|
963
1071
|
|
964
|
-
def fs_item_analysis_7(df,tickers,fsdate,items,title_txt='',notes=''):
|
1072
|
+
def fs_item_analysis_7(df,tickers,fsdate,items,title_txt='',notes='',facecolor='papayawhip'):
|
965
1073
|
"""
|
966
1074
|
功能:比较给定财报日期fsdate的项目和指标,与同业相比
|
967
1075
|
"""
|
@@ -972,7 +1080,7 @@ def fs_item_analysis_7(df,tickers,fsdate,items,title_txt='',notes=''):
|
|
972
1080
|
yiyuan_foot=False
|
973
1081
|
|
974
1082
|
for t in tickers:
|
975
|
-
tname=ticker_name(t).replace("(A股)",'')
|
1083
|
+
tname=ticker_name(t,'stock').replace("(A股)",'')
|
976
1084
|
row_list=[tname]
|
977
1085
|
for i in items:
|
978
1086
|
i_value,_,_=select_item(df,t,fsdate,i)
|
@@ -1009,8 +1117,8 @@ def fs_item_analysis_7(df,tickers,fsdate,items,title_txt='',notes=''):
|
|
1009
1117
|
if title_txt=='':
|
1010
1118
|
title_txt="=== 重要指标的同行业对比 ==="
|
1011
1119
|
ticker=tickers[0]
|
1012
|
-
|
1013
|
-
title_txt=
|
1120
|
+
tname=ticker_name(ticker,'stock').replace("(A股)",'')
|
1121
|
+
title_txt=tname+"财报分析:重要指标的同行业对比\n(截至"+fsdate+")"
|
1014
1122
|
import datetime; today=datetime.date.today()
|
1015
1123
|
if yiyuan_foot:
|
1016
1124
|
#footnote="*单位:亿元,数据来源:新浪财经,"+str(today)
|
@@ -1024,8 +1132,10 @@ def fs_item_analysis_7(df,tickers,fsdate,items,title_txt='',notes=''):
|
|
1024
1132
|
else:
|
1025
1133
|
foottext=notes+'\n'+footnote
|
1026
1134
|
|
1027
|
-
df_directprint(dfp,title_txt,foottext)
|
1028
|
-
|
1135
|
+
#df_directprint(dfp,title_txt,foottext,facecolor=facecolor)
|
1136
|
+
df_display_CSS(df=dfp,titletxt=title_txt,footnote=foottext, \
|
1137
|
+
first_col_align='left', \
|
1138
|
+
facecolor=facecolor,decimals=2)
|
1029
1139
|
return dfp
|
1030
1140
|
|
1031
1141
|
#==============================================================================
|
@@ -1039,7 +1149,7 @@ if __name__=='__main__':
|
|
1039
1149
|
items=['资产总计','资产负债率%','流动比率%','速动比率%']
|
1040
1150
|
dfp=fs_item_analysis_8(df,tickers,fsdate,items)
|
1041
1151
|
|
1042
|
-
def fs_item_analysis_8(df,tickers,fsdate,items,title_txt='',notes=''):
|
1152
|
+
def fs_item_analysis_8(df,tickers,fsdate,items,title_txt='',notes='',facecolor='papayawhip'):
|
1043
1153
|
"""
|
1044
1154
|
功能:比较给定财报日期fsdate的项目和指标,与同业相比
|
1045
1155
|
区别:项目不带‘(亿元)’字样,避免行过长
|
@@ -1052,7 +1162,7 @@ def fs_item_analysis_8(df,tickers,fsdate,items,title_txt='',notes=''):
|
|
1052
1162
|
yiyuan_foot=False
|
1053
1163
|
|
1054
1164
|
for t in tickers:
|
1055
|
-
tname=ticker_name(t).replace("(A股)",'')
|
1165
|
+
tname=ticker_name(t,'stock').replace("(A股)",'')
|
1056
1166
|
row_list=[tname]
|
1057
1167
|
for i in items:
|
1058
1168
|
i_value,_,_=select_item(df,t,fsdate,i)
|
@@ -1088,8 +1198,8 @@ def fs_item_analysis_8(df,tickers,fsdate,items,title_txt='',notes=''):
|
|
1088
1198
|
#无序号打印
|
1089
1199
|
if title_txt=='':
|
1090
1200
|
ticker=tickers[0]
|
1091
|
-
|
1092
|
-
title_txt=
|
1201
|
+
tname=ticker_name(ticker,'stock').replace("(A股)",'')
|
1202
|
+
title_txt=tname+"财报分析:重要指标的同行业对比\n(截至"+fsdate+")"
|
1093
1203
|
|
1094
1204
|
import datetime; today=datetime.date.today()
|
1095
1205
|
if yiyuan_foot:
|
@@ -1104,8 +1214,10 @@ def fs_item_analysis_8(df,tickers,fsdate,items,title_txt='',notes=''):
|
|
1104
1214
|
else:
|
1105
1215
|
foottext=notes+'\n'+footnote
|
1106
1216
|
|
1107
|
-
df_directprint(dfp,title_txt,foottext)
|
1108
|
-
|
1217
|
+
#df_directprint(dfp,title_txt,foottext,facecolor=facecolor)
|
1218
|
+
df_display_CSS(df=dfp,titletxt=title_txt,footnote=foottext, \
|
1219
|
+
first_col_align='left', \
|
1220
|
+
facecolor=facecolor,decimals=2)
|
1109
1221
|
return dfp
|
1110
1222
|
|
1111
1223
|
#==============================================================================
|
@@ -1114,16 +1226,16 @@ if __name__=='__main__':
|
|
1114
1226
|
fsdates=['2022-12-31','2021-12-31','2020-12-31','2019-12-31']
|
1115
1227
|
asset_liab_structure_china(tickers,fsdates)
|
1116
1228
|
|
1117
|
-
def asset_liab_china(tickers,fsdates):
|
1229
|
+
def asset_liab_china(tickers,fsdates,facecolor='papayawhip'):
|
1118
1230
|
"""
|
1119
1231
|
套壳函数asset_liab_structure_china
|
1120
1232
|
"""
|
1121
|
-
asset_liab_structure_china(tickers,fsdates)
|
1233
|
+
asset_liab_structure_china(tickers,fsdates,facecolor=facecolor)
|
1122
1234
|
|
1123
1235
|
return
|
1124
1236
|
|
1125
1237
|
|
1126
|
-
def asset_liab_structure_china(tickers,fsdates):
|
1238
|
+
def asset_liab_structure_china(tickers,fsdates,facecolor='papayawhip'):
|
1127
1239
|
"""
|
1128
1240
|
功能:分析上市公司的资产负债基本结构,并与同业公司对比。
|
1129
1241
|
注意1:分析近三期情况,fsdates要给出四个报表日期,以便获得期初数。
|
@@ -1156,11 +1268,11 @@ def asset_liab_structure_china(tickers,fsdates):
|
|
1156
1268
|
comparator=tickers[0]
|
1157
1269
|
comparee=tickers[1:]
|
1158
1270
|
print(" Conducting asset-liability analysis ...")
|
1159
|
-
print(" Comparator:",ticker_name(comparator))
|
1271
|
+
print(" Comparator:",ticker_name(comparator,'stock'))
|
1160
1272
|
#print(" Comparee :",ticker_name(comparee))
|
1161
1273
|
print(" Comparee :",end='')
|
1162
1274
|
if comparee != []:
|
1163
|
-
print_list(ticker_name(comparee))
|
1275
|
+
print_list(ticker_name(comparee,'stock'))
|
1164
1276
|
else:
|
1165
1277
|
print(" N/A")
|
1166
1278
|
|
@@ -1196,7 +1308,7 @@ def asset_liab_structure_china(tickers,fsdates):
|
|
1196
1308
|
print(" Solution: check ticker spelling and try at least 10 minutes later")
|
1197
1309
|
return
|
1198
1310
|
|
1199
|
-
title_head=ticker_name(comparator)+"资产负债分析:"
|
1311
|
+
title_head=ticker_name(comparator,'stock')+"资产负债分析:"
|
1200
1312
|
|
1201
1313
|
### 资产负债表的主要项目
|
1202
1314
|
#资产变动趋势2
|
@@ -1208,12 +1320,12 @@ def asset_liab_structure_china(tickers,fsdates):
|
|
1208
1320
|
notes3="注3:长期股权投资是指企业对其子公司、合营企业及联营企业的权益性投资"
|
1209
1321
|
notes4="注4:固定资产净额 = 固定资产原值 - 累计折旧 - 资产减值准备"
|
1210
1322
|
notes=notes1+'\n'+notes2+'\n'+notes3+'\n'+notes4
|
1211
|
-
dfp2=fs_item_analysis_1(df,ticker,fsdate,items2,title_txt,notes)
|
1323
|
+
dfp2=fs_item_analysis_1(df,ticker,fsdate,items2,title_txt,notes,facecolor=facecolor)
|
1212
1324
|
|
1213
1325
|
#负债变动趋势
|
1214
1326
|
title_txt=title_head+"主要负债项目"
|
1215
1327
|
items3=["短期借款","长期借款","应付账款","预收款项","应交税费","应付职工薪酬","负债合计"]
|
1216
|
-
dfp3=fs_item_analysis_1(df,ticker,fsdate,items3,title_txt)
|
1328
|
+
dfp3=fs_item_analysis_1(df,ticker,fsdate,items3,title_txt,facecolor=facecolor)
|
1217
1329
|
|
1218
1330
|
#所有者权益变动趋势
|
1219
1331
|
title_txt=title_head+"主要权益项目"
|
@@ -1237,36 +1349,36 @@ def asset_liab_structure_china(tickers,fsdates):
|
|
1237
1349
|
notesB=notes8+'\n'+notes9+'\n'+notes10+'\n'+notes11+'\n'+notes12+'\n'+notes13+'\n'+notes14
|
1238
1350
|
|
1239
1351
|
notes=notesA+'\n'+notesB
|
1240
|
-
dfp4=fs_item_analysis_1(df,ticker,fsdate,items4,title_txt,notes)
|
1352
|
+
dfp4=fs_item_analysis_1(df,ticker,fsdate,items4,title_txt,notes,facecolor=facecolor)
|
1241
1353
|
|
1242
1354
|
### 货币资金与应收项目
|
1243
1355
|
#资产变动趋势1:"货币资金","应收票据","应收账款"
|
1244
1356
|
title_txt=title_head+"货币资金与应收项目"
|
1245
1357
|
items1=["货币资金","应收票据","应收账款"]
|
1246
|
-
dfp1=fs_item_analysis_1(df,ticker,fsdate,items1,title_txt)
|
1358
|
+
dfp1=fs_item_analysis_1(df,ticker,fsdate,items1,title_txt,facecolor=facecolor)
|
1247
1359
|
|
1248
1360
|
#应收账款占比变动分析
|
1249
1361
|
fsdates1=fsdates[:3]
|
1250
1362
|
items5=["应收账款","资产总计"]
|
1251
1363
|
title_txt=title_head+"应收账款占比变动情况"
|
1252
|
-
dfp5=fs_item_analysis_2(df,ticker,fsdates1,items5,title_txt)
|
1364
|
+
dfp5=fs_item_analysis_2(df,ticker,fsdates1,items5,title_txt,facecolor=facecolor)
|
1253
1365
|
|
1254
1366
|
#应收与营业收入增幅对比
|
1255
1367
|
fsdates2=fsdates[:2]
|
1256
1368
|
items6=['应收账款',"应收票据",'营业总收入']
|
1257
1369
|
title_txt=title_head+"应收项目与营业收入增幅对比"
|
1258
|
-
dfp6=fs_item_analysis_6(df,ticker,fsdates2,items6,title_txt)
|
1370
|
+
dfp6=fs_item_analysis_6(df,ticker,fsdates2,items6,title_txt,facecolor=facecolor)
|
1259
1371
|
|
1260
1372
|
#应收账款占比同行对比
|
1261
1373
|
items7=['应收账款','资产总计','应收账款占比%']
|
1262
1374
|
title_txt=title_head+"应收账款占比同行对比"
|
1263
|
-
dfp7=fs_item_analysis_7(df,tickers,fsdate,items7,title_txt)
|
1375
|
+
dfp7=fs_item_analysis_7(df,tickers,fsdate,items7,title_txt,facecolor=facecolor)
|
1264
1376
|
|
1265
1377
|
### 存货
|
1266
1378
|
#存货占比变动分析
|
1267
1379
|
items8=["存货","资产总计"]
|
1268
1380
|
title_txt=title_head+"存货占比变动情况"
|
1269
|
-
dfp8=fs_item_analysis_2(df,ticker,fsdates1,items8,title_txt)
|
1381
|
+
dfp8=fs_item_analysis_2(df,ticker,fsdates1,items8,title_txt,facecolor=facecolor)
|
1270
1382
|
"""
|
1271
1383
|
items9=["存货","营业总收入"]
|
1272
1384
|
dfp9=fs_item_analysis_6(df,ticker,fsdates2,items9)
|
@@ -1274,30 +1386,30 @@ def asset_liab_structure_china(tickers,fsdates):
|
|
1274
1386
|
#存货与营业收入增幅对比分析
|
1275
1387
|
items10=['存货','流动资产合计',"速动资产合计","资产总计"]
|
1276
1388
|
title_txt=title_head+"存货与资产项目增幅对比"
|
1277
|
-
dfp10=fs_item_analysis_6(df,ticker,fsdates2,items10,title_txt)
|
1389
|
+
dfp10=fs_item_analysis_6(df,ticker,fsdates2,items10,title_txt,facecolor=facecolor)
|
1278
1390
|
|
1279
1391
|
#存货占比与行业对比
|
1280
1392
|
items11=['存货','资产总计','存货占比%']
|
1281
1393
|
title_txt=title_head+"存货占比情况同行对比"
|
1282
|
-
dfp11=fs_item_analysis_7(df,tickers,fsdate,items11,title_txt)
|
1394
|
+
dfp11=fs_item_analysis_7(df,tickers,fsdate,items11,title_txt,facecolor=facecolor)
|
1283
1395
|
|
1284
1396
|
### 偿债能力
|
1285
1397
|
#流动比率变动分析
|
1286
1398
|
title_txt=title_head+"流动比率变动情况"
|
1287
|
-
dfp12=fs_item_analysis_3(df,ticker,fsdates1,title_txt)
|
1399
|
+
dfp12=fs_item_analysis_3(df,ticker,fsdates1,title_txt,facecolor=facecolor)
|
1288
1400
|
|
1289
1401
|
#速动比率变动分析
|
1290
1402
|
title_txt=title_head+"速动比率变动情况"
|
1291
|
-
dfp13=fs_item_analysis_4(df,ticker,fsdates1,title_txt)
|
1403
|
+
dfp13=fs_item_analysis_4(df,ticker,fsdates1,title_txt,facecolor=facecolor)
|
1292
1404
|
|
1293
1405
|
#资产负债率变动分析
|
1294
1406
|
title_txt=title_head+"资产负债率变动情况"
|
1295
|
-
dfp14=fs_item_analysis_5(df,ticker,fsdates1,title_txt)
|
1407
|
+
dfp14=fs_item_analysis_5(df,ticker,fsdates1,title_txt,facecolor=facecolor)
|
1296
1408
|
|
1297
1409
|
#资产负债率同行比较
|
1298
1410
|
title_txt=title_head+"资产负债率同行比较"
|
1299
1411
|
items15=['资产总计','资产负债率%','流动比率%','速动比率%']
|
1300
|
-
dfp15=fs_item_analysis_8(df,tickers,fsdate,items15,title_txt)
|
1412
|
+
dfp15=fs_item_analysis_8(df,tickers,fsdate,items15,title_txt,facecolor=facecolor)
|
1301
1413
|
|
1302
1414
|
return
|
1303
1415
|
|
@@ -1307,15 +1419,15 @@ if __name__=='__main__':
|
|
1307
1419
|
fsdates=['2021-12-31','2020-12-31','2019-12-31','2018-12-31']
|
1308
1420
|
income_cost_structure_china(tickers,fsdates)
|
1309
1421
|
|
1310
|
-
def income_cost_china(tickers,fsdates):
|
1422
|
+
def income_cost_china(tickers,fsdates,facecolor='papayawhip'):
|
1311
1423
|
"""
|
1312
1424
|
套壳函数income_cost_structure_china
|
1313
1425
|
"""
|
1314
|
-
income_cost_structure_china(tickers,fsdates)
|
1426
|
+
income_cost_structure_china(tickers,fsdates,facecolor=facecolor)
|
1315
1427
|
|
1316
1428
|
return
|
1317
1429
|
|
1318
|
-
def income_cost_structure_china(tickers,fsdates):
|
1430
|
+
def income_cost_structure_china(tickers,fsdates,facecolor='papayawhip'):
|
1319
1431
|
"""
|
1320
1432
|
功能:分析上市公司的收入成本基本结构,并与同业公司对比。
|
1321
1433
|
注意1:分析近三期情况,fsdates要给出四个报表日期,以便获得期初数。
|
@@ -1357,11 +1469,11 @@ def income_cost_structure_china(tickers,fsdates):
|
|
1357
1469
|
comparator=tickers[0]
|
1358
1470
|
comparee=tickers[1:]
|
1359
1471
|
print(" Conducting income-cost analysis ...")
|
1360
|
-
print(" Comparator:",ticker_name(comparator))
|
1472
|
+
print(" Comparator:",ticker_name(comparator,'stock'))
|
1361
1473
|
#print(" Comparee :",ticker_name(comparee))
|
1362
1474
|
print(" Comparee :",end='')
|
1363
1475
|
if comparee != []:
|
1364
|
-
print_list(ticker_name(comparee))
|
1476
|
+
print_list(ticker_name(comparee,'stock'))
|
1365
1477
|
else:
|
1366
1478
|
print(" N/A")
|
1367
1479
|
|
@@ -1378,12 +1490,12 @@ def income_cost_structure_china(tickers,fsdates):
|
|
1378
1490
|
#print(" Possible reasons: no access to data source or invalid tickers")
|
1379
1491
|
return
|
1380
1492
|
|
1381
|
-
title_head=ticker_name(comparator)+"收入成本分析:"
|
1493
|
+
title_head=ticker_name(comparator,'stock')+"收入成本分析:"
|
1382
1494
|
|
1383
1495
|
#收入成本总体变动趋势
|
1384
1496
|
title_txt=title_head+"主要项目及其变动趋势"
|
1385
1497
|
items1=["营业总收入","营业总成本","营业成本","毛利润","营业利润","营业外收支","税前利润","所得税费用","净利润","归母净利润"]
|
1386
|
-
dfp1=fs_item_analysis_1(df,ticker,fsdate,items1,title_txt)
|
1498
|
+
dfp1=fs_item_analysis_1(df,ticker,fsdate,items1,title_txt,facecolor=facecolor)
|
1387
1499
|
|
1388
1500
|
#成本变动趋势
|
1389
1501
|
title_txt=title_head+"主要成本费用及其变动趋势"
|
@@ -1396,7 +1508,7 @@ def income_cost_structure_china(tickers,fsdates):
|
|
1396
1508
|
items2=["营业总成本","营业成本","营业税金及附加","销售费用","管理费用","研发费用",
|
1397
1509
|
"应付利息","非流动资产处置损失",
|
1398
1510
|
"资产减值损失","营业外支出"]
|
1399
|
-
dfp2=fs_item_analysis_1(df,ticker,'2021-12-31',items2,title_txt)
|
1511
|
+
dfp2=fs_item_analysis_1(df,ticker,'2021-12-31',items2,title_txt,facecolor=facecolor)
|
1400
1512
|
|
1401
1513
|
#占比变动分析:近三年
|
1402
1514
|
title_txt=title_head+"营业总成本占营业总收入比例情况"
|
@@ -1407,7 +1519,7 @@ def income_cost_structure_china(tickers,fsdates):
|
|
1407
1519
|
notes2="注2:营业收入=主营业务收入和其他非主营业务收入"
|
1408
1520
|
notes3="注3:营业总收入=营业收入+非营业收入(投资收益、营业外收入等)"
|
1409
1521
|
notes=notes1+'\n'+notes2+'\n'+notes3
|
1410
|
-
dfp3=fs_item_analysis_2(df,ticker,fsdates1,items3,title_txt,notes)
|
1522
|
+
dfp3=fs_item_analysis_2(df,ticker,fsdates1,items3,title_txt,notes,facecolor=facecolor)
|
1411
1523
|
#====================================================================
|
1412
1524
|
title_txt=title_head+"营业成本占营业总成本比例情况"
|
1413
1525
|
items4=["营业成本","营业总成本"]
|
@@ -1415,29 +1527,29 @@ def income_cost_structure_china(tickers,fsdates):
|
|
1415
1527
|
notes1="注1:营业成本是经营活动中发生的可归属于产品/劳务成本等的费用"
|
1416
1528
|
notes2="注2:营业总成本包括营业成本、营业税金及附加、三大费用和资产减值损失"
|
1417
1529
|
notes=notes1+'\n'+notes2
|
1418
|
-
dfp4=fs_item_analysis_2(df,ticker,fsdates1,items4,title_txt,notes)
|
1530
|
+
dfp4=fs_item_analysis_2(df,ticker,fsdates1,items4,title_txt,notes,facecolor=facecolor)
|
1419
1531
|
|
1420
1532
|
title_txt=title_head+"营业成本占营业总收入比例情况"
|
1421
1533
|
items5=["营业成本","营业总收入"]
|
1422
|
-
dfp5=fs_item_analysis_2(df,ticker,fsdates1,items5,title_txt)
|
1534
|
+
dfp5=fs_item_analysis_2(df,ticker,fsdates1,items5,title_txt,facecolor=facecolor)
|
1423
1535
|
|
1424
1536
|
title_txt=title_head+"营业成本增幅分析"
|
1425
1537
|
fsdates2=fsdates[:2]
|
1426
1538
|
items12=['营业成本','营业总成本','营业总收入']
|
1427
|
-
dfp12=fs_item_analysis_6(df,ticker,fsdates2,items12,title_txt)
|
1539
|
+
dfp12=fs_item_analysis_6(df,ticker,fsdates2,items12,title_txt,facecolor=facecolor)
|
1428
1540
|
|
1429
1541
|
#====================================================================
|
1430
1542
|
title_txt=title_head+"销售费用占营业总收入比例情况"
|
1431
1543
|
items6=["销售费用","营业总收入"]
|
1432
1544
|
|
1433
1545
|
notes="注:销售费用是企业销售过程中发生的各种费用"
|
1434
|
-
dfp6=fs_item_analysis_2(df,ticker,fsdates1,items6,title_txt,notes)
|
1546
|
+
dfp6=fs_item_analysis_2(df,ticker,fsdates1,items6,title_txt,notes,facecolor=facecolor)
|
1435
1547
|
#====================================================================
|
1436
1548
|
title_txt=title_head+"管理费用占营业总收入比例情况"
|
1437
1549
|
items7=["管理费用","营业总收入"]
|
1438
1550
|
|
1439
1551
|
notes="注:管理费用是行政管理部门为组织生产/经营活动发生的各种费用"
|
1440
|
-
dfp7=fs_item_analysis_2(df,ticker,fsdates1,items7,title_txt,notes)
|
1552
|
+
dfp7=fs_item_analysis_2(df,ticker,fsdates1,items7,title_txt,notes,facecolor=facecolor)
|
1441
1553
|
|
1442
1554
|
title_txt=title_head+"三项费用率同行对比"
|
1443
1555
|
items14=['营业总收入','销售费用率%','管理费用率%','研发费用率%']
|
@@ -1447,35 +1559,35 @@ def income_cost_structure_china(tickers,fsdates):
|
|
1447
1559
|
notes3="注3:研发费用率 = 研发费用 / 营业总收入"
|
1448
1560
|
notes=notes1+'\n'+notes2+'\n'+notes3
|
1449
1561
|
|
1450
|
-
dfp12=fs_item_analysis_8(df,tickers,fsdate,items14,title_txt,notes)
|
1562
|
+
dfp12=fs_item_analysis_8(df,tickers,fsdate,items14,title_txt,notes,facecolor=facecolor)
|
1451
1563
|
#====================================================================
|
1452
1564
|
title_txt=title_head+"毛利润占营业总收入比例情况"
|
1453
1565
|
items8=["毛利润","营业总收入"]
|
1454
|
-
dfp8=fs_item_analysis_2(df,ticker,fsdates1,items8,title_txt)
|
1566
|
+
dfp8=fs_item_analysis_2(df,ticker,fsdates1,items8,title_txt,facecolor=facecolor)
|
1455
1567
|
#====================================================================
|
1456
1568
|
title_txt=title_head+"营业利润占营业总收入比例情况"
|
1457
1569
|
items9=["营业利润","营业总收入"]
|
1458
|
-
dfp8=fs_item_analysis_2(df,ticker,fsdates1,items9,title_txt)
|
1570
|
+
dfp8=fs_item_analysis_2(df,ticker,fsdates1,items9,title_txt,facecolor=facecolor)
|
1459
1571
|
#====================================================================
|
1460
1572
|
title_txt=title_head+"税前利润占营业总收入比例情况"
|
1461
1573
|
items10=["税前利润","营业总收入"]
|
1462
|
-
dfp9=fs_item_analysis_2(df,ticker,fsdates1,items10,title_txt)
|
1574
|
+
dfp9=fs_item_analysis_2(df,ticker,fsdates1,items10,title_txt,facecolor=facecolor)
|
1463
1575
|
#====================================================================
|
1464
1576
|
title_txt=title_head+"净利润占营业总收入比例情况"
|
1465
1577
|
items11=["净利润","营业总收入"]
|
1466
|
-
dfp9=fs_item_analysis_2(df,ticker,fsdates1,items11,title_txt)
|
1578
|
+
dfp9=fs_item_analysis_2(df,ticker,fsdates1,items11,title_txt,facecolor=facecolor)
|
1467
1579
|
|
1468
1580
|
#增幅分析:近两年
|
1469
1581
|
title_txt=title_head+"四种利润对比"
|
1470
1582
|
items13=['毛利润','营业利润','税前利润','净利润']
|
1471
|
-
dfp11=fs_item_analysis_6(df,ticker,fsdates2,items13,title_txt)
|
1583
|
+
dfp11=fs_item_analysis_6(df,ticker,fsdates2,items13,title_txt,facecolor=facecolor)
|
1472
1584
|
|
1473
1585
|
#同行比较
|
1474
1586
|
title_txt=title_head+"利润率同行对比"
|
1475
1587
|
#items15=['营业利润','营业利润率%','税前利润率%','实际所得税率%','净利润','净利润率%']
|
1476
1588
|
#items15=['毛利润率%','营业利润率%','税前利润率%','净利润率%']
|
1477
1589
|
items15=['净利润率%','税前利润率%','营业利润率%','毛利润率%']
|
1478
|
-
dfp12=fs_item_analysis_8(df,tickers,fsdate,items15,title_txt)
|
1590
|
+
dfp12=fs_item_analysis_8(df,tickers,fsdate,items15,title_txt,facecolor=facecolor)
|
1479
1591
|
|
1480
1592
|
return
|
1481
1593
|
|
@@ -1485,16 +1597,16 @@ if __name__=='__main__':
|
|
1485
1597
|
fsdates=['2021-12-31','2020-12-31','2019-12-31','2018-12-31']
|
1486
1598
|
cash_flow_structure_china(tickers,fsdates)
|
1487
1599
|
|
1488
|
-
def cash_flow_china(tickers,fsdates):
|
1600
|
+
def cash_flow_china(tickers,fsdates,facecolor='papayawhip'):
|
1489
1601
|
"""
|
1490
1602
|
套壳函数cash_flow_structure_china
|
1491
1603
|
"""
|
1492
|
-
cash_flow_structure_china(tickers,fsdates)
|
1604
|
+
cash_flow_structure_china(tickers,fsdates,facecolor=facecolor)
|
1493
1605
|
|
1494
1606
|
return
|
1495
1607
|
|
1496
1608
|
|
1497
|
-
def cash_flow_structure_china(tickers,fsdates):
|
1609
|
+
def cash_flow_structure_china(tickers,fsdates,facecolor='papayawhip'):
|
1498
1610
|
"""
|
1499
1611
|
功能:分析上市公司的现金流量基本结构,并与同业公司对比。
|
1500
1612
|
注意1:分析近三期情况,fsdates要给出四个报表日期,以便获得期初数。
|
@@ -1535,10 +1647,10 @@ def cash_flow_structure_china(tickers,fsdates):
|
|
1535
1647
|
comparator=tickers[0]
|
1536
1648
|
comparee=tickers[1:]
|
1537
1649
|
print(" Conducting cash flow analysis ...")
|
1538
|
-
print(" Comparator:",ticker_name(comparator))
|
1650
|
+
print(" Comparator:",ticker_name(comparator,'stock'))
|
1539
1651
|
print(" Comparee :",end='')
|
1540
1652
|
if comparee != []:
|
1541
|
-
print_list(ticker_name(comparee))
|
1653
|
+
print_list(ticker_name(comparee,'stock'))
|
1542
1654
|
else:
|
1543
1655
|
print(" N/A")
|
1544
1656
|
|
@@ -1555,7 +1667,7 @@ def cash_flow_structure_china(tickers,fsdates):
|
|
1555
1667
|
#print(" Possible reasons: no access to data source or invalid tickers")
|
1556
1668
|
return
|
1557
1669
|
|
1558
|
-
title_head=ticker_name(comparator)+"现金流分析:"
|
1670
|
+
title_head=ticker_name(comparator,'stock')+"现金流分析:"
|
1559
1671
|
|
1560
1672
|
#总体变动趋势
|
1561
1673
|
title_txt=title_head+"主要项目及其变动趋势"
|
@@ -1563,23 +1675,23 @@ def cash_flow_structure_china(tickers,fsdates):
|
|
1563
1675
|
"投资活动现金流净额","投资活动现金流入","投资活动现金流出",
|
1564
1676
|
"筹资活动现金流净额","筹资活动现金流入","筹资活动现金流出",
|
1565
1677
|
"汇率对现金流的影响","现金流量净增加额"]
|
1566
|
-
dfp1=fs_item_analysis_1(df,ticker,fsdate,items1,title_txt)
|
1678
|
+
dfp1=fs_item_analysis_1(df,ticker,fsdate,items1,title_txt,facecolor=facecolor)
|
1567
1679
|
|
1568
1680
|
#占比变动分析:近三年
|
1569
1681
|
title_txt=title_head+"经营活动现金流入占比情况"
|
1570
1682
|
fsdates1=fsdates[:3]
|
1571
1683
|
items3=["经营活动现金流入","营业总收入"]
|
1572
|
-
dfp3=fs_item_analysis_2(df,ticker,fsdates1,items3,title_txt)
|
1684
|
+
dfp3=fs_item_analysis_2(df,ticker,fsdates1,items3,title_txt,facecolor=facecolor)
|
1573
1685
|
|
1574
1686
|
title_txt=title_head+"经营活动现金流净额占比情况"
|
1575
1687
|
items4=["经营活动现金流净额","营业利润"]
|
1576
|
-
dfp3=fs_item_analysis_2(df,ticker,fsdates1,items4,title_txt)
|
1688
|
+
dfp3=fs_item_analysis_2(df,ticker,fsdates1,items4,title_txt,facecolor=facecolor)
|
1577
1689
|
|
1578
1690
|
#增幅分析:近两年
|
1579
1691
|
title_txt=title_head+"经营活动现金流增幅情况"
|
1580
1692
|
fsdates2=fsdates[:2]
|
1581
1693
|
items12=['经营活动现金流入','经营活动现金流出','经营活动现金流净额']
|
1582
|
-
dfp12=fs_item_analysis_6(df,ticker,fsdates2,items12,title_txt)
|
1694
|
+
dfp12=fs_item_analysis_6(df,ticker,fsdates2,items12,title_txt,facecolor=facecolor)
|
1583
1695
|
|
1584
1696
|
#同行比较
|
1585
1697
|
title_txt=title_head+"现金收入能力同行比较"
|
@@ -1589,7 +1701,7 @@ def cash_flow_structure_china(tickers,fsdates):
|
|
1589
1701
|
notes2="注2:现金购销比率 = 经营活动现金流出 / 经营活动现金流入"
|
1590
1702
|
notes3="注3:营业现金回笼率 = 经营活动现金流入 / 营业总收入"
|
1591
1703
|
notes=notes1+'\n'+notes2+'\n'+notes3
|
1592
|
-
dfp12=fs_item_analysis_8(df,tickers,fsdate,items16,title_txt,notes)
|
1704
|
+
dfp12=fs_item_analysis_8(df,tickers,fsdate,items16,title_txt,notes,facecolor=facecolor)
|
1593
1705
|
|
1594
1706
|
title_txt=title_head+"现金偿债能力同行比较"
|
1595
1707
|
items14=['短期现金偿债能力%','长期现金偿债能力%']
|
@@ -1597,7 +1709,7 @@ def cash_flow_structure_china(tickers,fsdates):
|
|
1597
1709
|
notes1="注1:短期现金偿债能力 = 经营活动现金流净额 / 流动负债合计"
|
1598
1710
|
notes2="注2:长期现金偿债能力 = 经营活动现金流净额 / 负债合计"
|
1599
1711
|
notes=notes1+'\n'+notes2
|
1600
|
-
dfp12=fs_item_analysis_8(df,tickers,fsdate,items14,title_txt,notes)
|
1712
|
+
dfp12=fs_item_analysis_8(df,tickers,fsdate,items14,title_txt,notes,facecolor=facecolor)
|
1601
1713
|
|
1602
1714
|
title_txt=title_head+"现金支付能力同行比较"
|
1603
1715
|
items15=['现金支付股利能力(元)','现金综合支付能力%','支付给职工的现金比率%']
|
@@ -1606,7 +1718,7 @@ def cash_flow_structure_china(tickers,fsdates):
|
|
1606
1718
|
notes2="注2:现金综合支付能力 = 经营活动现金流净额 / 所有者权益合计"
|
1607
1719
|
notes3="注3:支付给职工的现金比率 = 支付给(为)职工支付的现金 / 经营活动现金流入"
|
1608
1720
|
notes=notes1+'\n'+notes2+'\n'+notes3
|
1609
|
-
dfp12=fs_item_analysis_8(df,tickers,fsdate,items15,title_txt,notes)
|
1721
|
+
dfp12=fs_item_analysis_8(df,tickers,fsdate,items15,title_txt,notes,facecolor=facecolor)
|
1610
1722
|
|
1611
1723
|
title_txt=title_head+"财务指标含金量同行比较"
|
1612
1724
|
items17=['盈利现金比率%','现金流入流出比率%','资产现金回收率%']
|
@@ -1615,7 +1727,7 @@ def cash_flow_structure_china(tickers,fsdates):
|
|
1615
1727
|
notes2="注2:现金流入流出比率 = 经营活动现金流入 / 经营活动现金流出"
|
1616
1728
|
notes3="注3:资产现金回收率 = 经营活动现金流净额 / 资产总计"
|
1617
1729
|
notes=notes1+'\n'+notes2+'\n'+notes3
|
1618
|
-
dfp12=fs_item_analysis_8(df,tickers,fsdate,items17,title_txt,notes)
|
1730
|
+
dfp12=fs_item_analysis_8(df,tickers,fsdate,items17,title_txt,notes,facecolor=facecolor)
|
1619
1731
|
|
1620
1732
|
return
|
1621
1733
|
|
@@ -1674,8 +1786,49 @@ def fs_analysis_china(tickers,fsdates=[],analysis_type='balance sheet', \
|
|
1674
1786
|
category='profile',business_period='recent', \
|
1675
1787
|
printout=False,gview=False, \
|
1676
1788
|
loc1='upper left',loc2='upper right', \
|
1677
|
-
):
|
1789
|
+
facecolor='whitesmoke'):
|
1678
1790
|
"""
|
1791
|
+
【功能】财务报表分析,仅适用于中国A股,注意不适用于港股和美股(含中概股)
|
1792
|
+
|
1793
|
+
选项tickers:必选
|
1794
|
+
单只股票:用于单只股票历史财报对比
|
1795
|
+
股票列表:用于股票之间同期财报横向对比
|
1796
|
+
|
1797
|
+
选项fsdates:必选
|
1798
|
+
单个财报日期:适用于选项tickers为股票列表时
|
1799
|
+
财报日期列表:适用于选项tickers为单只股票时,至少四个财报日期,便于对比
|
1800
|
+
|
1801
|
+
选项analysis_type:
|
1802
|
+
资产负债表分析(默认):balance sheet, asset liability
|
1803
|
+
利润表分析:income statement, cost, expense, earning
|
1804
|
+
现金流量表分析:cash flow, cashflow statement
|
1805
|
+
财报概述:financial summary
|
1806
|
+
财务指标:financial indicator
|
1807
|
+
股票画像:stock profile, 下面还可分别选择不同的category项目
|
1808
|
+
杜邦分析:dupont identify, dupont analysis
|
1809
|
+
杜邦分解:dupont decompose,需要安装graphviz插件
|
1810
|
+
|
1811
|
+
选项category:
|
1812
|
+
基本信息(默认):profile
|
1813
|
+
股东信息:shareholder
|
1814
|
+
历史分红:dividend
|
1815
|
+
主营业务:business
|
1816
|
+
市场估值:valuation
|
1817
|
+
财务概况:financial
|
1818
|
+
|
1819
|
+
选项business_period:
|
1820
|
+
最新(默认):recent,可能为最新可获得的季报或中报或年报
|
1821
|
+
最新的季报:quarterly
|
1822
|
+
最新的中报:semiannual
|
1823
|
+
最新的年报:annual
|
1824
|
+
|
1825
|
+
选项loc1/loc2:适用于需要绘图时指定图例的位置,仅在双图例重叠时手动调整
|
1826
|
+
|
1827
|
+
选项facecolor:指定表格/绘图的背景颜色
|
1828
|
+
烟白色(默认):whitesmoke
|
1829
|
+
其他颜色:参见matplotlib颜色列表,例如淡雅小麦色papayawhip
|
1830
|
+
|
1831
|
+
【备注】封装说明
|
1679
1832
|
套壳函数1:tickers为股票列表,fsdates为财报日期,可为单个日期或日期列表
|
1680
1833
|
asset_liab_china, income_cost_china, cash_flow_china
|
1681
1834
|
|
@@ -1686,9 +1839,9 @@ def fs_analysis_china(tickers,fsdates=[],analysis_type='balance sheet', \
|
|
1686
1839
|
compare_fin_indicator_china
|
1687
1840
|
|
1688
1841
|
套壳函数4:tickers为股票代码,fsdates不需要,
|
1689
|
-
|
1690
|
-
|
1691
|
-
|
1842
|
+
stock_profile_china
|
1843
|
+
|
1844
|
+
套壳函数5/6:杜邦分析compare_dupont_china / 杜邦分解dupont_decompose
|
1692
1845
|
"""
|
1693
1846
|
|
1694
1847
|
# 统一转小写,便于判断
|
@@ -1704,7 +1857,7 @@ def fs_analysis_china(tickers,fsdates=[],analysis_type='balance sheet', \
|
|
1704
1857
|
fsdates=gen_yoy_dates(fsdates,num=4)
|
1705
1858
|
|
1706
1859
|
# 分析资产负债表
|
1707
|
-
asset_liab_china(tickers,fsdates)
|
1860
|
+
asset_liab_china(tickers,fsdates,facecolor=facecolor)
|
1708
1861
|
return
|
1709
1862
|
|
1710
1863
|
elif ('income' in analysis_type1) or ('cost' in analysis_type1) \
|
@@ -1717,7 +1870,7 @@ def fs_analysis_china(tickers,fsdates=[],analysis_type='balance sheet', \
|
|
1717
1870
|
fsdates=gen_yoy_dates(fsdates,num=4)
|
1718
1871
|
|
1719
1872
|
# 分析利润表
|
1720
|
-
income_cost_china(tickers,fsdates)
|
1873
|
+
income_cost_china(tickers,fsdates,facecolor=facecolor)
|
1721
1874
|
return
|
1722
1875
|
|
1723
1876
|
elif ('cash' in analysis_type1) or ('flow' in analysis_type1):
|
@@ -1729,7 +1882,7 @@ def fs_analysis_china(tickers,fsdates=[],analysis_type='balance sheet', \
|
|
1729
1882
|
fsdates=gen_yoy_dates(fsdates,num=4)
|
1730
1883
|
|
1731
1884
|
# 分析现金流量表
|
1732
|
-
cash_flow_china(tickers,fsdates)
|
1885
|
+
cash_flow_china(tickers,fsdates,facecolor=facecolor)
|
1733
1886
|
return
|
1734
1887
|
|
1735
1888
|
elif ('summary' in analysis_type1):
|
@@ -1754,7 +1907,7 @@ def fs_analysis_china(tickers,fsdates=[],analysis_type='balance sheet', \
|
|
1754
1907
|
|
1755
1908
|
# 分析财报摘要
|
1756
1909
|
from siat.financials_china import compare_fin_summary_china
|
1757
|
-
df_summary=compare_fin_summary_china(tickers,fsdates)
|
1910
|
+
df_summary=compare_fin_summary_china(tickers,fsdates,facecolor=facecolor)
|
1758
1911
|
return
|
1759
1912
|
|
1760
1913
|
elif ('indicator' in analysis_type1):
|
@@ -1779,7 +1932,7 @@ def fs_analysis_china(tickers,fsdates=[],analysis_type='balance sheet', \
|
|
1779
1932
|
|
1780
1933
|
# 分析主要财务指标和比率
|
1781
1934
|
from siat.financials_china import compare_fin_indicator_china
|
1782
|
-
df_ind=compare_fin_indicator_china(tickers,fsdates)
|
1935
|
+
df_ind=compare_fin_indicator_china(tickers,fsdates,facecolor=facecolor)
|
1783
1936
|
return
|
1784
1937
|
|
1785
1938
|
elif ('profile' in analysis_type1):
|
@@ -1789,7 +1942,7 @@ def fs_analysis_china(tickers,fsdates=[],analysis_type='balance sheet', \
|
|
1789
1942
|
return
|
1790
1943
|
|
1791
1944
|
# 分析单只股票的全方位概况
|
1792
|
-
stock_profile_china(tickers,category,business_period,loc1=loc1,loc2=loc2)
|
1945
|
+
stock_profile_china(tickers,category,business_period,loc1=loc1,loc2=loc2,facecolor=facecolor)
|
1793
1946
|
return
|
1794
1947
|
|
1795
1948
|
elif ('dupont' in analysis_type1) and (('identity' in analysis_type1) or ('analysis' in analysis_type1)):
|
@@ -1807,7 +1960,7 @@ def fs_analysis_china(tickers,fsdates=[],analysis_type='balance sheet', \
|
|
1807
1960
|
|
1808
1961
|
# 多只股票的杜邦分析对比
|
1809
1962
|
from siat.financials_china import compare_dupont_china
|
1810
|
-
df_db=compare_dupont_china(tickers,fsdate=fsdates,printout=printout)
|
1963
|
+
df_db=compare_dupont_china(tickers,fsdate=fsdates,printout=printout,facecolor=facecolor)
|
1811
1964
|
return
|
1812
1965
|
|
1813
1966
|
elif ('dupont' in analysis_type1) and ('decompose' in analysis_type1):
|
@@ -1825,7 +1978,7 @@ def fs_analysis_china(tickers,fsdates=[],analysis_type='balance sheet', \
|
|
1825
1978
|
|
1826
1979
|
# 单只股票的多层杜邦分解
|
1827
1980
|
from siat.financials_china import dupont_decompose_china
|
1828
|
-
df_dbd=dupont_decompose_china(ticker=tickers,fsdate=fsdates,gview=gview)
|
1981
|
+
df_dbd=dupont_decompose_china(ticker=tickers,fsdate=fsdates,gview=gview,facecolor=facecolor)
|
1829
1982
|
return
|
1830
1983
|
|
1831
1984
|
else:
|