siat 3.0.10__py3-none-any.whl → 3.0.15__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 +22 -8
- siat/financials_china.py +28 -21
- siat/financials_china2.py +199 -106
- siat/grafix.py +109 -45
- 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 +1 -1
- siat/stock_technical.py +1 -1
- siat/valuation.py +34 -7
- {siat-3.0.10.dist-info → siat-3.0.15.dist-info}/METADATA +1 -1
- {siat-3.0.10.dist-info → siat-3.0.15.dist-info}/RECORD +16 -16
- {siat-3.0.10.dist-info → siat-3.0.15.dist-info}/WHEEL +1 -1
- {siat-3.0.10.dist-info → siat-3.0.15.dist-info}/top_level.txt +0 -0
siat/capm_beta2.py
CHANGED
@@ -251,8 +251,10 @@ if __name__=='__main__':
|
|
251
251
|
|
252
252
|
def compare_mticker_1beta(ticker,start,end, \
|
253
253
|
RF=0,regression_period=365, \
|
254
|
-
graph=True,axhline_value=1,axhline_label='', \
|
255
|
-
annotate=False,
|
254
|
+
graph=True,axhline_value=1,axhline_label='',facecolor='whitesmoke', \
|
255
|
+
annotate=False,annotate_value=False, \
|
256
|
+
mark_top=False,mark_bottom=False,mark_end=False, \
|
257
|
+
mktidx='auto',source='auto',ticker_type='auto'):
|
256
258
|
"""
|
257
259
|
功能:多只股票,对比其贝塔系数
|
258
260
|
"""
|
@@ -337,7 +339,10 @@ def compare_mticker_1beta(ticker,start,end, \
|
|
337
339
|
|
338
340
|
draw_lines(df1,y_label,x_label=footnotex, \
|
339
341
|
axhline_value=axhline_value,axhline_label=axhline_label, \
|
340
|
-
title_txt=title_txt,data_label=False,
|
342
|
+
title_txt=title_txt,data_label=False, \
|
343
|
+
annotate=annotate,annotate_value=annotate, \
|
344
|
+
mark_top=mark_top,mark_bottom=mark_bottom,mark_end=mark_end,
|
345
|
+
facecolor=facecolor)
|
341
346
|
|
342
347
|
return df
|
343
348
|
|
@@ -362,8 +367,11 @@ if __name__=='__main__':
|
|
362
367
|
def compare_1ticker_mRF(ticker,start,end, \
|
363
368
|
RF=[0,0.02,0.05], \
|
364
369
|
regression_period=365, \
|
365
|
-
graph=True,axhline_value=1,axhline_label='', \
|
366
|
-
annotate=False,
|
370
|
+
graph=True,axhline_value=1,axhline_label='',facecolor='whitesmoke', \
|
371
|
+
annotate=False,annotate_value=False, \
|
372
|
+
mark_top=False,mark_bottom=False,mark_end=False, \
|
373
|
+
mktidx='auto',source='auto', \
|
374
|
+
ticker_type='auto'):
|
367
375
|
"""
|
368
376
|
功能:一只股票,不同的无风险收益率
|
369
377
|
"""
|
@@ -446,7 +454,10 @@ def compare_1ticker_mRF(ticker,start,end, \
|
|
446
454
|
|
447
455
|
draw_lines(df1,y_label,x_label=footnotex, \
|
448
456
|
axhline_value=axhline_value,axhline_label=axhline_label, \
|
449
|
-
title_txt=title_txt,data_label=False,
|
457
|
+
title_txt=title_txt,data_label=False, \
|
458
|
+
annotate=annotate,annotate_value=annotate, \
|
459
|
+
mark_top=mark_top,mark_bottom=mark_bottom,mark_end=mark_end, \
|
460
|
+
facecolor=facecolor)
|
450
461
|
|
451
462
|
return df
|
452
463
|
|
@@ -470,8 +481,11 @@ if __name__=='__main__':
|
|
470
481
|
def compare_1ticker_mregression_period(ticker,start,end, \
|
471
482
|
RF=0, \
|
472
483
|
regression_period=[183,365,730], \
|
473
|
-
graph=True,axhline_value=1,axhline_label='', \
|
474
|
-
annotate=False,
|
484
|
+
graph=True,axhline_value=1,axhline_label='',facecolor='whitesmoke', \
|
485
|
+
annotate=False,annotate_value=False, \
|
486
|
+
mark_top=False,mark_bottom=False,mark_end=False, \
|
487
|
+
mktidx='auto',source='auto', \
|
488
|
+
ticker_type='auto'):
|
475
489
|
"""
|
476
490
|
功能:一只股票或一个投资组合,不同的回归期间
|
477
491
|
"""
|
@@ -550,7 +564,10 @@ def compare_1ticker_mregression_period(ticker,start,end, \
|
|
550
564
|
|
551
565
|
draw_lines(df1,y_label,x_label=footnotex, \
|
552
566
|
axhline_value=axhline_value,axhline_label=axhline_label, \
|
553
|
-
title_txt=title_txt,data_label=False,
|
567
|
+
title_txt=title_txt,data_label=False, \
|
568
|
+
annotate=annotate,annotate_value=annotate, \
|
569
|
+
mark_top=mark_top,mark_bottom=mark_bottom,mark_end=mark_end, \
|
570
|
+
facecolor=facecolor)
|
554
571
|
|
555
572
|
return df
|
556
573
|
|
@@ -577,8 +594,11 @@ if __name__=='__main__':
|
|
577
594
|
betas=compare_beta_security(ticker,start,end,RF)
|
578
595
|
|
579
596
|
def compare_beta_security(ticker,start,end,RF=0,regression_period=365, \
|
580
|
-
graph=True,
|
581
|
-
|
597
|
+
graph=True,facecolor='whitesmoke', \
|
598
|
+
annotate=False,annotate_value=False, \
|
599
|
+
mark_top=False,mark_bottom=False,mark_end=False, \
|
600
|
+
mktidx='auto',source='auto', \
|
601
|
+
ticker_type='auto'):
|
582
602
|
"""
|
583
603
|
功能:组合情况,可能多只股票、多个投资组合或投资组合与股票的混合,多个无风险收益率
|
584
604
|
|
@@ -591,9 +611,11 @@ def compare_beta_security(ticker,start,end,RF=0,regression_period=365, \
|
|
591
611
|
RF=RF[0]
|
592
612
|
|
593
613
|
df=compare_mticker_1beta(ticker,start,end,RF,regression_period, \
|
594
|
-
graph, \
|
595
|
-
annotate=annotate,
|
596
|
-
|
614
|
+
graph,facecolor=facecolor, \
|
615
|
+
annotate=annotate,annotate_value=annotate, \
|
616
|
+
mark_top=mark_top,mark_bottom=mark_bottom,mark_end=mark_end, \
|
617
|
+
mktidx=mktidx,source=source, \
|
618
|
+
ticker_type=ticker_type)
|
597
619
|
return df
|
598
620
|
else:
|
599
621
|
#实际上是单个证券
|
@@ -603,9 +625,11 @@ def compare_beta_security(ticker,start,end,RF=0,regression_period=365, \
|
|
603
625
|
if isinstance(RF,list):
|
604
626
|
if len(RF) > 1:
|
605
627
|
df=compare_1ticker_mRF(ticker,start,end,RF,regression_period, \
|
606
|
-
graph, \
|
607
|
-
annotate=annotate,
|
608
|
-
|
628
|
+
graph,facecolor=facecolor, \
|
629
|
+
annotate=annotate,annotate_value=annotate, \
|
630
|
+
mark_top=mark_top,mark_bottom=mark_bottom,mark_end=mark_end, \
|
631
|
+
mktidx=mktidx,source=source, \
|
632
|
+
ticker_type=ticker_type)
|
609
633
|
return df
|
610
634
|
else:
|
611
635
|
#实际上是单个RF
|
@@ -616,9 +640,11 @@ def compare_beta_security(ticker,start,end,RF=0,regression_period=365, \
|
|
616
640
|
if len(regression_period) > 1:
|
617
641
|
df=compare_1ticker_mregression_period(ticker,start,end, \
|
618
642
|
RF,regression_period, \
|
619
|
-
graph, \
|
620
|
-
annotate=annotate,
|
621
|
-
|
643
|
+
graph,facecolor=facecolor, \
|
644
|
+
annotate=annotate,annotate_value=annotate, \
|
645
|
+
mark_top=mark_top,mark_bottom=mark_bottom,mark_end=mark_end, \
|
646
|
+
mktidx=mktidx,source=source, \
|
647
|
+
ticker_type=ticker_type)
|
622
648
|
return df
|
623
649
|
else:
|
624
650
|
#实际上是单个regression_period
|
@@ -626,8 +652,11 @@ def compare_beta_security(ticker,start,end,RF=0,regression_period=365, \
|
|
626
652
|
|
627
653
|
#情形4:1只证券,1个RF,1个回归天数?
|
628
654
|
df=compare_mticker_1beta(ticker,start,end,RF,regression_period, \
|
629
|
-
graph,
|
630
|
-
|
655
|
+
graph,facecolor=facecolor, \
|
656
|
+
annotate=annotate,annotate_value=annotate, \
|
657
|
+
mark_top=mark_top,mark_bottom=mark_bottom,mark_end=mark_end, \
|
658
|
+
mktidx=mktidx,source=source, \
|
659
|
+
ticker_type=ticker_type)
|
631
660
|
|
632
661
|
return df
|
633
662
|
|
siat/common.py
CHANGED
@@ -2160,7 +2160,8 @@ if __name__=='__main__':
|
|
2160
2160
|
|
2161
2161
|
def descriptive_statistics2(df,titletxt,footnote,decimals=4,sortby='tpw_mean', \
|
2162
2162
|
recommend_only=False,trailing=7,trend_threshhold=0.01, \
|
2163
|
-
printout=True,style_print=False
|
2163
|
+
printout=True,style_print=False, \
|
2164
|
+
facecolor='whitesmoke',fontcolor='black'):
|
2164
2165
|
"""
|
2165
2166
|
功能:进行描述性统计,并打印结果
|
2166
2167
|
df的要求:
|
@@ -2392,15 +2393,28 @@ def descriptive_statistics2(df,titletxt,footnote,decimals=4,sortby='tpw_mean', \
|
|
2392
2393
|
display(dst6sd)
|
2393
2394
|
print(footnote+"\n")
|
2394
2395
|
"""
|
2395
|
-
# 处理表格标题
|
2396
|
-
dst6sd1=dst6.style.set_caption(titletxt).set_table_styles(
|
2397
|
-
[{'selector':'caption',
|
2398
|
-
'props':[('color','black'),('font-size','16px'),('font-weight','bold')]}])
|
2399
|
-
# 列居中
|
2400
|
-
dst6sd2=dst6sd1.set_properties(**{'text-align':'center'})
|
2401
2396
|
|
2397
|
+
disph=dst6.style.hide() #不显示索引列
|
2398
|
+
dispp=disph.format(precision=3) #设置带有小数点的列精度调整为小数点后3位
|
2399
|
+
#设置标题/列名
|
2400
|
+
dispt=dispp.set_caption(titletxt).set_table_styles(
|
2401
|
+
[{'selector':'caption', #设置标题
|
2402
|
+
'props':[('color','black'),('font-size','16px'),('font-weight','bold')]}, \
|
2403
|
+
{'selector':'th.col_heading', #设置列名
|
2404
|
+
'props':[('color','black'),('font-size','16px'),('background-color',facecolor),('text-align','center'),('margin','auto')]}])
|
2405
|
+
#设置列数值对齐
|
2406
|
+
dispt1=dispt.set_properties(**{'font-size':'16px'})
|
2407
|
+
dispf=dispt1.set_properties(**{'text-align':'center'})
|
2408
|
+
#设置前景背景颜色
|
2409
|
+
try:
|
2410
|
+
dispf2=dispf.set_properties(**{'background-color':facecolor,'color':fontcolor})
|
2411
|
+
except:
|
2412
|
+
print(" #Warning(descriptive_statistics2): color",facecolor,"is unsupported, changed to default setting")
|
2413
|
+
dispf2=dispf.set_properties(**{'background-color':'whitesmoke','color':'black'})
|
2414
|
+
|
2402
2415
|
from IPython.display import display
|
2403
|
-
display(
|
2416
|
+
display(dispf2)
|
2417
|
+
|
2404
2418
|
print(footnote+"\n")
|
2405
2419
|
|
2406
2420
|
return dst5
|
siat/financials_china.py
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
所属工具包:证券投资分析工具SIAT
|
5
5
|
SIAT:Security Investment Analysis Tool
|
6
6
|
创建日期:2020年9月8日
|
7
|
-
最新修订日期:
|
7
|
+
最新修订日期:2024年4月21日
|
8
8
|
作者:王德宏 (WANG Dehong, Peter)
|
9
9
|
作者单位:北京外国语大学国际商学院
|
10
10
|
作者邮件:wdehong2000@163.com
|
@@ -45,7 +45,7 @@ plt.rcParams['axes.unicode_minus'] = False
|
|
45
45
|
import pandas as pd
|
46
46
|
import akshare as ak
|
47
47
|
|
48
|
-
#
|
48
|
+
#SUFFIX_LIST_CN=['SS','SZ','BJ','NQ']
|
49
49
|
#==============================================================================
|
50
50
|
#==============================================================================
|
51
51
|
if __name__=='__main__':
|
@@ -67,7 +67,7 @@ def get_fin_stmt_ak(ticker):
|
|
67
67
|
print(" Searching financial statements for",ticker,"...")
|
68
68
|
#是否中国股票
|
69
69
|
result,prefix,suffix=split_prefix_suffix(ticker)
|
70
|
-
if not (suffix in
|
70
|
+
if not (suffix in SUFFIX_LIST_CN):
|
71
71
|
print(" #Error(get_fin_stmt_ak): not a stock in China",ticker)
|
72
72
|
return None
|
73
73
|
|
@@ -275,11 +275,17 @@ def get_fin_stmt_ak(ticker):
|
|
275
275
|
|
276
276
|
if not ('短期现金偿债能力%' in fslist):
|
277
277
|
#fs4['短期现金偿债能力%']=round((fs4['经营活动现金流净额'] / fs4['流动负债合计'])*100,2)
|
278
|
-
|
278
|
+
try:
|
279
|
+
fs4['短期现金偿债能力%']=fs4.apply(lambda x: round((x['经营活动现金流净额'] / x['流动负债合计'])*100,2),axis=1)
|
280
|
+
except:
|
281
|
+
fs4['短期现金偿债能力%']=np.nan
|
279
282
|
|
280
283
|
if not ('长期现金偿债能力%' in fslist):
|
281
|
-
#fs4['长期现金偿债能力%']=round((fs4['经营活动现金流净额'] / fs4['负债合计'])*100,2)
|
282
|
-
|
284
|
+
#fs4['长期现金偿债能力%']=round((fs4['经营活动现金流净额'] / fs4['负债合计'])*100,2)
|
285
|
+
try:
|
286
|
+
fs4['长期现金偿债能力%']=fs4.apply(lambda x: round((x['经营活动现金流净额'] / x['负债合计'])*100,2),axis=1)
|
287
|
+
except:
|
288
|
+
fs4['长期现金偿债能力%']==np.nan
|
283
289
|
|
284
290
|
if not ('流通股股数' in fslist):
|
285
291
|
for gs in ['实收资本(或股本)','股本']:
|
@@ -648,7 +654,8 @@ if __name__=='__main__':
|
|
648
654
|
hatchlist=['.', 'o', '\\']
|
649
655
|
|
650
656
|
def compare_dupont_china(tickerlist,fsdate='latest',scale1 = 10,scale2 = 10, \
|
651
|
-
hatchlist=['.', 'o', '\\'],printout=True,sort='PM'
|
657
|
+
hatchlist=['.', 'o', '\\'],printout=True,sort='PM', \
|
658
|
+
facecolor='papayawhip'):
|
652
659
|
"""
|
653
660
|
功能:获得tickerlist中每只股票的杜邦分析项目,绘制柱状叠加比较图
|
654
661
|
tickerlist:股票代码列表,建议在10只以内
|
@@ -832,7 +839,7 @@ def get_fin_abstract_ak(ticker):
|
|
832
839
|
|
833
840
|
#是否中国股票
|
834
841
|
result,prefix,suffix=split_prefix_suffix(ticker)
|
835
|
-
if not (suffix in
|
842
|
+
if not (suffix in SUFFIX_LIST_CN):
|
836
843
|
print(" #Warning(get_fin_abstract_ak): not a stock in China",ticker)
|
837
844
|
return None
|
838
845
|
|
@@ -900,7 +907,7 @@ def get_fin_indicator_ak(ticker):
|
|
900
907
|
|
901
908
|
#是否中国股票
|
902
909
|
result,prefix,suffix=split_prefix_suffix(ticker)
|
903
|
-
if not (suffix in
|
910
|
+
if not (suffix in SUFFIX_LIST_CN):
|
904
911
|
print(" #Warning(get_fin_indicator_ak): not a stock in China",ticker)
|
905
912
|
return None
|
906
913
|
|
@@ -991,7 +998,7 @@ def get_fin_performance_ak(ticker,endDate):
|
|
991
998
|
"""
|
992
999
|
#是否中国股票
|
993
1000
|
result,prefix,suffix=split_prefix_suffix(ticker)
|
994
|
-
if not (suffix in
|
1001
|
+
if not (suffix in SUFFIX_LIST_CN):
|
995
1002
|
print(" #Warning(get_fin_performance_ak): not a stock in China",ticker)
|
996
1003
|
return None
|
997
1004
|
|
@@ -1378,7 +1385,7 @@ def industry_rank_em2(tickers,rates=['eps','naps'],industry="银行",top=10):
|
|
1378
1385
|
for t in tickers_selected:
|
1379
1386
|
#是否中国股票
|
1380
1387
|
result,prefix,suffix=split_prefix_suffix(t)
|
1381
|
-
if not (suffix in
|
1388
|
+
if not (suffix in SUFFIX_LIST_CN) and not (tickers == ''):
|
1382
1389
|
print(" #Warning(industry_rank_em2): not a stock in China",t)
|
1383
1390
|
error_flag=True
|
1384
1391
|
stocks_selected=stocks_selected+[prefix]
|
@@ -1597,7 +1604,7 @@ def get_fin_performance_akm(tickers,endDate):
|
|
1597
1604
|
prefix_list=[]
|
1598
1605
|
for t in tickers:
|
1599
1606
|
result,prefix,suffix=split_prefix_suffix(t)
|
1600
|
-
if not (suffix in
|
1607
|
+
if not (suffix in SUFFIX_LIST_CN):
|
1601
1608
|
print(" #Warning(get_fin_performance_akm): not a stock in China",t)
|
1602
1609
|
return None
|
1603
1610
|
prefix_list=prefix_list+[prefix]
|
@@ -1945,7 +1952,7 @@ def prepare_fin_rate1t2r_china(ticker,rate1,rate2,start,end,period_type='all'):
|
|
1945
1952
|
|
1946
1953
|
#是否中国股票
|
1947
1954
|
result,prefix,suffix=split_prefix_suffix(ticker)
|
1948
|
-
if not (suffix in
|
1955
|
+
if not (suffix in SUFFIX_LIST_CN):
|
1949
1956
|
print(" #Warning(prepare_fin_rate1t2r_china): not a stock in China",ticker)
|
1950
1957
|
return None,None
|
1951
1958
|
|
@@ -2066,7 +2073,7 @@ def prepare_fin_rate1tmr_china(ticker,rates,start,end,period_type='all'):
|
|
2066
2073
|
|
2067
2074
|
#是否中国股票
|
2068
2075
|
result,prefix,suffix=split_prefix_suffix(ticker)
|
2069
|
-
if not (suffix in
|
2076
|
+
if not (suffix in SUFFIX_LIST_CN):
|
2070
2077
|
print(" #Warning(prepare_fin_rate1tmr_china): not a stock in China",ticker)
|
2071
2078
|
return None
|
2072
2079
|
|
@@ -2177,7 +2184,7 @@ def prepare_fin_ratemt1r_china(tickers,rate,start,end,period_type='all'):
|
|
2177
2184
|
prefix_list=[]
|
2178
2185
|
for t in mticker_list:
|
2179
2186
|
result,prefix,suffix=split_prefix_suffix(t)
|
2180
|
-
if not (suffix in
|
2187
|
+
if not (suffix in SUFFIX_LIST_CN):
|
2181
2188
|
print(" #Warning(prepare_fin_ratemt1r_china): not a stock in China",ticker)
|
2182
2189
|
return None
|
2183
2190
|
prefix_list=prefix_list+[prefix]
|
@@ -2257,11 +2264,11 @@ def cn_codetranslate(ticker):
|
|
2257
2264
|
注意:既能转换带后缀的股票代码,也能转换不带后缀的股票代码
|
2258
2265
|
"""
|
2259
2266
|
result,prefix,suffix=split_prefix_suffix(ticker)
|
2260
|
-
if suffix in
|
2267
|
+
if suffix in SUFFIX_LIST_CN:
|
2261
2268
|
name=ticker_name(ticker)
|
2262
2269
|
|
2263
2270
|
if suffix =='':
|
2264
|
-
for s in
|
2271
|
+
for s in SUFFIX_LIST_CN:
|
2265
2272
|
ticker_try=ticker+'.'+s
|
2266
2273
|
name=ticker_name(ticker_try)
|
2267
2274
|
print('\b'*99," Looking for the short name of stock",ticker)
|
@@ -2805,7 +2812,7 @@ if __name__=='__main__':
|
|
2805
2812
|
|
2806
2813
|
g=dupont_decompose_china(ticker,fsdate)
|
2807
2814
|
|
2808
|
-
def dupont_decompose_china(ticker,fsdate,gview=False):
|
2815
|
+
def dupont_decompose_china(ticker,fsdate,gview=False,facecolor='papayawhip'):
|
2809
2816
|
"""
|
2810
2817
|
功能:杜邦分析分解图
|
2811
2818
|
ticker: 股票代码
|
@@ -2965,7 +2972,7 @@ def dupont_decompose_china(ticker,fsdate,gview=False):
|
|
2965
2972
|
"""
|
2966
2973
|
#是否中国股票
|
2967
2974
|
result,prefix,suffix=split_prefix_suffix(ticker)
|
2968
|
-
if not (suffix in
|
2975
|
+
if not (suffix in SUFFIX_LIST_CN):
|
2969
2976
|
print(" #Error(dupont_decompose_china): not a stock in China",ticker)
|
2970
2977
|
return None
|
2971
2978
|
|
@@ -3529,7 +3536,7 @@ if __name__=='__main__':
|
|
3529
3536
|
tickers=['000002.SZ','600048.SS','001979.SZ','600325.SS','000069.SZ','600383.SS','600895.SS','601155.SS']
|
3530
3537
|
fsdates='2022-12-31'
|
3531
3538
|
|
3532
|
-
def compare_fin_summary_china(tickers,fsdates):
|
3539
|
+
def compare_fin_summary_china(tickers,fsdates,facecolor='whitesmoke'):
|
3533
3540
|
"""
|
3534
3541
|
功能:分类别显示财报摘要中的指标
|
3535
3542
|
"""
|
@@ -3952,7 +3959,7 @@ if __name__=='__main__':
|
|
3952
3959
|
'2018-12-31',
|
3953
3960
|
]
|
3954
3961
|
|
3955
|
-
def compare_fin_indicator_china(tickers,fsdates):
|
3962
|
+
def compare_fin_indicator_china(tickers,fsdates,facecolor='papayawhip'):
|
3956
3963
|
"""
|
3957
3964
|
功能:分类别显示财报摘要中的指标
|
3958
3965
|
"""
|