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/risk_adjusted_return2.py
CHANGED
@@ -518,9 +518,11 @@ if __name__=='__main__':
|
|
518
518
|
|
519
519
|
def compare_1ticker_mrar(ticker,start,end,rar=['sharpe','sortino','treynor','alpha'], \
|
520
520
|
ret_type="Annual Ret%",RF=0,regression_period=365, \
|
521
|
-
graph=True,axhline_value=0,axhline_label='', \
|
521
|
+
graph=True,axhline_value=0,axhline_label='',facecolor='whitesmoke', \
|
522
522
|
printout=False,sortby='tpw_mean',trailing=7,trend_threshhold=0.01, \
|
523
|
-
annotate=False,
|
523
|
+
annotate=False,annotate_value=False, \
|
524
|
+
mark_top=False,mark_bottom=False,mark_end=False, \
|
525
|
+
mktidx='auto',source='auto',ticker_type='auto'):
|
524
526
|
"""
|
525
527
|
功能:一只股票,对比其多个rar,支持股票和投资组合
|
526
528
|
"""
|
@@ -601,7 +603,6 @@ def compare_1ticker_mrar(ticker,start,end,rar=['sharpe','sortino','treynor','alp
|
|
601
603
|
|
602
604
|
#绘图
|
603
605
|
if graph:
|
604
|
-
|
605
606
|
y_label=''
|
606
607
|
import datetime; todaydt = datetime.date.today()
|
607
608
|
x_label="数据来源: 综合新浪/stooq/Yahoo,"+str(todaydt)
|
@@ -609,7 +610,10 @@ def compare_1ticker_mrar(ticker,start,end,rar=['sharpe','sortino','treynor','alp
|
|
609
610
|
|
610
611
|
draw_lines(df1,y_label,x_label=footnotex, \
|
611
612
|
axhline_value=axhline_value,axhline_label=axhline_label, \
|
612
|
-
title_txt=title_txt,data_label=False,
|
613
|
+
title_txt=title_txt,data_label=False, \
|
614
|
+
annotate=annotate,annotate_value=annotate, \
|
615
|
+
mark_top=mark_top,mark_bottom=mark_bottom,mark_end=mark_end, \
|
616
|
+
facecolor=facecolor)
|
613
617
|
|
614
618
|
#制表
|
615
619
|
recommenddf=pd.DataFrame()
|
@@ -631,13 +635,13 @@ def compare_1ticker_mrar(ticker,start,end,rar=['sharpe','sortino','treynor','alp
|
|
631
635
|
#title_txt='***** 风险调整收益评估:'+tname+','+sortby_txt+' *****'
|
632
636
|
title_txt='风险调整收益评估:'+tname+','+sortby_txt
|
633
637
|
|
634
|
-
footnote6='
|
638
|
+
footnote6='期间:'+str(start)+'至'+str(end)+";近期指近"+str(trailing)+"个交易日。趋势变化率阈值:"+str(trend_threshhold)+"。"
|
635
639
|
footnote7="近期优先趋势和星号为多项因素综合研判,最多五颗星"
|
636
640
|
footnotey=footnote6+footnote7+'\n'+footnotex
|
637
641
|
|
638
642
|
recommenddf=descriptive_statistics2(df1,title_txt,footnotey,decimals=4, \
|
639
643
|
sortby=sortby,recommend_only=True,trailing=trailing, \
|
640
|
-
trend_threshhold=trend_threshhold)
|
644
|
+
trend_threshhold=trend_threshhold,facecolor=facecolor)
|
641
645
|
|
642
646
|
return df,recommenddf
|
643
647
|
|
@@ -664,8 +668,10 @@ def compare_mticker_1rar(ticker,start,end,rar='sharpe', \
|
|
664
668
|
ret_type="Annual Ret%",RF=0,regression_period=365, \
|
665
669
|
graph=True,axhline_value=0,axhline_label='', \
|
666
670
|
printout=False,sortby='tpw_mean',trailing=7,trend_threshhold=0.01, \
|
667
|
-
annotate=False,
|
668
|
-
|
671
|
+
annotate=False,annotate_value=False, \
|
672
|
+
mark_top=False,mark_bottom=False,mark_end=False, \
|
673
|
+
mktidx='auto',source='auto', \
|
674
|
+
style_print=True,ticker_type='auto',facecolor='whitesmoke'):
|
669
675
|
"""
|
670
676
|
功能:多只股票,对比其同一个rar,支持股票和投资组合
|
671
677
|
"""
|
@@ -753,7 +759,10 @@ def compare_mticker_1rar(ticker,start,end,rar='sharpe', \
|
|
753
759
|
|
754
760
|
draw_lines(df1,y_label,x_label=footnotex, \
|
755
761
|
axhline_value=axhline_value,axhline_label=axhline_label, \
|
756
|
-
title_txt=title_txt,data_label=False,
|
762
|
+
title_txt=title_txt,data_label=False, \
|
763
|
+
annotate=annotate,annotate_value=annotate, \
|
764
|
+
mark_top=mark_top,mark_bottom=mark_bottom,mark_end=mark_end, \
|
765
|
+
facecolor=facecolor)
|
757
766
|
|
758
767
|
#制表
|
759
768
|
recommenddf=pd.DataFrame()
|
@@ -772,15 +781,16 @@ def compare_mticker_1rar(ticker,start,end,rar='sharpe', \
|
|
772
781
|
#title_txt='***** 风险调整收益评估:基于'+ectranslate(rar)+','+sortby_txt+' *****'
|
773
782
|
title_txt='风险调整收益评估:基于'+ectranslate(rar)+','+sortby_txt
|
774
783
|
|
775
|
-
footnote6='
|
776
|
-
footnote7="
|
784
|
+
footnote6='期间为'+str(start)+'至'+str(end)+";近期指近"+str(trailing)+"个交易日。趋势变化率阈值:"+str(trend_threshhold)
|
785
|
+
footnote7="近期优先趋势和星号为风险调整收益指标加趋势等多项因素综合研判,最多五颗星"
|
777
786
|
footnotey=footnote6+'\n'+footnote7+'\n'+footnotex
|
778
787
|
|
779
788
|
#删除含有Nan的行,否则可能引起近期优先加权平均计算结果市场出现Nan
|
780
789
|
df1.dropna(inplace=True)
|
781
790
|
recommenddf=descriptive_statistics2(df1,title_txt,footnotey,decimals=4, \
|
782
791
|
sortby=sortby,recommend_only=True,trailing=trailing, \
|
783
|
-
trend_threshhold=trend_threshhold,
|
792
|
+
trend_threshhold=trend_threshhold, \
|
793
|
+
style_print=style_print,facecolor=facecolor)
|
784
794
|
|
785
795
|
return df,recommenddf
|
786
796
|
|
@@ -807,7 +817,10 @@ def compare_mticker_mrar(ticker,start,end,rar=['sharpe','alpha','sortino','treyn
|
|
807
817
|
ret_type="Annual Ret%",RF=0,regression_period=365, \
|
808
818
|
graph=True,axhline_value=0,axhline_label='', \
|
809
819
|
printout=True,sortby='tpw_mean',trailing=7,trend_threshhold=0.01, \
|
810
|
-
annotate=False,
|
820
|
+
annotate=False,annotate_value=False, \
|
821
|
+
mark_top=False,mark_bottom=False,mark_end=False, \
|
822
|
+
mktidx='auto',source='auto', \
|
823
|
+
ticker_type='auto',facecolor='whitesmoke'):
|
811
824
|
"""
|
812
825
|
功能:多只股票,多个rar,综合对比和排列。支持股票和投资组合
|
813
826
|
"""
|
@@ -827,11 +840,16 @@ def compare_mticker_mrar(ticker,start,end,rar=['sharpe','alpha','sortino','treyn
|
|
827
840
|
df=pd.DataFrame()
|
828
841
|
for r in rar:
|
829
842
|
#with HiddenPrints(): #此项将压制所有print输出,造成表头脚注不显示
|
830
|
-
_,df_tmp=compare_mticker_1rar(ticker,start,end,r, \
|
831
|
-
ret_type,RF,regression_period, \
|
832
|
-
graph,
|
833
|
-
|
834
|
-
|
843
|
+
_,df_tmp=compare_mticker_1rar(ticker=ticker,start=start,end=end,rar=r, \
|
844
|
+
ret_type=ret_type,RF=RF,regression_period=regression_period, \
|
845
|
+
graph=graph,facecolor=facecolor, \
|
846
|
+
axhline_value=axhline_value,axhline_label=axhline_label, \
|
847
|
+
printout=printout,sortby=sortby, \
|
848
|
+
trailing=trailing,trend_threshhold=trend_threshhold, \
|
849
|
+
annotate=annotate,annotate_value=annotate, \
|
850
|
+
mark_top=mark_top,mark_bottom=mark_bottom,mark_end=mark_end, \
|
851
|
+
mktidx=mktidx,source=source,style_print=True, \
|
852
|
+
ticker_type=ticker_type)
|
835
853
|
if df_tmp is None:
|
836
854
|
break
|
837
855
|
else:
|
@@ -874,6 +892,7 @@ def compare_mticker_mrar(ticker,start,end,rar=['sharpe','alpha','sortino','treyn
|
|
874
892
|
# 处理表格标题
|
875
893
|
#titletxt='===风险调整收益综合对比:'+sortby_txt+'==='
|
876
894
|
titletxt='风险调整收益综合对比:'+sortby_txt
|
895
|
+
"""
|
877
896
|
#print("\n"+titletxt)
|
878
897
|
df2=df1.style.set_caption(titletxt).set_table_styles(
|
879
898
|
[{'selector':'caption',
|
@@ -882,6 +901,29 @@ def compare_mticker_mrar(ticker,start,end,rar=['sharpe','alpha','sortino','treyn
|
|
882
901
|
df3= df2.set_properties(**{'text-align':'center'})
|
883
902
|
from IPython.display import display
|
884
903
|
display(df3)
|
904
|
+
"""
|
905
|
+
|
906
|
+
disph=df1.style.hide() #不显示索引列
|
907
|
+
dispp=disph.format(precision=3) #设置带有小数点的列精度调整为小数点后3位
|
908
|
+
#设置标题/列名
|
909
|
+
dispt=dispp.set_caption(titletxt).set_table_styles(
|
910
|
+
[{'selector':'caption', #设置标题
|
911
|
+
'props':[('color','black'),('font-size','16px'),('font-weight','bold')]}, \
|
912
|
+
{'selector':'th.col_heading', #设置列名
|
913
|
+
'props':[('color','black'),('font-size','16px'),('background-color',facecolor),('text-align','center'),('margin','auto')]}])
|
914
|
+
#设置列数值对齐
|
915
|
+
dispt1=dispt.set_properties(**{'font-size':'16px'})
|
916
|
+
dispf=dispt1.set_properties(**{'text-align':'center'})
|
917
|
+
#设置前景背景颜色
|
918
|
+
try:
|
919
|
+
dispf2=dispf.set_properties(**{'background-color':facecolor,'color':'black'})
|
920
|
+
except:
|
921
|
+
print(" #Warning(compare_mticker_mrar): color",facecolor,"is unsupported, changed to default setting")
|
922
|
+
dispf2=dispf.set_properties(**{'background-color':'whitesmoke','color':'black'})
|
923
|
+
|
924
|
+
from IPython.display import display
|
925
|
+
display(dispf2)
|
926
|
+
|
885
927
|
|
886
928
|
"""
|
887
929
|
print(df1.to_string(justify='left'))
|
@@ -963,9 +1005,11 @@ if __name__=='__main__':
|
|
963
1005
|
def compare_1ticker_1rar_mret(ticker,start,end,rar='sharpe', \
|
964
1006
|
ret_type=["Annual Ret%","Monthly Ret%"], \
|
965
1007
|
RF=0,regression_period=365, \
|
966
|
-
graph=True,axhline_value=0,axhline_label='', \
|
1008
|
+
graph=True,axhline_value=0,axhline_label='',facecolor='whitesmoke', \
|
967
1009
|
printout=False,sortby='tpw_mean',trailing=7,trend_threshhold=0.01, \
|
968
|
-
annotate=False,
|
1010
|
+
annotate=False,annotate_value=False, \
|
1011
|
+
mark_top=False,mark_bottom=False,mark_end=False, \
|
1012
|
+
mktidx='auto',source='auto',ticker_type='auto'):
|
969
1013
|
"""
|
970
1014
|
功能:一只股票,同一个rar,对比其不同的收益率类型,支持股票和投资组合
|
971
1015
|
"""
|
@@ -1049,7 +1093,10 @@ def compare_1ticker_1rar_mret(ticker,start,end,rar='sharpe', \
|
|
1049
1093
|
|
1050
1094
|
draw_lines(df1,y_label,x_label=footnotex, \
|
1051
1095
|
axhline_value=axhline_value,axhline_label=axhline_label, \
|
1052
|
-
title_txt=title_txt,data_label=False,
|
1096
|
+
title_txt=title_txt,data_label=False, \
|
1097
|
+
annotate=annotate,annotate_value=annotate, \
|
1098
|
+
mark_top=mark_top,mark_bottom=mark_bottom,mark_end=mark_end, \
|
1099
|
+
facecolor=facecolor)
|
1053
1100
|
|
1054
1101
|
#制表
|
1055
1102
|
recommenddf=pd.DataFrame()
|
@@ -1068,7 +1115,7 @@ def compare_1ticker_1rar_mret(ticker,start,end,rar='sharpe', \
|
|
1068
1115
|
#title_txt='***** 风险调整收益评估:'+'基于'+ectranslate(rar)+','+ticker_name(ticker,ticker_type)+','+sortby_txt+' *****'
|
1069
1116
|
title_txt='风险调整收益评估:'+'基于'+ectranslate(rar)+','+ticker_name(ticker,ticker_type)+','+sortby_txt
|
1070
1117
|
|
1071
|
-
footnote6='
|
1118
|
+
footnote6='期间:'+str(start)+'至'+str(end)+";近期指近"+str(trailing)+"个交易日。趋势变化率阈值:"+str(trend_threshhold)+"。"
|
1072
1119
|
footnote7="近期优先趋势和星号为多项因素综合研判,最多五颗星"
|
1073
1120
|
footnotey=footnote6+footnote7+'\n'+footnotex
|
1074
1121
|
|
@@ -1077,7 +1124,7 @@ def compare_1ticker_1rar_mret(ticker,start,end,rar='sharpe', \
|
|
1077
1124
|
|
1078
1125
|
recommenddf=descriptive_statistics2(df1,title_txt,footnotey,decimals=4, \
|
1079
1126
|
sortby=sortby,recommend_only=True,trailing=trailing, \
|
1080
|
-
trend_threshhold=trend_threshhold)
|
1127
|
+
trend_threshhold=trend_threshhold,facecolor=facecolor)
|
1081
1128
|
|
1082
1129
|
return df,recommenddf
|
1083
1130
|
|
@@ -1102,12 +1149,12 @@ if __name__=='__main__':
|
|
1102
1149
|
rars=compare_1ticker_1rar_1ret_mRF(ticker,start,end,rar,ret_type,RF)
|
1103
1150
|
|
1104
1151
|
def compare_1ticker_1rar_1ret_mRF(ticker,start,end,rar='sharpe', \
|
1105
|
-
ret_type="Annual Ret%", \
|
1106
|
-
|
1107
|
-
regression_period=365, \
|
1108
|
-
graph=True,axhline_value=0,axhline_label='', \
|
1152
|
+
ret_type="Annual Ret%",RF=[0,0.02,0.05],regression_period=365, \
|
1153
|
+
graph=True,axhline_value=0,axhline_label='',facecolor='whitesmoke', \
|
1109
1154
|
printout=False,sortby='tpw_mean',trailing=7,trend_threshhold=0.01, \
|
1110
|
-
annotate=False,
|
1155
|
+
annotate=False,annotate_value=False, \
|
1156
|
+
mark_top=False,mark_bottom=False,mark_end=False, \
|
1157
|
+
mktidx='auto',source='auto',ticker_type='auto'):
|
1111
1158
|
"""
|
1112
1159
|
功能:一只股票,相同的rar,相同的收益率类型,不同的无风险收益率
|
1113
1160
|
支持股票和投资组合
|
@@ -1189,7 +1236,10 @@ def compare_1ticker_1rar_1ret_mRF(ticker,start,end,rar='sharpe', \
|
|
1189
1236
|
|
1190
1237
|
draw_lines(df1,y_label,x_label=footnotex, \
|
1191
1238
|
axhline_value=axhline_value,axhline_label=axhline_label, \
|
1192
|
-
title_txt=title_txt,data_label=False,
|
1239
|
+
title_txt=title_txt,data_label=False, \
|
1240
|
+
annotate=annotate,annotate_value=annotate, \
|
1241
|
+
mark_top=mark_top,mark_bottom=mark_bottom,mark_end=mark_end, \
|
1242
|
+
facecolor=facecolor)
|
1193
1243
|
|
1194
1244
|
#制表
|
1195
1245
|
recommenddf=pd.DataFrame()
|
@@ -1208,7 +1258,7 @@ def compare_1ticker_1rar_1ret_mRF(ticker,start,end,rar='sharpe', \
|
|
1208
1258
|
#title_txt='***** 风险调整收益评估:'+'基于'+ectranslate(rar)+','+ticker_name(ticker,ticker_type)+','+sortby_txt+' *****'
|
1209
1259
|
title_txt='风险调整收益评估:'+'基于'+ectranslate(rar)+','+ticker_name(ticker,ticker_type)+','+sortby_txt
|
1210
1260
|
|
1211
|
-
footnote6='
|
1261
|
+
footnote6='期间为'+str(start)+'至'+str(end)+";近期指近"+str(trailing)+"个交易日。趋势变化率阈值:"+str(trend_threshhold)+"。"
|
1212
1262
|
footnote7="近期优先趋势和星号为多项因素综合研判,最多五颗星"
|
1213
1263
|
footnotey=footnote6+footnote7+'\n'+footnotex
|
1214
1264
|
|
@@ -1217,7 +1267,7 @@ def compare_1ticker_1rar_1ret_mRF(ticker,start,end,rar='sharpe', \
|
|
1217
1267
|
|
1218
1268
|
recommenddf=descriptive_statistics2(df1,title_txt,footnotey,decimals=4, \
|
1219
1269
|
sortby=sortby,recommend_only=True,trailing=trailing, \
|
1220
|
-
trend_threshhold=trend_threshhold)
|
1270
|
+
trend_threshhold=trend_threshhold,facecolor=facecolor)
|
1221
1271
|
|
1222
1272
|
return df,recommenddf
|
1223
1273
|
|
@@ -1258,9 +1308,11 @@ def compare_rar_security(ticker,start,end,rar='sharpe', \
|
|
1258
1308
|
ret_type="Annual Ret%", \
|
1259
1309
|
RF=0, \
|
1260
1310
|
regression_period=365, \
|
1261
|
-
graph=True,axhline_value=0,axhline_label='', \
|
1311
|
+
graph=True,axhline_value=0,axhline_label='',facecolor='whitesmoke', \
|
1262
1312
|
printout=False,sortby='tpw_mean',trailing=7,trend_threshhold=0.05, \
|
1263
|
-
annotate=False,
|
1313
|
+
annotate=False,annotate_value=False, \
|
1314
|
+
mark_top=False,mark_bottom=False,mark_end=False, \
|
1315
|
+
mktidx='auto',source='auto', \
|
1264
1316
|
ticker_type='auto'):
|
1265
1317
|
"""
|
1266
1318
|
功能:组合情况,可能多只股票,多个rar,多个收益率类型,多个无风险收益率
|
@@ -1284,11 +1336,15 @@ def compare_rar_security(ticker,start,end,rar='sharpe', \
|
|
1284
1336
|
if rar_num==1: rar=rar[0]
|
1285
1337
|
|
1286
1338
|
if rar_num ==1: #一个RAR
|
1287
|
-
df=compare_mticker_1rar(ticker,start,end,rar, \
|
1288
|
-
ret_type,RF,regression_period, \
|
1289
|
-
graph,axhline_value,axhline_label, \
|
1290
|
-
printout,
|
1291
|
-
|
1339
|
+
df=compare_mticker_1rar(ticker=ticker,start=start,end=end,rar=rar, \
|
1340
|
+
ret_type=ret_type,RF=RF,regression_period=regression_period, \
|
1341
|
+
graph=graph,axhline_value=axhline_value,axhline_label=axhline_label, \
|
1342
|
+
printout=printout, \
|
1343
|
+
sortby=sortby,trailing=trailing,trend_threshhold=trend_threshhold, \
|
1344
|
+
annotate=annotate,annotate_value=annotate, \
|
1345
|
+
mark_top=mark_top,mark_bottom=mark_bottom,mark_end=mark_end, \
|
1346
|
+
mktidx=mktidx,source=source, \
|
1347
|
+
ticker_type=ticker_type,facecolor=facecolor)
|
1292
1348
|
return df
|
1293
1349
|
|
1294
1350
|
if rar_num >1: #多个RAR
|
@@ -1296,8 +1352,12 @@ def compare_rar_security(ticker,start,end,rar='sharpe', \
|
|
1296
1352
|
df=compare_mticker_mrar(ticker=ticker,start=start,end=end,rar=rar, \
|
1297
1353
|
ret_type=ret_type,RF=RF,regression_period=regression_period, \
|
1298
1354
|
graph=graph,axhline_value=axhline_value,axhline_label=axhline_label, \
|
1299
|
-
printout=printout,
|
1300
|
-
|
1355
|
+
printout=printout, \
|
1356
|
+
sortby=sortby,trailing=trailing,trend_threshhold=trend_threshhold, \
|
1357
|
+
annotate=annotate,annotate_value=annotate, \
|
1358
|
+
mark_top=mark_top,mark_bottom=mark_bottom,mark_end=mark_end, \
|
1359
|
+
mktidx=mktidx,source=source, \
|
1360
|
+
ticker_type=ticker_type,facecolor=facecolor)
|
1301
1361
|
return df
|
1302
1362
|
else:
|
1303
1363
|
#实际上是单个证券
|
@@ -1311,11 +1371,15 @@ def compare_rar_security(ticker,start,end,rar='sharpe', \
|
|
1311
1371
|
if isinstance(RF,list):
|
1312
1372
|
RF=RF[0]
|
1313
1373
|
|
1314
|
-
df=compare_1ticker_mrar(ticker,start,end,rar, \
|
1315
|
-
ret_type,RF,regression_period, \
|
1316
|
-
graph,axhline_value,axhline_label, \
|
1317
|
-
printout,
|
1318
|
-
|
1374
|
+
df=compare_1ticker_mrar(ticker=ticker,start=start,end=end,rar=rar, \
|
1375
|
+
ret_type=ret_type,RF=RF,regression_period=regression_period, \
|
1376
|
+
graph=graph,axhline_value=axhline_value,axhline_label=axhline_label, \
|
1377
|
+
printout=printout,facecolor=facecolor, \
|
1378
|
+
sortby=sortby,trailing=trailing,trend_threshhold=trend_threshhold, \
|
1379
|
+
annotate=annotate,annotate_value=annotate, \
|
1380
|
+
mark_top=mark_top,mark_bottom=mark_bottom,mark_end=mark_end, \
|
1381
|
+
mktidx=mktidx,source=source, \
|
1382
|
+
ticker_type=ticker_type)
|
1319
1383
|
return df
|
1320
1384
|
else:
|
1321
1385
|
#实际上是单个RAR
|
@@ -1327,11 +1391,15 @@ def compare_rar_security(ticker,start,end,rar='sharpe', \
|
|
1327
1391
|
if isinstance(RF,list):
|
1328
1392
|
RF=RF[0]
|
1329
1393
|
|
1330
|
-
df=compare_1ticker_1rar_mret(ticker,start,end,rar, \
|
1331
|
-
ret_type,RF,regression_period, \
|
1332
|
-
graph,axhline_value,axhline_label, \
|
1333
|
-
printout,
|
1334
|
-
|
1394
|
+
df=compare_1ticker_1rar_mret(ticker=ticker,start=start,end=end,rar=rar, \
|
1395
|
+
ret_type=ret_type,RF=RF,regression_period=regression_period, \
|
1396
|
+
graph=graph,axhline_value=axhline_value,axhline_label=axhline_label, \
|
1397
|
+
printout=printout, \
|
1398
|
+
sortby=sortby,trailing=trailing,trend_threshhold=trend_threshhold, \
|
1399
|
+
annotate=annotate,annotate_value=annotate, \
|
1400
|
+
mark_top=mark_top,mark_bottom=mark_bottom,mark_end=mark_end, \
|
1401
|
+
mktidx=mktidx,source=source, \
|
1402
|
+
ticker_type=ticker_type,facecolor=facecolor)
|
1335
1403
|
return df
|
1336
1404
|
else:
|
1337
1405
|
#实际上是单个收益率类型
|
@@ -1341,24 +1409,30 @@ def compare_rar_security(ticker,start,end,rar='sharpe', \
|
|
1341
1409
|
if isinstance(RF,list):
|
1342
1410
|
if len(RF) > 1:
|
1343
1411
|
|
1344
|
-
df=compare_1ticker_1rar_1ret_mRF(ticker,start,end,rar, \
|
1345
|
-
ret_type, \
|
1346
|
-
|
1347
|
-
|
1348
|
-
|
1349
|
-
|
1350
|
-
|
1412
|
+
df=compare_1ticker_1rar_1ret_mRF(ticker=ticker,start=start,end=end,rar=rar, \
|
1413
|
+
ret_type=ret_type,RF=RF,regression_period=regression_period, \
|
1414
|
+
graph=graph,axhline_value=axhline_value,axhline_label=axhline_label, \
|
1415
|
+
printout=printout,facecolor=facecolor, \
|
1416
|
+
sortby=sortby,trailing=trailing,trend_threshhold=trend_threshhold, \
|
1417
|
+
annotate=annotate,annotate_value=annotate, \
|
1418
|
+
mark_top=mark_top,mark_bottom=mark_bottom,mark_end=mark_end, \
|
1419
|
+
mktidx=mktidx,source=source, \
|
1420
|
+
ticker_type=ticker_type)
|
1351
1421
|
return df
|
1352
1422
|
else:
|
1353
1423
|
#实际上是单个RF
|
1354
1424
|
RF=RF[0]
|
1355
1425
|
|
1356
1426
|
#情形5:1只证券,1个RAR,1个收益率类型,1个RF
|
1357
|
-
df=compare_1ticker_mrar(ticker,start,end,rar, \
|
1358
|
-
ret_type,RF,regression_period, \
|
1359
|
-
graph,axhline_value,axhline_label, \
|
1360
|
-
printout,sortby,
|
1361
|
-
|
1427
|
+
df=compare_1ticker_mrar(ticker=ticker,start=start,end=end,rar=rar, \
|
1428
|
+
ret_type=ret_type,RF=RF,regression_period=regression_period, \
|
1429
|
+
graph=graph,axhline_value=axhline_value,axhline_label=axhline_label, \
|
1430
|
+
printout=printout,sortby=sortby, \
|
1431
|
+
trailing=trailing,trend_threshhold=trend_threshhold, \
|
1432
|
+
annotate=annotate,annotate_value=annotate, \
|
1433
|
+
mktidx=mktidx,source=source, \
|
1434
|
+
ticker_type=ticker_type,facecolor=facecolor)
|
1435
|
+
|
1362
1436
|
return df
|
1363
1437
|
|
1364
1438
|
|
siat/security_trend2.py
CHANGED
@@ -87,7 +87,7 @@ def security_trend(ticker,indicator='Close', \
|
|
87
87
|
|
88
88
|
kline=False,kline_demo=False,mav=[5,10,20], \
|
89
89
|
|
90
|
-
|
90
|
+
dividend=False,split=False, \
|
91
91
|
|
92
92
|
ret_type='Annual Ret%',RF=0,regression_period=365,market_index="auto", \
|
93
93
|
sortby='tpw_mean',trailing=7,trend_threshhold=0.05, \
|
@@ -95,11 +95,15 @@ def security_trend(ticker,indicator='Close', \
|
|
95
95
|
graph=True,twinx=False,loc1='best',loc2='best', \
|
96
96
|
datatag=False,power=0, \
|
97
97
|
smooth=True,date_range=False,date_freq=False, \
|
98
|
-
|
98
|
+
|
99
|
+
preprocess='none',scaling_option='change%', \
|
100
|
+
|
99
101
|
annotate=False,annotate_value=False, \
|
100
|
-
printout=False,source='auto', \
|
101
102
|
mark_top=False,mark_bottom=False,mark_end=False, \
|
102
|
-
|
103
|
+
|
104
|
+
printout=False,source='auto', \
|
105
|
+
ticker_type='auto', \
|
106
|
+
facecolor='whitesmoke'):
|
103
107
|
|
104
108
|
"""
|
105
109
|
功能:组合指令,分析证券指标走势,支持多个证券、多个指标和多种绘图方式。
|
@@ -205,7 +209,8 @@ def security_trend(ticker,indicator='Close', \
|
|
205
209
|
fromdate=date_adjust(todate,adjust=-60)
|
206
210
|
if not isinstance(mav,list):
|
207
211
|
mav=[mav]
|
208
|
-
df=candlestick(stkcd=tickers[0],fromdate=fromdate,todate=todate,mav=mav,
|
212
|
+
df=candlestick(stkcd=tickers[0],fromdate=fromdate,todate=todate,mav=mav, \
|
213
|
+
ticker_type=ticker_type,facecolor=facecolor)
|
209
214
|
return df
|
210
215
|
|
211
216
|
if kline and kline_demo:
|
@@ -216,30 +221,31 @@ def security_trend(ticker,indicator='Close', \
|
|
216
221
|
if start in ['default']:
|
217
222
|
fromdate=date_adjust(todate,adjust=-7)
|
218
223
|
|
219
|
-
df=candlestick_demo(tickers[0],fromdate=fromdate,todate=todate,
|
224
|
+
df=candlestick_demo(tickers[0],fromdate=fromdate,todate=todate, \
|
225
|
+
ticker_type=ticker_type,facecolor=facecolor)
|
220
226
|
return df
|
221
227
|
|
222
228
|
# 处理股票分红和股票分拆:需要访问雅虎财经=====================================
|
223
|
-
if
|
229
|
+
if dividend:
|
224
230
|
if portfolio_flag:
|
225
|
-
print(" #Warning(security_trend):
|
231
|
+
print(" #Warning(security_trend): investment portfolio does not support for stock dividend")
|
226
232
|
return None
|
227
233
|
|
228
234
|
if start in ['default']:
|
229
235
|
fromdate=date_adjust(todate,adjust=-365*5)
|
230
|
-
print(" #Notice: try to access Yahoo for stock dividend
|
231
|
-
df=stock_dividend(ticker=tickers[0],fromdate=fromdate,todate=todate)
|
236
|
+
print(" #Notice: try to access Yahoo for stock dividend ...")
|
237
|
+
df=stock_dividend(ticker=tickers[0],fromdate=fromdate,todate=todate,facecolor=facecolor)
|
232
238
|
return df
|
233
239
|
|
234
|
-
if
|
240
|
+
if split:
|
235
241
|
if portfolio_flag:
|
236
|
-
print(" #Warning(security_trend):
|
242
|
+
print(" #Warning(security_trend): investment portfolio does not support for stock split")
|
237
243
|
return None
|
238
244
|
|
239
245
|
if start in ['default']:
|
240
246
|
fromdate=date_adjust(todate,adjust=-365*5)
|
241
|
-
print(" #Notice: try to access Yahoo for stock split
|
242
|
-
df=stock_split(ticker=tickers[0],fromdate=fromdate,todate=todate)
|
247
|
+
print(" #Notice: try to access Yahoo for stock split ...")
|
248
|
+
df=stock_split(ticker=tickers[0],fromdate=fromdate,todate=todate,facecolor=facecolor)
|
243
249
|
return df
|
244
250
|
|
245
251
|
|
@@ -354,7 +360,8 @@ def security_trend(ticker,indicator='Close', \
|
|
354
360
|
datatag=datatag,power=power,graph=graph, \
|
355
361
|
source=source, \
|
356
362
|
mark_top=mark_top,mark_bottom=mark_bottom, \
|
357
|
-
mark_end=mark_end,ticker_type=ticker_type
|
363
|
+
mark_end=mark_end,ticker_type=ticker_type, \
|
364
|
+
facecolor=facecolor)
|
358
365
|
return df
|
359
366
|
|
360
367
|
# 情形2:单个证券,两个普通指标,twinx==True =================================
|
@@ -362,7 +369,7 @@ def security_trend(ticker,indicator='Close', \
|
|
362
369
|
df=compare_security(tickers=tickers[0],measures=measures[:2], \
|
363
370
|
fromdate=fromdate,todate=todate,twinx=twinx, \
|
364
371
|
loc1=loc1,loc2=loc2,graph=graph,source=source, \
|
365
|
-
ticker_type=ticker_type)
|
372
|
+
ticker_type=ticker_type,facecolor=facecolor)
|
366
373
|
return df
|
367
374
|
|
368
375
|
# 情形3:单个证券,两个及以上普通指标=========================================
|
@@ -374,7 +381,7 @@ def security_trend(ticker,indicator='Close', \
|
|
374
381
|
annotate=annotate,annotate_value=annotate_value, \
|
375
382
|
source=source,
|
376
383
|
mark_top=mark_top,mark_bottom=mark_bottom,mark_end=mark_end, \
|
377
|
-
ticker_type=ticker_type)
|
384
|
+
ticker_type=ticker_type,facecolor=facecolor)
|
378
385
|
return df
|
379
386
|
|
380
387
|
# 情形4:两个证券,取第一个普通指标,twinx==True =============================
|
@@ -382,7 +389,7 @@ def security_trend(ticker,indicator='Close', \
|
|
382
389
|
df=compare_security(tickers=tickers,measures=measures[0], \
|
383
390
|
fromdate=fromdate,todate=todate,twinx=twinx, \
|
384
391
|
loc1=loc1,loc2=loc2,graph=graph,source=source, \
|
385
|
-
ticker_type=ticker_type)
|
392
|
+
ticker_type=ticker_type,facecolor=facecolor)
|
386
393
|
return df
|
387
394
|
|
388
395
|
# 情形5:两个及以上证券,取第一个普通指标=====================================
|
@@ -403,7 +410,7 @@ def security_trend(ticker,indicator='Close', \
|
|
403
410
|
|
404
411
|
if ((ticker_num == 2 and not twinx) or ticker_num > 2) and indicator_group1:
|
405
412
|
df=compare_msecurity(tickers=tickers,measure=measures[0], \
|
406
|
-
|
413
|
+
start=fromdate,end=todate, \
|
407
414
|
axhline_value=axhline_value,axhline_label=axhline_label, \
|
408
415
|
preprocess=preprocess,linewidth=linewidth, \
|
409
416
|
scaling_option=scaling_option, \
|
@@ -412,7 +419,7 @@ def security_trend(ticker,indicator='Close', \
|
|
412
419
|
smooth=smooth, \
|
413
420
|
source=source, \
|
414
421
|
mark_top=mark_top,mark_bottom=mark_bottom,mark_end=mark_end, \
|
415
|
-
ticker_type=ticker_type)
|
422
|
+
ticker_type=ticker_type,facecolor=facecolor)
|
416
423
|
return df
|
417
424
|
|
418
425
|
# 情形6:单个或多个证券,单个或多个RAR指标,支持投资组合=======================
|
@@ -423,16 +430,21 @@ def security_trend(ticker,indicator='Close', \
|
|
423
430
|
graph=graph,axhline_value=0,axhline_label='', \
|
424
431
|
printout=printout, \
|
425
432
|
sortby=sortby,trailing=trailing,trend_threshhold=trend_threshhold, \
|
426
|
-
annotate=annotate,
|
427
|
-
|
433
|
+
annotate=annotate,annotate_value=annotate_value, \
|
434
|
+
mark_top=mark_top,mark_bottom=mark_bottom,mark_end=mark_end, \
|
435
|
+
mktidx=market_index,source=source, \
|
436
|
+
ticker_type=ticker_type,facecolor=facecolor)
|
428
437
|
return df
|
429
438
|
|
430
439
|
# 情形7:单个或多个证券,CAPM贝塔系数=========================================
|
431
440
|
if indicator_group4:
|
432
441
|
df=compare_beta_security(ticker=tickers,start=fromdate,end=todate, \
|
433
442
|
RF=RF,regression_period=regression_period, \
|
434
|
-
graph=graph,
|
435
|
-
|
443
|
+
graph=graph,facecolor=facecolor, \
|
444
|
+
annotate=annotate,annotate_value=annotate_value, \
|
445
|
+
mark_top=mark_top,mark_bottom=mark_bottom,mark_end=mark_end, \
|
446
|
+
mktidx=market_index,source=source, \
|
447
|
+
ticker_type=ticker_type)
|
436
448
|
|
437
449
|
return df
|
438
450
|
|
@@ -442,7 +454,9 @@ def security_trend(ticker,indicator='Close', \
|
|
442
454
|
df=security_valuation(tickers=tickers,indicators=measures,start=fromdate,end=todate, \
|
443
455
|
preprocess=preprocess,scaling_option=scaling_option, \
|
444
456
|
twinx=twinx,loc1=loc1,loc2=loc2, \
|
445
|
-
graph=graph,
|
457
|
+
graph=graph,facecolor=facecolor, \
|
458
|
+
annotate=annotate,annotate_value=annotate_value, \
|
459
|
+
mark_top=mark_top,mark_bottom=mark_bottom,mark_end=mark_end)
|
446
460
|
return df
|
447
461
|
|
448
462
|
# 其他未预料情形
|