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/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
|
@@ -3657,6 +3671,119 @@ def ticker_type_preprocess_mticker_mixed(ticker,ticker_type='auto'):
|
|
3657
3671
|
|
3658
3672
|
|
3659
3673
|
#==============================================================================
|
3674
|
+
if __name__=='__main__':
|
3675
|
+
df=get_price('600519.SS','2024-4-1','2024-4-20')
|
3676
|
+
titletxt='This is the Tilte'
|
3677
|
+
titletxt=''
|
3678
|
+
footnote='This is the footnote'
|
3679
|
+
facecolor='papayawhip'
|
3680
|
+
decimals=2
|
3681
|
+
|
3682
|
+
#在Spyder中无法测试效果
|
3683
|
+
df_display_CSS(df,titletxt,footnote,facecolor,decimals)
|
3684
|
+
|
3685
|
+
def df_display_CSS(df,titletxt='',footnote='',facecolor='papayawhip',decimals=2, \
|
3686
|
+
first_col_align='left',second_col_align='right', \
|
3687
|
+
last_col_align='right',other_col_align='right', \
|
3688
|
+
titile_font_size='18px',heading_font_size='17px', \
|
3689
|
+
data_font_size='17px'):
|
3690
|
+
"""
|
3691
|
+
功能:采样CSS式样显示df,适用于Jupyter环境,整齐紧凑,不挑浏览器
|
3692
|
+
注意:若facecolor不被支持,则自动改为papayawhip
|
3693
|
+
"""
|
3694
|
+
#检查df是否为空
|
3695
|
+
if len(df)==0: return
|
3696
|
+
|
3697
|
+
#替换nan和inf
|
3698
|
+
import pandas as pd
|
3699
|
+
import numpy as np
|
3700
|
+
df.replace([np.inf, -np.inf],'-', inplace=True)
|
3701
|
+
df.replace([np.nan],'-', inplace=True)
|
3702
|
+
|
3703
|
+
#默认的facecolor,一旦不支持则改为这个颜色
|
3704
|
+
facecolor_default='papayawhip'
|
3705
|
+
|
3706
|
+
#不显示索引列,注意style1已经不是DaraFrame了
|
3707
|
+
style1=df.style.hide()
|
3708
|
+
|
3709
|
+
#设置数值字段的千分位符号,同时设置数值字段的小数点精度
|
3710
|
+
style2=style1.format(precision=decimals,thousands=',',na_rep='-')
|
3711
|
+
|
3712
|
+
#设置标题/列名:对齐,颜色,背景
|
3713
|
+
try:
|
3714
|
+
style3=style2.set_caption(titletxt).set_table_styles(
|
3715
|
+
[{'selector':'caption', #设置标题对齐
|
3716
|
+
'props':[('color','black'),('font-size',titile_font_size),('font-weight','bold')]}, \
|
3717
|
+
|
3718
|
+
{'selector':'th.col_heading', #设置列名对齐
|
3719
|
+
'props':[('color','black'),('background-color',facecolor), \
|
3720
|
+
('font-size',heading_font_size),('text-align','center'),('margin','auto')]}])
|
3721
|
+
except:
|
3722
|
+
style3=style2.set_caption(titletxt).set_table_styles(
|
3723
|
+
[{'selector':'caption', #设置标题对齐
|
3724
|
+
'props':[('color','black'),('font-size',titile_font_size),('font-weight','bold')]}, \
|
3725
|
+
|
3726
|
+
{'selector':'th.col_heading', #设置列名对齐
|
3727
|
+
'props':[('color','black'),('background-color',facecolor_default), \
|
3728
|
+
('font-size',heading_font_size),('text-align','center'),('margin','auto')]}])
|
3729
|
+
|
3730
|
+
#设置数据:字体大小
|
3731
|
+
style4=style3.set_properties(**{'font-size':data_font_size})
|
3732
|
+
|
3733
|
+
#设置数据:对齐,第一列,最后列,中间列
|
3734
|
+
col_list=list(df)
|
3735
|
+
style5=style4.set_properties(**{'text-align':other_col_align}).\
|
3736
|
+
set_properties(**{'text-align':first_col_align},subset=[col_list[0]]).\
|
3737
|
+
set_properties(**{'text-align':second_col_align},subset=[col_list[1]]).\
|
3738
|
+
set_properties(**{'text-align':last_col_align},subset=[col_list[-1]])
|
3739
|
+
|
3740
|
+
#设置数据:背景颜色
|
3741
|
+
try:
|
3742
|
+
style6=style5.set_properties(**{'background-color':facecolor,'color':'black'})
|
3743
|
+
except:
|
3744
|
+
print(" #Warning(df_display_CSS): unsupported color",facecolor,"\b, changed to default")
|
3745
|
+
style6=style5.set_properties(**{'background-color':facecolor_default,'color':'black'})
|
3746
|
+
|
3747
|
+
#打印数据框本身
|
3748
|
+
print('') #空一行
|
3749
|
+
from IPython.display import display
|
3750
|
+
display(style6)
|
3751
|
+
|
3752
|
+
print(footnote)
|
3753
|
+
print('') #空一行
|
3754
|
+
|
3755
|
+
return
|
3756
|
+
|
3660
3757
|
#==============================================================================
|
3661
|
-
|
3758
|
+
def upgrade_siat():
|
3759
|
+
"""
|
3760
|
+
功能:一次性升级siat及其相关插件
|
3761
|
+
|
3762
|
+
注意:在Spyder中可用,但在Jupyter中不能用,可能是路径问题!
|
3763
|
+
"""
|
3764
|
+
#系统路径
|
3765
|
+
import sys
|
3766
|
+
python_dir=sys.path
|
3767
|
+
|
3768
|
+
#插件列表
|
3769
|
+
pip_list=['siat','akshare','pandas','pandas_datareader','yfinance','yahooquery']
|
3770
|
+
pip_cmd='pip install --upgrade '
|
3771
|
+
|
3772
|
+
import subprocess
|
3773
|
+
for p in pip_list:
|
3774
|
+
print(" Upgrading",p,"\b, please wait ... ...")
|
3775
|
+
command = pip_cmd + p
|
3776
|
+
#result = subprocess.run(command, shell=True, text=True, capture_output=True)
|
3777
|
+
result = subprocess.run(command.split(' '), stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
3778
|
+
|
3779
|
+
if result.returncode == 0:
|
3780
|
+
print(' Successfully upgraded', p)
|
3781
|
+
else:
|
3782
|
+
print(' Upgrade failed:', result.returncode)
|
3783
|
+
print(' Error message:', result.stderr)
|
3784
|
+
|
3785
|
+
return
|
3662
3786
|
|
3787
|
+
#==============================================================================
|
3788
|
+
#==============================================================================
|
3789
|
+
#==============================================================================
|