siat 3.0.4__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/allin.py +2 -1
- siat/capm_beta2.py +51 -22
- siat/common.py +30 -3
- siat/fama_french.py +2 -0
- siat/financials_china.py +28 -21
- siat/financials_china2.py +199 -106
- siat/grafix.py +109 -45
- siat/markowitz.py +25 -14
- siat/markowitz2.py +2446 -0
- siat/risk_adjusted_return2.py +169 -85
- siat/security_trend2.py +39 -25
- siat/stock.py +127 -47
- siat/stock_china.py +1 -1
- siat/stock_technical.py +33 -12
- siat/valuation.py +34 -7
- {siat-3.0.4.dist-info → siat-3.0.15.dist-info}/METADATA +1 -1
- {siat-3.0.4.dist-info → siat-3.0.15.dist-info}/RECORD +19 -18
- {siat-3.0.4.dist-info → siat-3.0.15.dist-info}/WHEEL +1 -1
- {siat-3.0.4.dist-info → siat-3.0.15.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
|
"""
|
@@ -547,7 +549,7 @@ def compare_1ticker_mrar(ticker,start,end,rar=['sharpe','sortino','treynor','alp
|
|
547
549
|
regression_period=regression_period[0]
|
548
550
|
|
549
551
|
tname=ticker_name(ticker,ticker_type)
|
550
|
-
print(" Starting to retrive and calculate different rar for",tname,"\b, please wait
|
552
|
+
print(" Starting to retrive and calculate different rar for",tname,"\b, please wait ......\n")
|
551
553
|
|
552
554
|
#预处理ticker_type
|
553
555
|
ticker_type=ticker_type_preprocess_mticker_mixed(ticker,ticker_type)
|
@@ -590,7 +592,7 @@ def compare_1ticker_mrar(ticker,start,end,rar=['sharpe','sortino','treynor','alp
|
|
590
592
|
|
591
593
|
footnote3=''
|
592
594
|
if 'treynor' in rar or 'alpha' in rar:
|
593
|
-
footnote3="
|
595
|
+
footnote3="贝塔系数回归期间"+str(regression_period)+"个自然日"
|
594
596
|
|
595
597
|
import datetime; todaydt = datetime.date.today()
|
596
598
|
footnote4="数据来源: 综合新浪/stooq/Yahoo,"+str(todaydt)+"统计"
|
@@ -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()
|
@@ -628,15 +632,16 @@ def compare_1ticker_mrar(ticker,start,end,rar=['sharpe','sortino','treynor','alp
|
|
628
632
|
elif sortby=='trailing':
|
629
633
|
sortby_txt='按推荐标记+短期均值走势降序排列'
|
630
634
|
|
631
|
-
title_txt='***** 风险调整收益评估:'+tname+','+sortby_txt+' *****'
|
635
|
+
#title_txt='***** 风险调整收益评估:'+tname+','+sortby_txt+' *****'
|
636
|
+
title_txt='风险调整收益评估:'+tname+','+sortby_txt
|
632
637
|
|
633
|
-
footnote6='
|
634
|
-
footnote7="
|
638
|
+
footnote6='期间:'+str(start)+'至'+str(end)+";近期指近"+str(trailing)+"个交易日。趋势变化率阈值:"+str(trend_threshhold)+"。"
|
639
|
+
footnote7="近期优先趋势和星号为多项因素综合研判,最多五颗星"
|
635
640
|
footnotey=footnote6+footnote7+'\n'+footnotex
|
636
641
|
|
637
642
|
recommenddf=descriptive_statistics2(df1,title_txt,footnotey,decimals=4, \
|
638
643
|
sortby=sortby,recommend_only=True,trailing=trailing, \
|
639
|
-
trend_threshhold=trend_threshhold)
|
644
|
+
trend_threshhold=trend_threshhold,facecolor=facecolor)
|
640
645
|
|
641
646
|
return df,recommenddf
|
642
647
|
|
@@ -663,8 +668,10 @@ def compare_mticker_1rar(ticker,start,end,rar='sharpe', \
|
|
663
668
|
ret_type="Annual Ret%",RF=0,regression_period=365, \
|
664
669
|
graph=True,axhline_value=0,axhline_label='', \
|
665
670
|
printout=False,sortby='tpw_mean',trailing=7,trend_threshhold=0.01, \
|
666
|
-
annotate=False,
|
667
|
-
|
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'):
|
668
675
|
"""
|
669
676
|
功能:多只股票,对比其同一个rar,支持股票和投资组合
|
670
677
|
"""
|
@@ -690,7 +697,7 @@ def compare_mticker_1rar(ticker,start,end,rar='sharpe', \
|
|
690
697
|
RF=RF[0]
|
691
698
|
if isinstance(regression_period,list):
|
692
699
|
regression_period=regression_period[0]
|
693
|
-
print(" Starting to retrive and calculate",rar,"\b, please wait
|
700
|
+
print(" Starting to retrive and calculate",rar,"\b, please wait ......\n")
|
694
701
|
|
695
702
|
#预处理ticker_type
|
696
703
|
ticker_type_list=ticker_type_preprocess_mticker_mixed(ticker,ticker_type)
|
@@ -736,7 +743,7 @@ def compare_mticker_1rar(ticker,start,end,rar='sharpe', \
|
|
736
743
|
|
737
744
|
footnote3=''
|
738
745
|
if rar.lower() in ['treynor','alpha']:
|
739
|
-
footnote3="
|
746
|
+
footnote3="贝塔系数回归期间"+str(regression_period)+"个自然日"
|
740
747
|
|
741
748
|
import datetime; todaydt = datetime.date.today()
|
742
749
|
footnote4="数据来源: 综合新浪/stooq/Yahoo,"+str(todaydt)+"统计"
|
@@ -752,7 +759,10 @@ def compare_mticker_1rar(ticker,start,end,rar='sharpe', \
|
|
752
759
|
|
753
760
|
draw_lines(df1,y_label,x_label=footnotex, \
|
754
761
|
axhline_value=axhline_value,axhline_label=axhline_label, \
|
755
|
-
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)
|
756
766
|
|
757
767
|
#制表
|
758
768
|
recommenddf=pd.DataFrame()
|
@@ -768,17 +778,19 @@ def compare_mticker_1rar(ticker,start,end,rar='sharpe', \
|
|
768
778
|
elif sortby=='trailing':
|
769
779
|
sortby_txt='按推荐标记+短期均值走势降序排列'
|
770
780
|
|
771
|
-
title_txt='***** 风险调整收益评估:基于'+ectranslate(rar)+','+sortby_txt+' *****'
|
781
|
+
#title_txt='***** 风险调整收益评估:基于'+ectranslate(rar)+','+sortby_txt+' *****'
|
782
|
+
title_txt='风险调整收益评估:基于'+ectranslate(rar)+','+sortby_txt
|
772
783
|
|
773
|
-
footnote6='
|
774
|
-
footnote7="
|
784
|
+
footnote6='期间为'+str(start)+'至'+str(end)+";近期指近"+str(trailing)+"个交易日。趋势变化率阈值:"+str(trend_threshhold)
|
785
|
+
footnote7="近期优先趋势和星号为风险调整收益指标加趋势等多项因素综合研判,最多五颗星"
|
775
786
|
footnotey=footnote6+'\n'+footnote7+'\n'+footnotex
|
776
787
|
|
777
788
|
#删除含有Nan的行,否则可能引起近期优先加权平均计算结果市场出现Nan
|
778
789
|
df1.dropna(inplace=True)
|
779
790
|
recommenddf=descriptive_statistics2(df1,title_txt,footnotey,decimals=4, \
|
780
791
|
sortby=sortby,recommend_only=True,trailing=trailing, \
|
781
|
-
trend_threshhold=trend_threshhold,
|
792
|
+
trend_threshhold=trend_threshhold, \
|
793
|
+
style_print=style_print,facecolor=facecolor)
|
782
794
|
|
783
795
|
return df,recommenddf
|
784
796
|
|
@@ -805,7 +817,10 @@ def compare_mticker_mrar(ticker,start,end,rar=['sharpe','alpha','sortino','treyn
|
|
805
817
|
ret_type="Annual Ret%",RF=0,regression_period=365, \
|
806
818
|
graph=True,axhline_value=0,axhline_label='', \
|
807
819
|
printout=True,sortby='tpw_mean',trailing=7,trend_threshhold=0.01, \
|
808
|
-
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'):
|
809
824
|
"""
|
810
825
|
功能:多只股票,多个rar,综合对比和排列。支持股票和投资组合
|
811
826
|
"""
|
@@ -825,11 +840,16 @@ def compare_mticker_mrar(ticker,start,end,rar=['sharpe','alpha','sortino','treyn
|
|
825
840
|
df=pd.DataFrame()
|
826
841
|
for r in rar:
|
827
842
|
#with HiddenPrints(): #此项将压制所有print输出,造成表头脚注不显示
|
828
|
-
_,df_tmp=compare_mticker_1rar(ticker,start,end,r, \
|
829
|
-
ret_type,RF,regression_period, \
|
830
|
-
graph,
|
831
|
-
|
832
|
-
|
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)
|
833
853
|
if df_tmp is None:
|
834
854
|
break
|
835
855
|
else:
|
@@ -864,17 +884,46 @@ def compare_mticker_mrar(ticker,start,end,rar=['sharpe','alpha','sortino','treyn
|
|
864
884
|
sortby_txt='中位数值优先'
|
865
885
|
elif sortby=='trailing':
|
866
886
|
sortby_txt='短期均值走势优先'
|
867
|
-
|
868
|
-
titletxt='===风险调整收益综合对比:'+sortby_txt+'==='
|
869
|
-
print("\n"+titletxt)
|
870
887
|
|
871
888
|
df1=df.copy()
|
872
889
|
df1.reset_index(drop=True,inplace=True)
|
873
890
|
df1.index=df1.index + 1
|
874
891
|
|
875
|
-
|
892
|
+
# 处理表格标题
|
893
|
+
#titletxt='===风险调整收益综合对比:'+sortby_txt+'==='
|
894
|
+
titletxt='风险调整收益综合对比:'+sortby_txt
|
895
|
+
"""
|
896
|
+
#print("\n"+titletxt)
|
897
|
+
df2=df1.style.set_caption(titletxt).set_table_styles(
|
898
|
+
[{'selector':'caption',
|
899
|
+
'props':[('color','black'),('font-size','16px'),('font-weight','bold')]}])
|
900
|
+
|
901
|
+
df3= df2.set_properties(**{'text-align':'center'})
|
876
902
|
from IPython.display import display
|
877
|
-
display(
|
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
|
+
|
878
927
|
|
879
928
|
"""
|
880
929
|
print(df1.to_string(justify='left'))
|
@@ -912,7 +961,7 @@ def compare_mticker_mrar(ticker,start,end,rar=['sharpe','alpha','sortino','treyn
|
|
912
961
|
"""
|
913
962
|
|
914
963
|
#脚注
|
915
|
-
footnote1="
|
964
|
+
footnote1="风险调整收益基于"+ectranslate(ret_type)+","
|
916
965
|
if RF !=0:
|
917
966
|
footnote2="年化无风险利率"+str(round(RF*100,4))+'%'
|
918
967
|
else:
|
@@ -920,7 +969,7 @@ def compare_mticker_mrar(ticker,start,end,rar=['sharpe','alpha','sortino','treyn
|
|
920
969
|
|
921
970
|
footnote3=''
|
922
971
|
if 'treynor' in rar or 'alpha' in rar:
|
923
|
-
footnote3="
|
972
|
+
footnote3="贝塔系数回归期间"+str(regression_period)+"个自然日"
|
924
973
|
|
925
974
|
import datetime; todaydt = datetime.date.today()
|
926
975
|
footnote4="数据来源: 综合新浪/stooq/Yahoo,"+str(todaydt)+"统计"
|
@@ -929,7 +978,8 @@ def compare_mticker_mrar(ticker,start,end,rar=['sharpe','alpha','sortino','treyn
|
|
929
978
|
else:
|
930
979
|
footnotex=footnote1+footnote2+'\n'+footnote4
|
931
980
|
|
932
|
-
print("\n"+footnotex)
|
981
|
+
#print("\n"+footnotex)
|
982
|
+
print(footnotex)
|
933
983
|
|
934
984
|
return df
|
935
985
|
|
@@ -955,9 +1005,11 @@ if __name__=='__main__':
|
|
955
1005
|
def compare_1ticker_1rar_mret(ticker,start,end,rar='sharpe', \
|
956
1006
|
ret_type=["Annual Ret%","Monthly Ret%"], \
|
957
1007
|
RF=0,regression_period=365, \
|
958
|
-
graph=True,axhline_value=0,axhline_label='', \
|
1008
|
+
graph=True,axhline_value=0,axhline_label='',facecolor='whitesmoke', \
|
959
1009
|
printout=False,sortby='tpw_mean',trailing=7,trend_threshhold=0.01, \
|
960
|
-
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'):
|
961
1013
|
"""
|
962
1014
|
功能:一只股票,同一个rar,对比其不同的收益率类型,支持股票和投资组合
|
963
1015
|
"""
|
@@ -983,7 +1035,7 @@ def compare_1ticker_1rar_mret(ticker,start,end,rar='sharpe', \
|
|
983
1035
|
RF=RF[0]
|
984
1036
|
if isinstance(regression_period,list):
|
985
1037
|
regression_period=regression_period[0]
|
986
|
-
print(" Starting to retrive and calculate",rar,"for",ticker_name(ticker,ticker_type),"on different types of return, please wait
|
1038
|
+
print(" Starting to retrive and calculate",rar,"for",ticker_name(ticker,ticker_type),"on different types of return, please wait ......\n")
|
987
1039
|
|
988
1040
|
df=pd.DataFrame()
|
989
1041
|
for t in ret_type:
|
@@ -1024,7 +1076,7 @@ def compare_1ticker_1rar_mret(ticker,start,end,rar='sharpe', \
|
|
1024
1076
|
|
1025
1077
|
footnote3=''
|
1026
1078
|
if rar.lower() in ['treynor','alpha']:
|
1027
|
-
footnote3="
|
1079
|
+
footnote3="贝塔系数回归期间"+str(regression_period)+"个自然日"
|
1028
1080
|
|
1029
1081
|
import datetime; todaydt = datetime.date.today()
|
1030
1082
|
footnote4="数据来源: 综合新浪/stooq/Yahoo,"+str(todaydt)+"统计"
|
@@ -1041,7 +1093,10 @@ def compare_1ticker_1rar_mret(ticker,start,end,rar='sharpe', \
|
|
1041
1093
|
|
1042
1094
|
draw_lines(df1,y_label,x_label=footnotex, \
|
1043
1095
|
axhline_value=axhline_value,axhline_label=axhline_label, \
|
1044
|
-
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)
|
1045
1100
|
|
1046
1101
|
#制表
|
1047
1102
|
recommenddf=pd.DataFrame()
|
@@ -1057,10 +1112,11 @@ def compare_1ticker_1rar_mret(ticker,start,end,rar='sharpe', \
|
|
1057
1112
|
elif sortby=='trailing':
|
1058
1113
|
sortby_txt='按推荐标记+短期均值走势降序排列'
|
1059
1114
|
|
1060
|
-
title_txt='***** 风险调整收益评估:'+'基于'+ectranslate(rar)+','+ticker_name(ticker,ticker_type)+','+sortby_txt+' *****'
|
1115
|
+
#title_txt='***** 风险调整收益评估:'+'基于'+ectranslate(rar)+','+ticker_name(ticker,ticker_type)+','+sortby_txt+' *****'
|
1116
|
+
title_txt='风险调整收益评估:'+'基于'+ectranslate(rar)+','+ticker_name(ticker,ticker_type)+','+sortby_txt
|
1061
1117
|
|
1062
|
-
footnote6='
|
1063
|
-
footnote7="
|
1118
|
+
footnote6='期间:'+str(start)+'至'+str(end)+";近期指近"+str(trailing)+"个交易日。趋势变化率阈值:"+str(trend_threshhold)+"。"
|
1119
|
+
footnote7="近期优先趋势和星号为多项因素综合研判,最多五颗星"
|
1064
1120
|
footnotey=footnote6+footnote7+'\n'+footnotex
|
1065
1121
|
|
1066
1122
|
#删除含有Nan的行
|
@@ -1068,7 +1124,7 @@ def compare_1ticker_1rar_mret(ticker,start,end,rar='sharpe', \
|
|
1068
1124
|
|
1069
1125
|
recommenddf=descriptive_statistics2(df1,title_txt,footnotey,decimals=4, \
|
1070
1126
|
sortby=sortby,recommend_only=True,trailing=trailing, \
|
1071
|
-
trend_threshhold=trend_threshhold)
|
1127
|
+
trend_threshhold=trend_threshhold,facecolor=facecolor)
|
1072
1128
|
|
1073
1129
|
return df,recommenddf
|
1074
1130
|
|
@@ -1093,12 +1149,12 @@ if __name__=='__main__':
|
|
1093
1149
|
rars=compare_1ticker_1rar_1ret_mRF(ticker,start,end,rar,ret_type,RF)
|
1094
1150
|
|
1095
1151
|
def compare_1ticker_1rar_1ret_mRF(ticker,start,end,rar='sharpe', \
|
1096
|
-
ret_type="Annual Ret%", \
|
1097
|
-
|
1098
|
-
regression_period=365, \
|
1099
|
-
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', \
|
1100
1154
|
printout=False,sortby='tpw_mean',trailing=7,trend_threshhold=0.01, \
|
1101
|
-
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'):
|
1102
1158
|
"""
|
1103
1159
|
功能:一只股票,相同的rar,相同的收益率类型,不同的无风险收益率
|
1104
1160
|
支持股票和投资组合
|
@@ -1125,7 +1181,7 @@ def compare_1ticker_1rar_1ret_mRF(ticker,start,end,rar='sharpe', \
|
|
1125
1181
|
RF=[RF]
|
1126
1182
|
if isinstance(regression_period,list):
|
1127
1183
|
regression_period=regression_period[0]
|
1128
|
-
print(" Starting to retrive and calculate",rar,"for",ticker_name(ticker,ticker_type),"on different RF, please wait
|
1184
|
+
print(" Starting to retrive and calculate",rar,"for",ticker_name(ticker,ticker_type),"on different RF, please wait ......\n")
|
1129
1185
|
|
1130
1186
|
df=pd.DataFrame()
|
1131
1187
|
for t in RF:
|
@@ -1163,7 +1219,7 @@ def compare_1ticker_1rar_1ret_mRF(ticker,start,end,rar='sharpe', \
|
|
1163
1219
|
|
1164
1220
|
footnote3=""
|
1165
1221
|
if rar.lower() in ['treynor','alpha']:
|
1166
|
-
footnote3="
|
1222
|
+
footnote3="贝塔系数回归期间"+str(regression_period)+"个自然日"
|
1167
1223
|
|
1168
1224
|
import datetime; todaydt = datetime.date.today()
|
1169
1225
|
footnote4="数据来源: 综合新浪/stooq/Yahoo,"+str(todaydt)+"统计"
|
@@ -1180,7 +1236,10 @@ def compare_1ticker_1rar_1ret_mRF(ticker,start,end,rar='sharpe', \
|
|
1180
1236
|
|
1181
1237
|
draw_lines(df1,y_label,x_label=footnotex, \
|
1182
1238
|
axhline_value=axhline_value,axhline_label=axhline_label, \
|
1183
|
-
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)
|
1184
1243
|
|
1185
1244
|
#制表
|
1186
1245
|
recommenddf=pd.DataFrame()
|
@@ -1196,10 +1255,11 @@ def compare_1ticker_1rar_1ret_mRF(ticker,start,end,rar='sharpe', \
|
|
1196
1255
|
elif sortby=='trailing':
|
1197
1256
|
sortby_txt='按推荐标记+短期均值走势降序排列'
|
1198
1257
|
|
1199
|
-
title_txt='***** 风险调整收益评估:'+'基于'+ectranslate(rar)+','+ticker_name(ticker,ticker_type)+','+sortby_txt+' *****'
|
1258
|
+
#title_txt='***** 风险调整收益评估:'+'基于'+ectranslate(rar)+','+ticker_name(ticker,ticker_type)+','+sortby_txt+' *****'
|
1259
|
+
title_txt='风险调整收益评估:'+'基于'+ectranslate(rar)+','+ticker_name(ticker,ticker_type)+','+sortby_txt
|
1200
1260
|
|
1201
|
-
footnote6='
|
1202
|
-
footnote7="
|
1261
|
+
footnote6='期间为'+str(start)+'至'+str(end)+";近期指近"+str(trailing)+"个交易日。趋势变化率阈值:"+str(trend_threshhold)+"。"
|
1262
|
+
footnote7="近期优先趋势和星号为多项因素综合研判,最多五颗星"
|
1203
1263
|
footnotey=footnote6+footnote7+'\n'+footnotex
|
1204
1264
|
|
1205
1265
|
#删除含有Nan的行
|
@@ -1207,7 +1267,7 @@ def compare_1ticker_1rar_1ret_mRF(ticker,start,end,rar='sharpe', \
|
|
1207
1267
|
|
1208
1268
|
recommenddf=descriptive_statistics2(df1,title_txt,footnotey,decimals=4, \
|
1209
1269
|
sortby=sortby,recommend_only=True,trailing=trailing, \
|
1210
|
-
trend_threshhold=trend_threshhold)
|
1270
|
+
trend_threshhold=trend_threshhold,facecolor=facecolor)
|
1211
1271
|
|
1212
1272
|
return df,recommenddf
|
1213
1273
|
|
@@ -1248,9 +1308,11 @@ def compare_rar_security(ticker,start,end,rar='sharpe', \
|
|
1248
1308
|
ret_type="Annual Ret%", \
|
1249
1309
|
RF=0, \
|
1250
1310
|
regression_period=365, \
|
1251
|
-
graph=True,axhline_value=0,axhline_label='', \
|
1311
|
+
graph=True,axhline_value=0,axhline_label='',facecolor='whitesmoke', \
|
1252
1312
|
printout=False,sortby='tpw_mean',trailing=7,trend_threshhold=0.05, \
|
1253
|
-
annotate=False,
|
1313
|
+
annotate=False,annotate_value=False, \
|
1314
|
+
mark_top=False,mark_bottom=False,mark_end=False, \
|
1315
|
+
mktidx='auto',source='auto', \
|
1254
1316
|
ticker_type='auto'):
|
1255
1317
|
"""
|
1256
1318
|
功能:组合情况,可能多只股票,多个rar,多个收益率类型,多个无风险收益率
|
@@ -1274,11 +1336,15 @@ def compare_rar_security(ticker,start,end,rar='sharpe', \
|
|
1274
1336
|
if rar_num==1: rar=rar[0]
|
1275
1337
|
|
1276
1338
|
if rar_num ==1: #一个RAR
|
1277
|
-
df=compare_mticker_1rar(ticker,start,end,rar, \
|
1278
|
-
ret_type,RF,regression_period, \
|
1279
|
-
graph,axhline_value,axhline_label, \
|
1280
|
-
printout,
|
1281
|
-
|
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)
|
1282
1348
|
return df
|
1283
1349
|
|
1284
1350
|
if rar_num >1: #多个RAR
|
@@ -1286,8 +1352,12 @@ def compare_rar_security(ticker,start,end,rar='sharpe', \
|
|
1286
1352
|
df=compare_mticker_mrar(ticker=ticker,start=start,end=end,rar=rar, \
|
1287
1353
|
ret_type=ret_type,RF=RF,regression_period=regression_period, \
|
1288
1354
|
graph=graph,axhline_value=axhline_value,axhline_label=axhline_label, \
|
1289
|
-
printout=printout,
|
1290
|
-
|
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)
|
1291
1361
|
return df
|
1292
1362
|
else:
|
1293
1363
|
#实际上是单个证券
|
@@ -1301,11 +1371,15 @@ def compare_rar_security(ticker,start,end,rar='sharpe', \
|
|
1301
1371
|
if isinstance(RF,list):
|
1302
1372
|
RF=RF[0]
|
1303
1373
|
|
1304
|
-
df=compare_1ticker_mrar(ticker,start,end,rar, \
|
1305
|
-
ret_type,RF,regression_period, \
|
1306
|
-
graph,axhline_value,axhline_label, \
|
1307
|
-
printout,
|
1308
|
-
|
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)
|
1309
1383
|
return df
|
1310
1384
|
else:
|
1311
1385
|
#实际上是单个RAR
|
@@ -1317,11 +1391,15 @@ def compare_rar_security(ticker,start,end,rar='sharpe', \
|
|
1317
1391
|
if isinstance(RF,list):
|
1318
1392
|
RF=RF[0]
|
1319
1393
|
|
1320
|
-
df=compare_1ticker_1rar_mret(ticker,start,end,rar, \
|
1321
|
-
ret_type,RF,regression_period, \
|
1322
|
-
graph,axhline_value,axhline_label, \
|
1323
|
-
printout,
|
1324
|
-
|
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)
|
1325
1403
|
return df
|
1326
1404
|
else:
|
1327
1405
|
#实际上是单个收益率类型
|
@@ -1331,24 +1409,30 @@ def compare_rar_security(ticker,start,end,rar='sharpe', \
|
|
1331
1409
|
if isinstance(RF,list):
|
1332
1410
|
if len(RF) > 1:
|
1333
1411
|
|
1334
|
-
df=compare_1ticker_1rar_1ret_mRF(ticker,start,end,rar, \
|
1335
|
-
ret_type, \
|
1336
|
-
|
1337
|
-
|
1338
|
-
|
1339
|
-
|
1340
|
-
|
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)
|
1341
1421
|
return df
|
1342
1422
|
else:
|
1343
1423
|
#实际上是单个RF
|
1344
1424
|
RF=RF[0]
|
1345
1425
|
|
1346
1426
|
#情形5:1只证券,1个RAR,1个收益率类型,1个RF
|
1347
|
-
df=compare_1ticker_mrar(ticker,start,end,rar, \
|
1348
|
-
ret_type,RF,regression_period, \
|
1349
|
-
graph,axhline_value,axhline_label, \
|
1350
|
-
printout,sortby,
|
1351
|
-
|
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
|
+
|
1352
1436
|
return df
|
1353
1437
|
|
1354
1438
|
|