siat 3.8.10__py3-none-any.whl → 3.8.25__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/economy2.py CHANGED
@@ -170,25 +170,29 @@ if __name__ =="__main__":
170
170
 
171
171
  indicator_name_wb(indicator)
172
172
 
173
- def indicator_name_wb(indicator='NY.GDP.MKTP.KN'):
173
+ def indicator_name_wb(indicator):
174
174
  """
175
175
  ===========================================================================
176
176
  功能:抓取World Bank网页上指标的名称
177
- indicator:WB指标名称,默认'NY.GDP.MKTP.KN'
177
+ indicator:WB指标名称,例如'NY.GDP.MKTP.KN'
178
178
  """
179
+ # 优先查询本地词典
180
+ indicator_name=economic_translate(indicator)
179
181
 
180
- # 构造 API 请求 URL
181
- url = f"https://api.worldbank.org/v2/indicator/{indicator}?format=json"
182
-
183
- # 发送请求
184
- response = requests.get(url)
185
- data = response.json()
186
-
187
- # 提取指标名称
188
- try:
189
- indicator_name = data[1][0]['name']
190
- except:
191
- indicator_name = ''
182
+ # 查询WB网页
183
+ if indicator_name == indicator:
184
+ # 构造 API 请求 URL
185
+ url = f"https://api.worldbank.org/v2/indicator/{indicator}?format=json"
186
+
187
+ # 发送请求
188
+ response = requests.get(url)
189
+ data = response.json()
190
+
191
+ # 提取指标名称
192
+ try:
193
+ indicator_name = data[1][0]['name']
194
+ except:
195
+ indicator_name = indicator
192
196
 
193
197
  return indicator_name
194
198
 
@@ -291,8 +295,8 @@ def economy_indicator_wb(ticker='CN',indicator='NY.GDP.MKTP.KN', \
291
295
  """
292
296
  # 检测指标是否存在,并取得指标名称
293
297
  indicator_name=indicator_name_wb(indicator)
294
- if indicator_name == '':
295
- print(f" #Error(economy_indicator_wb): no indicator found for {indicator}")
298
+ if indicator_name == indicator:
299
+ print(f" #Error(economy_indicator_wb): indicator {indicator} not found")
296
300
  return None
297
301
 
298
302
  # 日期具体化
@@ -302,20 +306,20 @@ def economy_indicator_wb(ticker='CN',indicator='NY.GDP.MKTP.KN', \
302
306
  try:
303
307
  pricedf=wb.download(indicator=indicator,country=ticker,start=start,end=end)
304
308
  except:
305
- print(f" #Error(economy_indicator_wb): either {indicator} deprecated or {ticker} does not exist")
309
+ print(f" #Error(economy_indicator_wb): {indicator} deprecated or {ticker} not found")
306
310
  return None
307
311
 
308
312
  # 是否返回None
309
313
  if pricedf is None:
310
- print(f" #Error(economy_indicator_wb): no data found on {indicator} for {ticker}")
314
+ print(f" #Error(economy_indicator_wb): no data found on {indicator} in {ticker}")
311
315
  return None
312
316
  # 是否返回空的数据表
313
317
  if len(pricedf) == 0:
314
- print(f" #Error(economy_indicator_wb): zero data found on {indicator} for {ticker}")
318
+ print(f" #Error(economy_indicator_wb): zero data found on {indicator} in {ticker}")
315
319
  return None
316
320
  # 是否返回数据表但内容均为NaN
317
321
  if pricedf[indicator].isnull().all():
318
- print(f" #Error(economy_indicator_wb): all empty data found on {indicator} for {ticker}")
322
+ print(f" #Error(economy_indicator_wb): empty data found on {indicator} in {ticker}")
319
323
  return None
320
324
 
321
325
  pricedf.reset_index(inplace=True)
@@ -360,8 +364,8 @@ def economy_indicator_wb(ticker='CN',indicator='NY.GDP.MKTP.KN', \
360
364
  if ind_max * ind_min <0:
361
365
  zeroline=True
362
366
 
363
- titletxt1=text_lang("经济趋势分析","Economic Trend Analysis")
364
- titletxt=titletxt1+': '+country+', '+indicator_name
367
+ titletxt1=text_lang("经济分析","Economic Analysis")
368
+ titletxt=titletxt1+': '+country_translate(country)+', '+indicator_name
365
369
  if unit != '':
366
370
  titletxt=titletxt+', '+unit
367
371
 
@@ -530,7 +534,7 @@ def economy_mindicators_wb(ticker='CN',indicator=['NY.GDP.MKTP.CN','NY.GDP.MKTP.
530
534
  return None
531
535
 
532
536
  # 绘图
533
- titletxt=text_lang("经济趋势分析","Economic Trend Analysis")+': '+country
537
+ titletxt=text_lang("经济趋势分析","Economic Trend Analysis")+': '+country_translate(country)
534
538
 
535
539
  y_label=text_lang('经济指标',"Economic Indicator")
536
540
  import datetime; todaydt = datetime.date.today()
@@ -573,6 +577,10 @@ def economy_mindicators_wb(ticker='CN',indicator=['NY.GDP.MKTP.CN','NY.GDP.MKTP.
573
577
 
574
578
  # 为避免绘图出错,对空值进行插值
575
579
  df.interpolate(method='linear',limit_direction='both',inplace=True)
580
+
581
+ # 翻译指标名称
582
+ for c in list(df):
583
+ df.rename(columns={c:economic_translate(c)},inplace=True)
576
584
 
577
585
  draw_lines2(df,y_label,x_label,axhline_value,axhline_label,titletxt, \
578
586
  data_label=False,resample_freq='1D',smooth=smooth, \
@@ -695,15 +703,15 @@ def economy_mtickers_wb(ticker=['CN','US','JP'],indicator='NY.GDP.MKTP.PP.CD', \
695
703
  dfs=pd.DataFrame(); have_data=False
696
704
  country_list=[]; unit_list=[]
697
705
  for t in tickers:
698
- print(f" Looking indicator info for {t} ... ...")
706
+ print(f" Looking for {measure} info in {t} ... ...")
699
707
  with HiddenPrints():
700
708
  df_tmp=economy_indicator_wb(ticker=t,indicator=measure, \
701
709
  start=start,end=end,graph=False)
702
710
  if df_tmp is None:
703
- print(f" #Warning(economy_mticker_wb): indicator info not found for {t}")
711
+ print(f" #Warning(economy_mticker_wb): {measure} info not found in {t}")
704
712
  continue
705
713
  if len(df_tmp)==0:
706
- print(f" #Warning(economy_mticker_wb): zero info found for {t} between {start} and {end}")
714
+ print(f" #Warning(economy_mticker_wb): zero info found for {measure} in {t}")
707
715
  continue
708
716
 
709
717
  have_data=True
@@ -714,7 +722,10 @@ def economy_mtickers_wb(ticker=['CN','US','JP'],indicator='NY.GDP.MKTP.PP.CD', \
714
722
  unit_list=unit_list+[unit]
715
723
  df_tmp.drop(columns=['country','unit'],inplace=True)
716
724
  indicator_name=list(df_tmp)[0]
717
-
725
+
726
+ if DEBUG:
727
+ print(f"DEBUG: t={t}, band_area={band_area}, df_tmp={list(df_tmp)}")
728
+
718
729
  if t in band_area:
719
730
  band_area = [country if x == t else x for x in band_area]
720
731
 
@@ -724,12 +735,15 @@ def economy_mtickers_wb(ticker=['CN','US','JP'],indicator='NY.GDP.MKTP.PP.CD', \
724
735
  dfs=df_tmp
725
736
  else:
726
737
  dfs=pd.concat([dfs,df_tmp],axis=1,join='outer')
727
-
738
+
739
+ # 翻译band_area
740
+ band_area=[country_translate(x) for x in band_area]
741
+
728
742
  if dfs is None:
729
743
  print(f" #Error(economy_mticker_wb): no records found for {measure}")
730
744
  return None
731
745
  if len(dfs)==0:
732
- print(" #Error(economy_mticker_wb): zero records found for {measure}")
746
+ print(f" #Error(economy_mticker_wb): zero records found for {measure}")
733
747
  return None
734
748
 
735
749
  # 若不绘图则返回原始数据
@@ -740,11 +754,12 @@ def economy_mtickers_wb(ticker=['CN','US','JP'],indicator='NY.GDP.MKTP.PP.CD', \
740
754
  return None
741
755
 
742
756
  # 绘图
743
- titletxt=text_lang("经济趋势分析","Economic Trend Analysis")+': '+indicator_name
744
- y_label=indicator_name
757
+ titletxt=text_lang("经济分析","Economic Analysis")+': '+indicator_name
758
+ #y_label=indicator_name
759
+ y_label=text_lang("经济指标","Economic Indicator")
745
760
 
746
761
  import datetime; todaydt = datetime.date.today()
747
- footnote2=text_lang("数据来源:WB/IMF/FRED","Data source: World Bank")+', '+str(todaydt)
762
+ footnote2=text_lang("数据来源:WB/IMF/FRED","Data source: WB/IMF/FRED")+', '+str(todaydt)
748
763
 
749
764
  one_unit=False
750
765
  if len(set(unit_list)) == 1: one_unit=True
@@ -801,6 +816,10 @@ def economy_mtickers_wb(ticker=['CN','US','JP'],indicator='NY.GDP.MKTP.PP.CD', \
801
816
  if axhline_label=='':
802
817
  axhline_label='零线'
803
818
 
819
+ # 翻译国家名称
820
+ for c in list(dfs2):
821
+ dfs2.rename(columns={c:country_translate(c)},inplace=True)
822
+
804
823
  draw_lines(dfs2,y_label,x_label,axhline_value,axhline_label,titletxt, \
805
824
  data_label=False,resample_freq='D',smooth=smooth,linewidth=linewidth, \
806
825
  band_area=band_area,loc=loc, \
@@ -973,5 +992,210 @@ def economy_trend2(ticker='CN',indicator='NY.GDP.MKTP.KN', \
973
992
  #==============================================================================
974
993
  #==============================================================================
975
994
  #==============================================================================
995
+
996
+
997
+ def economic_translate(indicator):
998
+ """
999
+ ===========================================================================
1000
+ 功能:翻译宏观经济指标术语
1001
+ 参数:
1002
+ indicator: 指标编码,主要是世界银行编码。
1003
+ 注意:部分编码已放弃,可能无数据或无最新数据。
1004
+ 返回值:是否找到,基于语言环境为中文或英文解释。
1005
+ 语言环境判断为check_language()
1006
+
1007
+ 数据结构:['指标编码','中文解释','英文解释']
1008
+ """
1009
+ DEBUG=False
1010
+
1011
+ import pandas as pd
1012
+ trans_dict=pd.DataFrame([
1013
+
1014
+ # NE.CON.PRVT:家庭及NPISH最终消费=======================================
1015
+ ['NE.CON.PRVT.CD','家庭及NPISH最终消费(美元时价)',
1016
+ 'Household & NPISHs Final Consumption (current US$)',
1017
+ 'Households and NPISHs Final consumption expenditure (current US$)'],
1018
+
1019
+ ['NE.CON.PRVT.KD','家庭及NPISH最终消费(2015美元不变价格)',
1020
+ 'Household & NPISHs Final Consumption (constant 2015 US$)',
1021
+ 'Households and NPISHs Final consumption expenditure (constant 2015 US$)'],
1022
+
1023
+ ['NE.CON.PRVT.CN','家庭及NPISH最终消费(本币时价)',
1024
+ 'Household & NPISHs Final Consumption (current LCU)',
1025
+ 'Households and NPISHs Final consumption expenditure (current LCU)'],
1026
+
1027
+ ['NE.CON.PRVT.KN','家庭及NPISH最终消费(本币不变价格)',
1028
+ 'Household & NPISHs Final Consumption (constant LCU)',
1029
+ 'Households and NPISHs Final consumption expenditure (constant LCU)'],
1030
+
1031
+ ['NE.CON.PRVT.ZS','家庭及NPISH最终消费(占GDP%)',
1032
+ 'Household & NPISHs Final Consumption (GDP%)',
1033
+ 'Households and NPISHs Final consumption expenditure (% of GDP)'],
1034
+
1035
+ ['NE.CON.PRVT.KD.ZG','家庭及NPISH最终消费(年增速%)',
1036
+ 'Household & NPISHs Final Consumption (annual % growth)',
1037
+ 'Households and NPISHs Final consumption expenditure (annual % growth)'],
1038
+
1039
+ ['NE.CON.PRVT.PP.CD','家庭及NPISH最终消费(购买力平价,国际美元时价)',
1040
+ 'Household & NPISHs Final Consumption (PPP, current intl $)',
1041
+ 'Households and NPISHs Final consumption expenditure, PPP (current international $)'],
1042
+
1043
+ ['NE.CON.PRVT.PP.KD','家庭及NPISH最终消费(购买力平价,2021国际美元不变价格)',
1044
+ 'Household & NPISHs Final Consumption (PPP, constant 2021 intl $)',
1045
+ 'Households and NPISHs Final consumption expenditure, PPP (constant 2021 international $)'],
1046
+
1047
+ ['NE.CON.PRVT.PC.KD.ZG','人均家庭及NPISH最终消费(年增速%)',
1048
+ 'Household & NPISHs Final Consumption per capita growth (annual %)',
1049
+ 'Households and NPISHs Final consumption expenditure per capita growth (annual %)'],
1050
+
1051
+ ['NE.CON.PRVT.PC.KD','人均家庭及NPISH最终消费(2015美元不变价格)',
1052
+ 'Household & NPISHs Final Consumption per capita (constant 2015 US$)',
1053
+ 'Households and NPISHs Final consumption expenditure per capita (constant 2015 US$)'],
1054
+
1055
+ ['NE.CON.PRVT.CN.AD','家庭及NPISH最终消费(统计口径调整后,本币时价)',
1056
+ 'Household & NPISHs Final Consumption (linked series, current LCU)',
1057
+ 'Households and NPISHs Final consumption expenditure: linked series (current LCU)'],
1058
+
1059
+ # 币种指标:CD=current US$, KD=constant 2015 US$, CN=current LCU
1060
+ # KN=constant LCU, ZS=% of GDP, PC=per capita, PP=PPP
1061
+
1062
+
1063
+
1064
+
1065
+
1066
+
1067
+ ], columns=['indicator','cword','eword','original_eword'])
1068
+
1069
+ found=False; result=indicator
1070
+ try:
1071
+ dict_word=trans_dict[trans_dict['indicator']==indicator]
1072
+ found=True
1073
+ except:
1074
+ #未查到翻译词汇,返回原词
1075
+ pass
1076
+
1077
+ if dict_word is None:
1078
+ found=False
1079
+ elif len(dict_word) == 0:
1080
+ found=False
1081
+
1082
+ if found:
1083
+ lang=check_language()
1084
+
1085
+ if DEBUG:
1086
+ print(f"DEBUG: indicator={indicator}, lang={lang}, dict_word={dict_word}")
1087
+
1088
+ if lang == 'Chinese':
1089
+ result=dict_word['cword'].values[0]
1090
+ else:
1091
+ result=dict_word['eword'].values[0]
1092
+
1093
+ return result
1094
+
1095
+ if __name__=='__main__':
1096
+ indicator='NE.CON.PRVT.CD'
1097
+ indicator='NE.CON.PRVT.KD'
1098
+
1099
+ indicator='NE.CON.PRVT.CN'
1100
+ indicator='NE.CON.PRVT.KN'
1101
+
1102
+ result=economic_translate(indicator)
1103
+ economic_translate(indicator)[1]
1104
+
1105
+ #==============================================================================
1106
+
1107
+
1108
+ def country_translate(country):
1109
+ """
1110
+ ===========================================================================
1111
+ 功能:翻译国家名称
1112
+ 参数:
1113
+ country: 国家名称英文,并非国家代码。
1114
+ 返回值:是否找到,基于语言环境为中文或英文解释。
1115
+ 语言环境判断为check_language()
1116
+
1117
+ 数据结构:['国家名称英文','国家名称中文','国家代码2位','国家代码3位']
1118
+ """
1119
+
1120
+ import pandas as pd
1121
+ trans_dict=pd.DataFrame([
1122
+
1123
+ ['China','中国','CN','CHN'],
1124
+ ['United States','美国','US','USA'],
1125
+ ['Japan','日本','JP','JPN'],
1126
+ ['Germany','德国','DE','DEU'],
1127
+ ['India','印度','IN','IND'],
1128
+ ['Brazil','巴西','BR','BRA'],
1129
+
1130
+ ['France','法国','FR','FRA'],
1131
+ ['United Kingdom','英国','GB','GBR'],
1132
+ ['Russia','俄罗斯','RU','RUS'],
1133
+ ['Canada','加拿大','CA','CAN'],
1134
+ ['Australia','澳大利亚','AU','AUS'],
1135
+ ['South Korea','韩国','KR','KOR'],
1136
+
1137
+ ['Italy','意大利','IT','ITA'],
1138
+ ['Mexico','墨西哥','MX','MEX'],
1139
+ ['South Africa','南非','ZA','ZAF'],
1140
+ ['Saudi Arabia','沙特阿拉伯','SA','SAU'],
1141
+ ['Indonesia','印度尼西亚','ID','IDN'],
1142
+ ['Turkey','土耳其','TR','TUR'],
1143
+
1144
+ ['Argentina','阿根廷','AR','ARG'],
1145
+ ['Egypt','埃及','EG','EGY'],
1146
+ ['European Union','欧盟','EU','EUU'],
1147
+ ['Hong Kong','中国香港','HK','HKG'],
1148
+ ['Hong Kong, China','中国香港','HK','HKG'],
1149
+ ['Taiwan','中国台湾','TW','TWN'],
1150
+ ['Taiwan, China','中国台湾','TW','TWN'],
1151
+ ['World','全球','1W','WLD'],
1152
+
1153
+ ['Singapore','新加坡','SG','SGP'],
1154
+ ['Malaysia','马来西亚','MY','MYS'],
1155
+ ['Thailand','泰国','TH','THA'],
1156
+ ['Israel','以色列','IL','ISR'],
1157
+ ['Vietnam','越南','VN','VNM'],
1158
+ ['Philippines','菲律宾','PH','PHL'],
1159
+ ['Brunei','文莱','BN','BRN'],
1160
+ ['Cambodia','柬埔寨','KH','KHM'],
1161
+
1162
+ ['Laos','老挝','LA','LAO'],
1163
+ ['Myanmar','缅甸','MM','MMR'],
1164
+
1165
+
1166
+
1167
+
1168
+
1169
+ ], columns=['ecountry','ccountry','country code2','country code3'])
1170
+
1171
+ found=False; result=country
1172
+ try:
1173
+ dict_word=trans_dict[trans_dict['ecountry']==country]
1174
+ found=True
1175
+ except:
1176
+ #未查到翻译词汇,返回原词
1177
+ pass
1178
+
1179
+ if dict_word is None:
1180
+ found=False
1181
+ elif len(dict_word) == 0:
1182
+ found=False
1183
+
1184
+ if found:
1185
+ lang=check_language()
1186
+ if lang == 'Chinese':
1187
+ result=dict_word['ccountry'].values[0]
1188
+ else:
1189
+ #result=dict_word['ecountry'].values[0]
1190
+ pass
1191
+
1192
+ return result
1193
+
1194
+ if __name__=='__main__':
1195
+ country='China'
1196
+ country='United States'
1197
+
1198
+ result=country_translate(country)
1199
+
976
1200
  #==============================================================================
977
1201
 
@@ -811,6 +811,7 @@ def compare_1ticker_mrar(ticker,start,end,rar=['sharpe','sortino','treynor','alp
811
811
  ret_type="Annual Adj Ret%",RF=0,regression_period=365, \
812
812
  attention_value='',attention_value_area='', \
813
813
  attention_point='',attention_point_area='', \
814
+ band_area='', \
814
815
  graph=True,loc1='best', \
815
816
  axhline_value=0,axhline_label='',facecolor='whitesmoke', \
816
817
  printout=False,sortby='tpw_mean',trailing=7,trend_threshhold=0.01, \
@@ -843,7 +844,7 @@ def compare_1ticker_mrar(ticker,start,end,rar=['sharpe','sortino','treynor','alp
843
844
  regression_period=regression_period[0]
844
845
 
845
846
  tname=ticker_name(ticker,ticker_type)
846
- print(" Starting to retrieve and calculate different rar for",tname,"\b, please wait ......\n")
847
+ print(" Working on different rars for",tname,"\b, please wait ......\n")
847
848
 
848
849
  #预处理ticker_type
849
850
  ticker_type=ticker_type_preprocess_mticker_mixed(ticker,ticker_type)
@@ -876,7 +877,14 @@ def compare_1ticker_mrar(ticker,start,end,rar=['sharpe','sortino','treynor','alp
876
877
  if df1[c].max() > axhline_value and df1[c].min() < axhline_value:
877
878
  axhline_label='零线'
878
879
 
879
- df1.rename(columns={c:ectranslate(c)},inplace=True)
880
+ cname=ectranslate(c)
881
+ df1.rename(columns={c:cname},inplace=True)
882
+
883
+ # 将band_area中的ticker替换为tname
884
+ if band_area != '':
885
+ for index, item in enumerate(band_area):
886
+ if item == c:
887
+ band_area[index] = cname
880
888
 
881
889
  footnote1=text_lang("评估值基于","Note: RaR based on ")+ectranslate(ret_type)
882
890
  if RF !=0:
@@ -914,6 +922,7 @@ def compare_1ticker_mrar(ticker,start,end,rar=['sharpe','sortino','treynor','alp
914
922
  attention_value=attention_value,attention_value_area=attention_value_area, \
915
923
  attention_point=attention_point,attention_point_area=attention_point_area, \
916
924
  annotate=annotate,annotate_value=annotate, \
925
+ band_area=band_area, \
917
926
  mark_top=mark_top,mark_bottom=mark_bottom,mark_end=mark_end, \
918
927
  facecolor=facecolor,loc=loc1)
919
928
 
@@ -974,6 +983,7 @@ def compare_mticker_1rar(ticker,start,end,rar='sharpe', \
974
983
  ret_type="Annual Adj Ret%",RF=0,regression_period=365, \
975
984
  attention_value='',attention_value_area='', \
976
985
  attention_point='',attention_point_area='', \
986
+ band_area='', \
977
987
  graph=True,loc1='best', \
978
988
  axhline_value=0,axhline_label='', \
979
989
  printout=False,sortby='tpw_mean',trailing=7,trend_threshhold=0.01, \
@@ -1006,7 +1016,7 @@ def compare_mticker_1rar(ticker,start,end,rar='sharpe', \
1006
1016
  RF=RF[0]
1007
1017
  if isinstance(regression_period,list):
1008
1018
  regression_period=regression_period[0]
1009
- print(" Starting to retrieve and calculate",rar,"\b, please wait ......\n")
1019
+ print(" Working on",rar,"ratio, please wait ......\n")
1010
1020
 
1011
1021
  #预处理ticker_type
1012
1022
  ticker_type_list=ticker_type_preprocess_mticker_mixed(ticker,ticker_type)
@@ -1027,7 +1037,14 @@ def compare_mticker_1rar(ticker,start,end,rar='sharpe', \
1027
1037
  continue
1028
1038
  else:
1029
1039
  dft=df_tmp[[rar]]
1030
- dft.rename(columns={rar:ticker_name(t,tt)},inplace=True)
1040
+ tname=ticker_name(t,tt)
1041
+ dft.rename(columns={rar:tname},inplace=True)
1042
+
1043
+ # 将band_area中的ticker替换为tname
1044
+ if band_area != '':
1045
+ for index, item in enumerate(band_area):
1046
+ if item == t:
1047
+ band_area[index] = tname
1031
1048
 
1032
1049
  if len(df)==0: #第一个
1033
1050
  df=dft
@@ -1097,6 +1114,7 @@ def compare_mticker_1rar(ticker,start,end,rar='sharpe', \
1097
1114
  title_txt=title_txt,data_label=False, \
1098
1115
  attention_value=attention_value,attention_value_area=attention_value_area, \
1099
1116
  attention_point=attention_point,attention_point_area=attention_point_area, \
1117
+ band_area=band_area, \
1100
1118
  annotate=annotate,annotate_value=annotate, \
1101
1119
  mark_top=mark_top,mark_bottom=mark_bottom,mark_end=mark_end, \
1102
1120
  facecolor=facecolor,loc=loc1)
@@ -1154,6 +1172,7 @@ def compare_mticker_mrar(ticker,start,end,rar=['sharpe','alpha','sortino','treyn
1154
1172
  ret_type="Annual Adj Ret%",RF=0,regression_period=365, \
1155
1173
  attention_value='',attention_value_area='', \
1156
1174
  attention_point='',attention_point_area='', \
1175
+ band_area='', \
1157
1176
  graph=True,loc1='best', \
1158
1177
  axhline_value=0,axhline_label='', \
1159
1178
  printout=True,sortby='tpw_mean',trailing=7,trend_threshhold=0.01, \
@@ -1184,6 +1203,7 @@ def compare_mticker_mrar(ticker,start,end,rar=['sharpe','alpha','sortino','treyn
1184
1203
  ret_type=ret_type,RF=RF,regression_period=regression_period, \
1185
1204
  attention_value=attention_value,attention_value_area=attention_value_area, \
1186
1205
  attention_point=attention_point,attention_point_area=attention_point_area, \
1206
+ band_area=band_area, \
1187
1207
  graph=graph,facecolor=facecolor, \
1188
1208
  axhline_value=axhline_value,axhline_label=axhline_label, \
1189
1209
  printout=printout,sortby=sortby, \
@@ -1361,6 +1381,7 @@ def compare_1ticker_1rar_mret(ticker,start,end,rar='sharpe', \
1361
1381
  RF=0,regression_period=365, \
1362
1382
  attention_value='',attention_value_area='', \
1363
1383
  attention_point='',attention_point_area='', \
1384
+ band_area='', \
1364
1385
  graph=True,loc1='best', \
1365
1386
  axhline_value=0,axhline_label='',facecolor='whitesmoke', \
1366
1387
  printout=False,sortby='tpw_mean',trailing=7,trend_threshhold=0.01, \
@@ -1392,7 +1413,7 @@ def compare_1ticker_1rar_mret(ticker,start,end,rar='sharpe', \
1392
1413
  RF=RF[0]
1393
1414
  if isinstance(regression_period,list):
1394
1415
  regression_period=regression_period[0]
1395
- print(" Working on",rar,"for",ticker_name(ticker,ticker_type),"in different returns, please wait ......\n")
1416
+ print(" Working on",rar,"ratio for",ticker_name(ticker,ticker_type),"in different return types ......\n")
1396
1417
 
1397
1418
  df=pd.DataFrame()
1398
1419
  for t in ret_type:
@@ -1406,8 +1427,15 @@ def compare_1ticker_1rar_mret(ticker,start,end,rar='sharpe', \
1406
1427
  break
1407
1428
  else:
1408
1429
  dft=df_tmp[[rar]]
1430
+ tname=text_lang("基于","Based on ")+ectranslate(t)
1409
1431
  dft.rename(columns={rar:text_lang("基于","Based on ")+ectranslate(t)},inplace=True)
1410
1432
 
1433
+ # 将band_area中的ticker替换为tname
1434
+ if band_area != '':
1435
+ for index, item in enumerate(band_area):
1436
+ if item == t:
1437
+ band_area[index] = tname
1438
+
1411
1439
  if len(df)==0: #第一个
1412
1440
  df=dft
1413
1441
  else:
@@ -1457,6 +1485,7 @@ def compare_1ticker_1rar_mret(ticker,start,end,rar='sharpe', \
1457
1485
  attention_value=attention_value,attention_value_area=attention_value_area, \
1458
1486
  attention_point=attention_point,attention_point_area=attention_point_area, \
1459
1487
  annotate=annotate,annotate_value=annotate, \
1488
+ band_area=band_area, \
1460
1489
  mark_top=mark_top,mark_bottom=mark_bottom,mark_end=mark_end, \
1461
1490
  facecolor=facecolor,loc=loc1)
1462
1491
 
@@ -1514,6 +1543,7 @@ def compare_1ticker_1rar_1ret_mRF(ticker,start,end,rar='sharpe', \
1514
1543
  ret_type="Annual Adj Ret%",RF=[0,0.02,0.05],regression_period=365, \
1515
1544
  attention_value='',attention_value_area='', \
1516
1545
  attention_point='',attention_point_area='', \
1546
+ band_area='', \
1517
1547
  graph=True,loc1='best', \
1518
1548
  axhline_value=0,axhline_label='',facecolor='whitesmoke', \
1519
1549
  printout=False,sortby='tpw_mean',trailing=7,trend_threshhold=0.01, \
@@ -1546,7 +1576,7 @@ def compare_1ticker_1rar_1ret_mRF(ticker,start,end,rar='sharpe', \
1546
1576
  RF=[RF]
1547
1577
  if isinstance(regression_period,list):
1548
1578
  regression_period=regression_period[0]
1549
- print(" Starting to retrieve and calculate",rar,"for",ticker_name(ticker,ticker_type),"on different RF, please wait ......\n")
1579
+ print(" Working on",rar,"ratio for",ticker_name(ticker,ticker_type),"in different RF levels ......\n")
1550
1580
 
1551
1581
  df=pd.DataFrame()
1552
1582
  for t in RF:
@@ -1560,7 +1590,14 @@ def compare_1ticker_1rar_1ret_mRF(ticker,start,end,rar='sharpe', \
1560
1590
  break
1561
1591
  else:
1562
1592
  dft=df_tmp[[rar]]
1563
- dft.rename(columns={rar:text_lang("基于无风险利率","Based on RF=")+str(round(t*100,4))+'%'},inplace=True)
1593
+ tname=text_lang("RF=","RF=")+str(round(t*100,4))+'%'
1594
+ dft.rename(columns={rar:tname},inplace=True)
1595
+
1596
+ # 将band_area中的ticker替换为tname
1597
+ if band_area != '':
1598
+ for index, item in enumerate(band_area):
1599
+ if item == t:
1600
+ band_area[index] = tname
1564
1601
 
1565
1602
  if len(df)==0: #第一个
1566
1603
  df=dft
@@ -1605,6 +1642,7 @@ def compare_1ticker_1rar_1ret_mRF(ticker,start,end,rar='sharpe', \
1605
1642
  attention_value=attention_value,attention_value_area=attention_value_area, \
1606
1643
  attention_point=attention_point,attention_point_area=attention_point_area, \
1607
1644
  annotate=annotate,annotate_value=annotate, \
1645
+ band_area=band_area, \
1608
1646
  mark_top=mark_top,mark_bottom=mark_bottom,mark_end=mark_end, \
1609
1647
  facecolor=facecolor,loc=loc1)
1610
1648
 
@@ -1679,6 +1717,7 @@ def compare_rar_security(ticker,start,end,rar='sharpe', \
1679
1717
  regression_period=365, \
1680
1718
  attention_value='',attention_value_area='', \
1681
1719
  attention_point='',attention_point_area='', \
1720
+ band_area='', \
1682
1721
  graph=True,loc1='best', \
1683
1722
  axhline_value=0,axhline_label='',facecolor='whitesmoke', \
1684
1723
  printout=False,sortby='tpw_mean',trailing=7,trend_threshhold=0.05, \
@@ -1712,6 +1751,7 @@ def compare_rar_security(ticker,start,end,rar='sharpe', \
1712
1751
  ret_type=ret_type,RF=RF,regression_period=regression_period, \
1713
1752
  attention_value=attention_value,attention_value_area=attention_value_area, \
1714
1753
  attention_point=attention_point,attention_point_area=attention_point_area, \
1754
+ band_area=band_area, \
1715
1755
  graph=graph,loc1=loc1, \
1716
1756
  axhline_value=axhline_value,axhline_label=axhline_label, \
1717
1757
  printout=printout, \
@@ -1722,12 +1762,13 @@ def compare_rar_security(ticker,start,end,rar='sharpe', \
1722
1762
  ticker_type=ticker_type,facecolor=facecolor)
1723
1763
  return df
1724
1764
 
1725
- if rar_num >1: #多个RAR
1765
+ if rar_num >1: #多个RAR,此项的主要意图并非绘图,而是进行多指标综合推荐
1726
1766
  printout=True #否则无法运行descriptive_statistics2函数
1727
1767
  df=compare_mticker_mrar(ticker=ticker,start=start,end=end,rar=rar, \
1728
1768
  ret_type=ret_type,RF=RF,regression_period=regression_period, \
1729
1769
  attention_value=attention_value,attention_value_area=attention_value_area, \
1730
1770
  attention_point=attention_point,attention_point_area=attention_point_area, \
1771
+ band_area=band_area, \
1731
1772
  graph=graph,loc1=loc1, \
1732
1773
  axhline_value=axhline_value,axhline_label=axhline_label, \
1733
1774
  printout=printout, \
@@ -1753,6 +1794,7 @@ def compare_rar_security(ticker,start,end,rar='sharpe', \
1753
1794
  ret_type=ret_type,RF=RF,regression_period=regression_period, \
1754
1795
  attention_value=attention_value,attention_value_area=attention_value_area, \
1755
1796
  attention_point=attention_point,attention_point_area=attention_point_area, \
1797
+ band_area=band_area, \
1756
1798
  graph=graph,loc1=loc1, \
1757
1799
  axhline_value=axhline_value,axhline_label=axhline_label, \
1758
1800
  printout=printout,facecolor=facecolor, \
@@ -1776,6 +1818,7 @@ def compare_rar_security(ticker,start,end,rar='sharpe', \
1776
1818
  ret_type=ret_type,RF=RF,regression_period=regression_period, \
1777
1819
  attention_value=attention_value,attention_value_area=attention_value_area, \
1778
1820
  attention_point=attention_point,attention_point_area=attention_point_area, \
1821
+ band_area=band_area, \
1779
1822
  graph=graph,loc1=loc1, \
1780
1823
  axhline_value=axhline_value,axhline_label=axhline_label, \
1781
1824
  printout=printout, \
@@ -1797,6 +1840,7 @@ def compare_rar_security(ticker,start,end,rar='sharpe', \
1797
1840
  ret_type=ret_type,RF=RF,regression_period=regression_period, \
1798
1841
  attention_value=attention_value,attention_value_area=attention_value_area, \
1799
1842
  attention_point=attention_point,attention_point_area=attention_point_area, \
1843
+ band_area=band_area, \
1800
1844
  graph=graph,loc1=loc1, \
1801
1845
  axhline_value=axhline_value,axhline_label=axhline_label, \
1802
1846
  printout=printout,facecolor=facecolor, \
siat/security_trend2.py CHANGED
@@ -546,6 +546,7 @@ def security_trend(ticker,indicator='Close',adjust='', \
546
546
  ret_type=ret_type,RF=RF,regression_period=regression_period, \
547
547
  attention_value=attention_value,attention_value_area=attention_value_area, \
548
548
  attention_point=attention_point,attention_point_area=attention_point_area, \
549
+ band_area=band_area, \
549
550
  graph=graph,axhline_value=0,axhline_label='', \
550
551
  loc1=loc1, \
551
552
  printout=printout, \
@@ -586,6 +587,7 @@ def security_trend(ticker,indicator='Close',adjust='', \
586
587
  graph=graph,facecolor=facecolor, \
587
588
  attention_value=attention_value,attention_value_area=attention_value_area, \
588
589
  attention_point=attention_point,attention_point_area=attention_point_area, \
590
+ band_area=band_area, \
589
591
  annotate=annotate,annotate_value=annotate_value, \
590
592
  mark_top=mark_top,mark_bottom=mark_bottom,mark_end=mark_end)
591
593
  return df
siat/translate.py CHANGED
@@ -817,7 +817,7 @@ def codetranslate0(code):
817
817
  ['EBAY','易贝'],['eBay','易贝'],['META','元宇宙(脸书)'],['ZM','ZOOM'],
818
818
  ['GOOG','谷歌'],['GOOGL','谷歌'],['TWTR','X(推特)'],
819
819
  ['VIPS','唯品会'],['Vipshop','唯品会'],
820
- ['PDD','拼多多'],['Pinduoduo','拼多多'],
820
+ ['PDD','拼多多美股'],['Pinduoduo','拼多多'],
821
821
  ['BABA','阿里巴巴美股'],['Alibaba','阿里巴巴美股'],
822
822
  ['JD','京东美股'],['MPNGY','美团美股'],
823
823
  ['SINA','新浪网'],['BIDU','百度'],['NTES','网易'],
siat/valuation.py CHANGED
@@ -944,6 +944,7 @@ def security_valuation(tickers,indicators,start,end, \
944
944
  graph=True,facecolor='whitesmoke', \
945
945
  attention_value='',attention_value_area='', \
946
946
  attention_point='',attention_point_area='', \
947
+ band_area='', \
947
948
  annotate=False,annotate_value=False, \
948
949
  mark_top=False,mark_bottom=False,mark_end=False):
949
950
  """
@@ -974,6 +975,28 @@ def security_valuation(tickers,indicators,start,end, \
974
975
  name_num=len(names1)
975
976
  indicator_num=len(indicators1)
976
977
 
978
+
979
+ # 将band_area中的ticker替换为tname
980
+ if band_area != '':
981
+ if name_num > 1:
982
+ # 假定band_area里面的是ticker
983
+ for index, item in enumerate(band_area):
984
+ tname=ticker_name(item)
985
+ if tname in names1:
986
+ band_area[index] = tname
987
+ else:
988
+ band_area.remove(item)
989
+
990
+ if name_num == 1 and indicator_num > 1:
991
+ # 假定band_area里面的是indicator
992
+ for index, item in enumerate(band_area):
993
+ if item not in indicators1:
994
+ band_area.remove(item)
995
+
996
+ if len(band_area) != 2:
997
+ band_area=''
998
+ print(" #Warning(security_valuation): band_area does not match ticker or indicator")
999
+
977
1000
  import datetime
978
1001
  # 绘制一条线+均值/中位数虚线
979
1002
  if name_num * indicator_num == 1:
@@ -1120,6 +1143,7 @@ def security_valuation(tickers,indicators,start,end, \
1120
1143
  title_txt=titletxt,data_label=False, \
1121
1144
  resample_freq='D',loc=loc1, \
1122
1145
  annotate=annotate,annotate_value=annotate_value, \
1146
+ band_area=band_area, \
1123
1147
  plus_sign=plus_sign, \
1124
1148
  facecolor=facecolor, \
1125
1149
  attention_value=attention_value,attention_value_area=attention_value_area, \
@@ -1167,6 +1191,7 @@ def security_valuation(tickers,indicators,start,end, \
1167
1191
  title_txt=titletxt,data_label=False, \
1168
1192
  resample_freq='D',loc=loc1,plus_sign=plus_sign, \
1169
1193
  annotate=annotate,annotate_value=annotate_value, \
1194
+ band_area=band_area, \
1170
1195
  facecolor=facecolor, \
1171
1196
  attention_value=attention_value,attention_value_area=attention_value_area, \
1172
1197
  attention_point=attention_point,attention_point_area=attention_point_area, \
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: siat
3
- Version: 3.8.10
3
+ Version: 3.8.25
4
4
  Summary: Securities Investment Analysis Tools (siat)
5
5
  Home-page: https://pypi.org/project/siat/
6
6
  Author: Prof. WANG Dehong, International Business School, Beijing Foreign Studies University
@@ -30,7 +30,7 @@ siat/cryptocurrency_test.py,sha256=3AikTNJ7j-HwLGLIYEfyXZ3bLVuLeru9mwiwHQi2SdA,2
30
30
  siat/derivative.py,sha256=qV8n09799eqLc26ojR6vN5n_X-xd7rGwdYjgq-wBih8,41483
31
31
  siat/economy-20230125.py,sha256=vxZZlPnLkh7SpGMVEPLwxjt0yYLSVmdZrO-s2NYLyoM,73848
32
32
  siat/economy.py,sha256=BFVQDxOTbuizyumpCgpZIauH6sqnwUXebpqRMmQCzys,84198
33
- siat/economy2.py,sha256=FOVf5WxKnge3dVEV2CEf--CupXhFtlRUc5k5FUMTD-Q,39857
33
+ siat/economy2.py,sha256=paLZWJFa5in5Pl_isyb-7qnT8EUkvLGvg0G3s-eUONE,48275
34
34
  siat/economy_test.py,sha256=6vjNlPz7W125pJb7simCddobSEp3jmLIMvVkLRZ7zW8,13339
35
35
  siat/esg.py,sha256=GMhaonIKtvOK83rhpQUH5aJt2OL3HQBSVfD__Yw-0oo,19040
36
36
  siat/esg_test.py,sha256=Z9m6GUt8O7oHZSEG9aDYpGdvvrv2AiRJdHTiU6jqmZ0,2944
@@ -92,7 +92,7 @@ siat/option_sina_api_test.py,sha256=dn-k_wrQnAaNKHoROvWJEc7lqlU0bwiV2Aa4usWAFGM,
92
92
  siat/proxy_test.py,sha256=erQJrmGs2X46z8Gb1h-7GYQ0rTUcaR8dxHExWoBz2eM,2610
93
93
  siat/quandl_test.py,sha256=EcPoXnLuqzPl5dKyVEZi3j3PJZFpsnU_iNPhLWC9p-A,1552
94
94
  siat/risk_adjusted_return.py,sha256=6F8CpKm-HKO4wfnndri0ew-D3lDAH1fs5O9K5cphoLg,55096
95
- siat/risk_adjusted_return2.py,sha256=59YDzhbvr8PRRzb1Ew_8fuGqV4lEitm6itpk54xEb48,84335
95
+ siat/risk_adjusted_return2.py,sha256=92GXCpJPVVsYpQ-X3WXaADZvCqxsuJXQN5vG5trVX9I,86296
96
96
  siat/risk_adjusted_return_test.py,sha256=m_VHL5AtT74cJv5i7taTeTfnkX48y0AFJk5phawyYWg,3416
97
97
  siat/risk_evaluation.py,sha256=HK6U2G85-AxjSoeARbmTuiCNwTVdPdB9Znfgvslo0Os,76455
98
98
  siat/risk_evaluation_test.py,sha256=YEXM96gKzTfwN4U61AS4Rr1tV7KgUvn4rRC6f3iMw9s,3731
@@ -106,7 +106,7 @@ siat/security_prices.py,sha256=HoCZ7YPrQYZHgKC-LyXFeeBCTfRc3EMMEiEg52SVv2w,10907
106
106
  siat/security_prices_test.py,sha256=OEphoJ87NPKoNow1QA8EU_5MUYrJF-qKoWKNapVfZNI,10779
107
107
  siat/security_trend.py,sha256=o0vpWdrJkmODCP94X-Bvn-w7efHhj9HpUYBHtLl55D0,17240
108
108
  siat/security_trend2-20240620.py,sha256=QVnEcb7AyVbO77jVqfFsJffGXrX8pgJ9xCfoAKmWBPk,24854
109
- siat/security_trend2.py,sha256=Ab4ZQzjD-xIunDAXHfcD6hVlQ2OqgsGPDKAXfrmW0E0,30576
109
+ siat/security_trend2.py,sha256=8-Z-PWaX8fjnyAyfxEp3qXdVllgDpRISOASKEn7Zeoc,30706
110
110
  siat/setup.py,sha256=up65rQGLmTBkhtaMLowjoQXYmIsnycnm4g1SYmeQS6o,1335
111
111
  siat/shenwan index history test.py,sha256=JCVAzOSEldHalhSFa3pqD8JI_8_djPMQOxpkuYU-Esg,1418
112
112
  siat/stock.py,sha256=W3JhjfRwqb9luNydrKyGd97uRmTsZD5FvRdqJ3DynVo,159509
@@ -135,17 +135,17 @@ siat/transaction_test.py,sha256=Z8g1LJCN4-mnUByXMUMoFmN0t105cbmsz2QmvSuIkbU,1858
135
135
  siat/translate-20230125.py,sha256=NPPSXhT38s5t9fzMvl_fvi4ckSB73ThLmZetVI-xGdU,117953
136
136
  siat/translate-20230206.py,sha256=-vtI125WyaJhmPotOpDAmclt_XnYVaWU9ByLWZ6FyYE,118133
137
137
  siat/translate-20230215.py,sha256=TJgtPE3n8IjljmZ4Pefy8dmHoNdFF-1zpML6BhA9FKE,121657
138
- siat/translate.py,sha256=Xg5lq_rwKKrt8Ysz84LhwLu276KYl1-Nfqq84jRfl7w,262241
138
+ siat/translate.py,sha256=t4SM4QWE7mCfY5GWPJ8SSquNRFrPAKHxJbpKsCWnneU,262247
139
139
  siat/translate_20240606.py,sha256=63IyHWEU3Uz9mjwyuAX3fqY4nUMdwh0ICQAgmgPXP7Y,215121
140
140
  siat/translate_241003_keep.py,sha256=un7Fqe1v35MXsja5exZgjmLzrZtt66NARZIGlyFuGGU,218747
141
141
  siat/universal_test.py,sha256=CDAOffW1Rvs-TcNN5giWVvHMlch1w4dp-w5SIV9jXL0,3936
142
- siat/valuation.py,sha256=tSW5jyda3lChqBkdsbBGfdUeh9bCfjo6P93CjLif9eM,50825
142
+ siat/valuation.py,sha256=K7epQC_UtELjRR5cyjJp4gskSyJMxXy-jHIAS0SUEj8,51801
143
143
  siat/valuation_china.py,sha256=CVp1IwIsF3Om0J29RGkyxZLt4n9Ug-ua_RKhLwL9fUQ,69624
144
144
  siat/valuation_market_china_test.py,sha256=gbJ0ioauuo4koTPH6WKUkqcXiQPafnbhU5eKJ6lpdLA,1571
145
145
  siat/var_model_validation.py,sha256=R0caWnuZarrRg9939hxh3vJIIpIyPfvelYmzFNZtPbo,14910
146
146
  siat/yf_name.py,sha256=laNKMTZ9hdenGX3IZ7G0a2RLBKEWtUQJFY9CWuk_fp8,24058
147
- siat-3.8.10.dist-info/LICENSE,sha256=NTEMMROY9_4U1szoKC3N2BLHcDd_o5uTgqdVH8tbApw,1071
148
- siat-3.8.10.dist-info/METADATA,sha256=BjhxGSm9JIlTCe620pBWE36mrdR_5VUznsMLRqzVgvw,8144
149
- siat-3.8.10.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
150
- siat-3.8.10.dist-info/top_level.txt,sha256=r1cVyL7AIKqeAmEJjNR8FMT20OmEzufDstC2gv3NvEY,5
151
- siat-3.8.10.dist-info/RECORD,,
147
+ siat-3.8.25.dist-info/LICENSE,sha256=NTEMMROY9_4U1szoKC3N2BLHcDd_o5uTgqdVH8tbApw,1071
148
+ siat-3.8.25.dist-info/METADATA,sha256=pWsYGwjmUvMD1r3g1lU0Ijl4V_Pif_RRtuBGhrcLw3A,8144
149
+ siat-3.8.25.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
150
+ siat-3.8.25.dist-info/top_level.txt,sha256=r1cVyL7AIKqeAmEJjNR8FMT20OmEzufDstC2gv3NvEY,5
151
+ siat-3.8.25.dist-info/RECORD,,
File without changes
File without changes