siat 3.8.48__py3-none-any.whl → 3.9.10__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 CHANGED
@@ -93,6 +93,7 @@ from siat.valuation_china import *
93
93
  # 获取证券价格与计算
94
94
  from siat.security_prices import *
95
95
  from siat.security_price2 import *
96
+ from siat.other_indexes import *
96
97
 
97
98
  # 股票分析
98
99
  from siat.stock import *
siat/event_study.py CHANGED
@@ -44,6 +44,15 @@ if __name__=='__main__':
44
44
  event_window=[1,1] #事件发生时股市已经收盘,故检测下一个交易日的股市反应
45
45
  market_index='000001.SS' #贵州茅台在上交所上市,故使用上证综合指数
46
46
  RF=0
47
+
48
+ #测试组1b
49
+ ticker='600519.SS'
50
+
51
+ event_date='2024-4-2' #贵州茅台2023年报于2024年4月2日晚披露
52
+ start='2024-3-1'; end='2024-4-30'
53
+ event_window=[0,2] #事件发生时股市已经收盘,故检测下一个交易日的股市反应
54
+ market_index='000001.SS' #贵州茅台在上交所上市,故使用上证综合指数
55
+ RF=0
47
56
 
48
57
  #测试组2
49
58
  ticker=['600519.SS','399997.SZ']
@@ -75,6 +84,7 @@ if __name__=='__main__':
75
84
  facecolor="whitesmoke"
76
85
  show_AR=True
77
86
  show_RF=True
87
+ show_BHAR=True
78
88
  loc='best'
79
89
 
80
90
  es=event_study("600519.SS",event_date="2024-4-2", \
@@ -111,8 +121,9 @@ def event_study(ticker,event_date, \
111
121
  RF="market index", \
112
122
  ret_type="Daily Adj Ret%", \
113
123
  ticker_type='auto', \
114
- facecolor="whitesmoke",show_AR='auto',show_RF=False, \
115
- loc='best'):
124
+ show_AR='auto',show_RF=False,show_BHAR=False, \
125
+ draw_CAR=True,draw_BHAR=False, \
126
+ facecolor="whitesmoke",loc='best'):
116
127
  """
117
128
  ===========================================================================
118
129
  功能:展示事件研究法的累计异常收益率CAR。
@@ -127,13 +138,15 @@ def event_study(ticker,event_date, \
127
138
  注意:事件窗口不一定包括事件日(适用于事件日在非交易日的情形,例如周末或假日,或者在当日闭市后发生)
128
139
  如果事件日为非交易日,事件窗口需要后移至事件日后的第一个交易日。
129
140
  如果怀疑市场提前对事件发生反应,可以考虑前移事件窗口的开始日期。
141
+ 使用CAR时,事件窗口长度一般为数日;使用BHAR时可长达数月。
130
142
  post_event_days:用于分析事件窗口后的漂移效应,取事件窗口后多少天。
131
143
  默认不分析,取0天。可以指定天数,注意是否跨过非交易日情形,过长的窗口期也可能混杂其他事件的影响。
132
144
  method:估计事件窗口以及事件后窗口收益率预期值的方法
133
- 默认为CAPM(主要用于ticker为股票等),即通常所说的市场模型。
145
+ 默认为CAPM(主要用于ticker为股票等),即通常所说的市场模型法。
134
146
  如果ticker为股票等,也可直接使用指数收益率为其预期收益率,此时method为Market或Index,即常说的市场调整模型。
135
147
  如果ticker为指数,无法再借助指数,method只能使用Random Walk,即使用前一个收益率为预期收益率。
136
148
  注意:不管多个ticker时里面的不同证券类型,仅按第一个ticker的类型判断,并使用同一种证券类型。
149
+ 使用CAR时,对每日异常收益率相加,反映短期逐日异常收益的累积;使用BHAR时则为复利累积,反映长期异常收益。
137
150
  early_response_days:默认为-2,即提前2天市场就开始有反应。
138
151
  市场很可能对事件提前发生反应(因为泄密等原因),例如中国市场规定上市公司董事会开完后两天内必须披露。
139
152
  很可能刚开完董事会,市场就得到了消息。为规避这种情况对估计窗口的影响,可以调节此参数。
@@ -145,12 +158,17 @@ def event_study(ticker,event_date, \
145
158
  默认使用市场模型"market index"自动计算,无需指定。
146
159
  可直接指定具体数值。
147
160
  也可指定特定指标替代,例如一年期中国国债收益率"1YCNY.B"或一年期美债收益率"1YUSY.B"等。
148
- show_RF:在使用市场模型或指定指标时是否显示计算出的RF均值,默认为False。
149
161
  ticker_type:显式指明ticker的证券类型,当siat误判其类型(中国内地股票/债券/基金)时使用,默认'auto'。
150
- facecolor:显式指定绘图背景颜色,默认"whitesmoke"
162
+ show_RF:在使用市场模型或指定指标时是否显示计算出的RF均值,默认为False
151
163
  show_AR:是否绘图时绘制异常收益率AR
152
164
  默认'auto'(单个ticker时绘制,多个时不绘制)。
153
165
  也可指定True/False强行绘制/不绘制。
166
+ show_BHAR;是否显示BHAR数值,适用于长期窗口,默认否False。
167
+ draw_CAR:是否绘制CAR曲线,默认是True。
168
+ draw_BHAR:是否绘制BHAR曲线,默认否False。
169
+ 注意:对于短期窗口,CAR曲线与BHAR曲线差异微小,可能基本重合,因此建议仅绘制其中之一。
170
+ facecolor:显式指定绘图背景颜色,默认"whitesmoke"。
171
+
154
172
 
155
173
  示例:美的收购库卡事件对股价的影响
156
174
  es=event_study(["000333.SZ"],
@@ -441,10 +459,11 @@ def event_study(ticker,event_date, \
441
459
  if DEBUG2:
442
460
  print(" DEBUG: RF_type={0}, RF_text={1}, rf_dict={2}".format(RF_type,RF_text, rf_dict))
443
461
 
444
- #=====计算CAR==============================================================
462
+ #=====计算CAR和BHAR==============================================================
445
463
  for t in ticker_name(ticker,ticker_type):
446
464
  try:
447
465
  df_ret[t+"_CAR"]=0
466
+ df_ret[t+"_BHAR"]=0
448
467
  except: continue
449
468
 
450
469
  event_window_startpd=pd.to_datetime(event_window_start)
@@ -452,11 +471,14 @@ def event_study(ticker,event_date, \
452
471
  post_event_endpd=pd.to_datetime(post_event_end)
453
472
  startpd=pd.to_datetime(start); endpd=pd.to_datetime(end)
454
473
 
455
- #计算CAR
474
+ #计算CAR和BHAR
456
475
  df_ret_event=df_ret[(df_ret.index >=event_window_startpd) & (df_ret.index <=endpd)]
457
476
  for t in ticker_name(ticker,ticker_type):
458
477
  try:
459
- df_ret_event[t+'_CAR'] = df_ret_event[t+'_AR'].cumsum()
478
+ # CAR:单利累加求和(每日异常收益相加)
479
+ df_ret_event[t+'_CAR'] = df_ret_event[t+'_AR'].cumsum(skipna=True)
480
+ # BHAR:复利累积
481
+ df_ret_event[t+'_BHAR'] = ((1+df_ret_event[t+'_AR']/100).cumprod()-1)*100
460
482
  except: continue
461
483
 
462
484
  #合成事件前期间
@@ -464,11 +486,12 @@ def event_study(ticker,event_date, \
464
486
  for t in ticker_name(ticker,ticker_type):
465
487
  try:
466
488
  df_ret_before_event[t+'_CAR']=np.nan
489
+ df_ret_before_event[t+'_BHAR']=np.nan
467
490
  except: continue
468
491
 
469
492
  df_show=pd.concat([df_ret_before_event,df_ret_event])
470
493
 
471
- #是否显示AR:默认单证券显示,多证券不显示
494
+ #是否显示AR:默认单证券显示,多证券时不显示
472
495
  df_show_cols=[]
473
496
  for c in list(df_show):
474
497
  if show_AR=='auto':
@@ -555,6 +578,17 @@ def event_study(ticker,event_date, \
555
578
  #footnote5=footnote5+c_name+p_value_str+","
556
579
  #footnote5=footnote5+"{0}({1}, {2}), ".format(c_name,car_value_str,p_value_str)
557
580
  footnote5=footnote5+"{0}({1}, {2}, {3}), ".format(c_name,car_mean_str,car_median_str,p_value_str)
581
+
582
+ if 'BHAR' in c.upper():
583
+ bhar_value=df_event_window[c][-1]
584
+ if bhar_value > 0:
585
+ bhar_value_str=str(round(bhar_value,4))[:6]
586
+ else:
587
+ bhar_value_str=str(round(bhar_value,4))[:7]
588
+
589
+ if show_BHAR:
590
+ footnote5=footnote5+"BHAR: {0}, ".format(bhar_value_str)
591
+
558
592
  footnote5=footnote5.strip(", ")
559
593
 
560
594
  #显著性检验:异于零的t检验,事件后窗口
@@ -606,6 +640,17 @@ def event_study(ticker,event_date, \
606
640
 
607
641
  #footnote6=footnote6+c[:-4]+str(p_value)[:6]+","
608
642
  footnote6=footnote6+"{0}({1}, {2}, {3}), ".format(c_name,car_mean_str,car_median_str,p_value_str)
643
+
644
+ if 'BHAR' in c.upper():
645
+ bhar_value=df_post_event_window[c][-1]
646
+ if bhar_value > 0:
647
+ bhar_value_str=str(round(bhar_value,4))[:6]
648
+ else:
649
+ bhar_value_str=str(round(bhar_value,4))[:7]
650
+
651
+ if show_BHAR:
652
+ footnote6=footnote6+"BHAR: {0}, ".format(bhar_value_str)
653
+
609
654
  footnote6=footnote6.strip(", ")
610
655
 
611
656
  footnote7="数据来源:Sina/EM/Yahoo/Stooq/SWHY,"+stoday
@@ -659,8 +704,16 @@ def event_study(ticker,event_date, \
659
704
  attention_point.sort(reverse=False)
660
705
  attention_point=list({}.fromkeys(attention_point).keys())
661
706
 
707
+ # 是否绘制CAR或BHAR曲线:对于短期窗口,CAR曲线和BHAR曲线很可能基本重合,建议仅绘制其中之一!
708
+ df0draw=df0.copy()
709
+ for c in list(df0draw):
710
+ if not draw_CAR and 'CAR' in c:
711
+ del df0draw[c]
712
+ if not draw_BHAR and 'BHAR' in c:
713
+ del df0draw[c]
714
+
662
715
  #绘图
663
- draw_lines(df0,y_label,x_label,axhline_value,axhline_label,title_txt, \
716
+ draw_lines(df0draw,y_label,x_label,axhline_value,axhline_label,title_txt, \
664
717
  data_label=False, \
665
718
  loc=loc,resample_freq='D',smooth=False, \
666
719
  annotate=True,annotate_value=False, \
@@ -668,7 +721,7 @@ def event_study(ticker,event_date, \
668
721
  attention_point_area=attention_point_area, \
669
722
  ticker_type=ticker_type,facecolor=facecolor)
670
723
 
671
- #=====输出AR和/或CAR表格====================================================
724
+ #=====输出AR和/或CAR或BHAR表格====================================================
672
725
  df1=df0.copy()
673
726
  #df1=df1.replace([np.nan, None], np.nan).dropna()
674
727
  df1=df1.replace([np.nan, None],'-')
@@ -735,6 +788,10 @@ def event_study(ticker,event_date, \
735
788
  else:
736
789
  footnote=footnote2+footnote3+footnote4+'\n'+footnote5+'\n'+footnote6
737
790
 
791
+ for c in list(df1):
792
+ if not show_BHAR and 'BHAR' in c:
793
+ del df1[c]
794
+
738
795
  #显示结果表格
739
796
  df_display_CSS(df1,titletxt=title_txt,footnote=footnote,facecolor=facecolor,decimals=4, \
740
797
  first_col_align='left',second_col_align='left', \
siat/grafix.py CHANGED
@@ -331,7 +331,9 @@ def plot_line(df0,colname,collabel,ylabeltxt,titletxt,footnote,datatag=False, \
331
331
  atpd=at
332
332
 
333
333
  if DEBUG: print(f"atpd={atpd}")
334
- plt.axvline(x=atpd,ls=":",c=color,linewidth=1.5,label=text_lang("关注点","Attention point ")+str(at))
334
+ at_str=atpd.strftime('%Y-%m-%d')
335
+ #plt.axvline(x=atpd,ls=":",c=color,linewidth=1.5,label=text_lang("关注点","Attention point ")+str(at))
336
+ plt.axvline(x=atpd,ls=":",c=color,linewidth=1.5,label=text_lang("关注点","Attention point ")+at_str)
335
337
 
336
338
  if not attention_point_area=='':
337
339
  if isinstance(attention_point_area,list) and len(attention_point_area)>=2:
@@ -722,8 +724,9 @@ def plot_line2_coaxial(df01,ticker1,colname1,label1, \
722
724
 
723
725
  if DEBUG:
724
726
  print("atpd=",atpd)
725
-
726
- plt.axvline(x=atpd,ls=":",c=color,linewidth=1.5,label=text_lang("关注点","Attention point ")+str(at))
727
+
728
+ at_str=atpd.strftime('%Y-%m-%d')
729
+ plt.axvline(x=atpd,ls=":",c=color,linewidth=1.5,label=text_lang("关注点","Attention point ")+at_str)
727
730
 
728
731
  if not attention_point_area=='':
729
732
  if isinstance(attention_point_area,list) and len(attention_point_area)>=2:
@@ -992,8 +995,10 @@ def plot_line2_coaxial2(df01,ticker1,colname1,label1, \
992
995
 
993
996
  if DEBUG:
994
997
  print("atpd=",atpd)
995
-
996
- plt.axvline(x=atpd,ls=":",c=color,linewidth=1.5,label=text_lang("关注点","Attention point ")+str(at))
998
+
999
+ at_str=atpd.strftime('%Y-%m-%d')
1000
+ #plt.axvline(x=atpd,ls=":",c=color,linewidth=1.5,label=text_lang("关注点","Attention point ")+str(at))
1001
+ plt.axvline(x=atpd,ls=":",c=color,linewidth=1.5,label=text_lang("关注点","Attention point ")+at_str)
997
1002
 
998
1003
  if not attention_point_area=='':
999
1004
  if isinstance(attention_point_area,list) and len(attention_point_area)>=2:
@@ -1207,7 +1212,9 @@ def plot_line2_twinx(df01,ticker1,colname1,label1, \
1207
1212
  atpd=pd.to_datetime(at)
1208
1213
  except:
1209
1214
  atpd=at
1210
- plt.axvline(x=atpd,ls=":",c=color,linewidth=1.5,label=text_lang("关注点","Attention point ")+str(at))
1215
+
1216
+ at_str=atpd.strftime('%Y-%m-%d')
1217
+ plt.axvline(x=atpd,ls=":",c=color,linewidth=1.5,label=text_lang("关注点","Attention point ")+at_str)
1211
1218
 
1212
1219
  if not attention_point_area=='':
1213
1220
  if isinstance(attention_point_area,list) and len(attention_point_area)>=2:
@@ -1455,7 +1462,10 @@ def plot_line2_LR(df01,ticker1,colname1,label1, \
1455
1462
  atpd=pd.to_datetime(at)
1456
1463
  except:
1457
1464
  atpd=at
1458
- ax.axvline(x=atpd,ls=":",c=color,linewidth=1.5,label=text_lang("关注点","Attention point ")+str(at))
1465
+
1466
+ at_str=atpd.strftime('%Y-%m-%d')
1467
+ #ax.axvline(x=atpd,ls=":",c=color,linewidth=1.5,label=text_lang("关注点","Attention point ")+str(at))
1468
+ ax.axvline(x=atpd,ls=":",c=color,linewidth=1.5,label=text_lang("关注点","Attention point ")+at_str)
1459
1469
 
1460
1470
  if not attention_point_area=='':
1461
1471
  if isinstance(attention_point_area,list) and len(attention_point_area)>=2:
@@ -1698,7 +1708,10 @@ def plot_line2_UD(df01,ticker1,colname1,label1, \
1698
1708
  atpd=pd.to_datetime(at)
1699
1709
  except:
1700
1710
  atpd=at
1701
- ax.axvline(x=atpd,ls=":",c=color,linewidth=1.5,label=text_lang("关注点","Attention point ")+str(at))
1711
+
1712
+ at_str=atpd.strftime('%Y-%m-%d')
1713
+ #ax.axvline(x=atpd,ls=":",c=color,linewidth=1.5,label=text_lang("关注点","Attention point ")+str(at))
1714
+ ax.axvline(x=atpd,ls=":",c=color,linewidth=1.5,label=text_lang("关注点","Attention point ")+at_str)
1702
1715
 
1703
1716
  if not attention_point_area=='':
1704
1717
  if isinstance(attention_point_area,list) and len(attention_point_area)>=2:
@@ -1938,7 +1951,10 @@ def plot_line2_twinx2(df01,ticker1,colname1,label1, \
1938
1951
  atpd=pd.to_datetime(at)
1939
1952
  except:
1940
1953
  atpd=at
1941
- plt.axvline(x=atpd,ls=":",c=color,linewidth=1.5,label=text_lang("关注点","Attention point ")+str(at))
1954
+
1955
+ at_str=atpd.strftime('%Y-%m-%d')
1956
+ #plt.axvline(x=atpd,ls=":",c=color,linewidth=1.5,label=text_lang("关注点","Attention point ")+str(at))
1957
+ plt.axvline(x=atpd,ls=":",c=color,linewidth=1.5,label=text_lang("关注点","Attention point ")+at_str)
1942
1958
 
1943
1959
  if not attention_point_area=='':
1944
1960
  if isinstance(attention_point_area,list) and len(attention_point_area)>=2:
@@ -2406,7 +2422,9 @@ def draw_lines(df0,y_label,x_label,axhline_value,axhline_label,title_txt, \
2406
2422
  plt.arrow(atpd,yaxis_min,arrow_dx,arrow_dy,ls=':',lw=2,fc=color,ec=color,alpha=0.5,shape='full', \
2407
2423
  width=0.05,length_includes_head=True)
2408
2424
  """
2409
- plt.axvline(x=atpd,ls=":",c=color,linewidth=1.5,label=text_lang("关注点","Attention point ")+str(at))
2425
+ at_str=atpd.strftime('%Y-%m-%d')
2426
+ #plt.axvline(x=atpd,ls=":",c=color,linewidth=1.5,label=text_lang("关注点","Attention point ")+str(at))
2427
+ plt.axvline(x=atpd,ls=":",c=color,linewidth=1.5,label=text_lang("关注点","Attention point ")+at_str)
2410
2428
 
2411
2429
  if not attention_point_area=='':
2412
2430
  if isinstance(attention_point_area,list) and len(attention_point_area)>=2:
@@ -2782,7 +2800,10 @@ def draw_lines2(df0,y_label,x_label,axhline_value,axhline_label,title_txt, \
2782
2800
  atpd=pd.to_datetime(at)
2783
2801
  except:
2784
2802
  atpd=at
2785
- plt.axvline(x=atpd,ls=":",c=color,linewidth=1.5,label=text_lang("关注点","Attention point ")+str(at))
2803
+
2804
+ at_str=atpd.strftime('%Y-%m-%d')
2805
+ #plt.axvline(x=atpd,ls=":",c=color,linewidth=1.5,label=text_lang("关注点","Attention point ")+str(at))
2806
+ plt.axvline(x=atpd,ls=":",c=color,linewidth=1.5,label=text_lang("关注点","Attention point ")+at_str)
2786
2807
 
2787
2808
  if not attention_point_area=='':
2788
2809
  if isinstance(attention_point_area,list) and len(attention_point_area)>=2:
siat/other_indexes.py ADDED
@@ -0,0 +1,189 @@
1
+ # -*- coding: utf-8 -*-
2
+ """
3
+ 本模块功能:另类证券市场指数
4
+ 所属工具包:证券投资分析工具SIAT
5
+ SIAT:Security Investment Analysis Tool
6
+ 创建日期:2025年5月8日
7
+ 最新修订日期:
8
+ 作者:王德宏 (WANG Dehong, Peter)
9
+ 作者单位:北京外国语大学国际商学院
10
+ 作者邮件:wdehong2000@163.com
11
+ 版权所有:王德宏
12
+ 用途限制:仅限研究与教学使用,不可商用!商用需要额外授权。
13
+ 特别声明:作者不对使用本工具进行证券投资导致的任何损益负责!
14
+ """
15
+ #==============================================================================
16
+ #关闭所有警告
17
+ import warnings; warnings.filterwarnings('ignore')
18
+
19
+ from siat.common import *
20
+ #==============================================================================
21
+
22
+
23
+ def other_index_translate(index_code):
24
+ """
25
+ ===========================================================================
26
+ 功能:另类证券市场指数代码
27
+ 参数:
28
+ index_code: 指数代码,非标准,来自东方财富和新浪。
29
+ 返回值:是否找到,基于语言环境为中文或英文解释。
30
+ 语言环境判断为check_language()
31
+
32
+ 数据结构:['指数代码','指数符号','指数名称中文','指数名称英文','数据来源']
33
+ """
34
+
35
+ import pandas as pd
36
+ trans_dict=pd.DataFrame([
37
+
38
+ ['INDEXCF','俄罗斯MICEX指数','俄罗斯MICEX指数','MICEX Index','sina'],
39
+ ['RTS','俄罗斯RTS指数','俄罗斯RTS指数','RTS Index','sina'],
40
+ ['CASE','埃及CASE 30指数','埃及CASE30指数','CASE30 Index','sina'],
41
+ ['VNINDEX','越南胡志明','越南胡志明指数','Ho Chi-Ming Index','em'],
42
+ ['HSCEI','国企指数','港股国企指数','HK H-share Index','em'],
43
+ ['HSCCI','红筹指数','港股红筹指数','HK Red-share Index','em'],
44
+ ['CSEALL','斯里兰卡科伦坡','斯里兰卡科伦坡全指','Colombo Index','em'],
45
+ ['UDI','美元指数','美元指数','US Dollar Index','em'],
46
+ ['CRB','路透CRB商品指数','路透CRB商品指数','Reuters CRB Index','em'],
47
+ ['BDI','波罗的海BDI指数','波罗的海BDI指数','Baltic Dry Index','em'],
48
+ ['KSE100','巴基斯坦卡拉奇','巴基斯坦卡拉奇指数','KSE100 Index','em'],
49
+
50
+
51
+ ], columns=['code','symbol','name_cn','name_en','source'])
52
+
53
+ found=False; symbol=index_code
54
+ try:
55
+ dict_word=trans_dict[trans_dict['code']==index_code]
56
+ found=True
57
+ except:
58
+ #未查到翻译词汇,返回原词
59
+ pass
60
+
61
+ if dict_word is None:
62
+ found=False
63
+ elif len(dict_word) == 0:
64
+ found=False
65
+
66
+ source=''; name=''
67
+ if found:
68
+ symbol=dict_word['symbol'].values[0]
69
+
70
+ lang=check_language()
71
+ if lang == 'Chinese':
72
+ name=dict_word['name_cn'].values[0]
73
+ else:
74
+ name=dict_word['name_en'].values[0]
75
+
76
+ source=dict_word['source'].values[0]
77
+
78
+ return symbol,name,source
79
+
80
+ if __name__=='__main__':
81
+ index_code='KSE100'
82
+ index_code='CASE'
83
+ index_code='XYZ'
84
+
85
+ set_language('Chinese')
86
+ set_language('English')
87
+ other_index_translate(index_code)
88
+
89
+ #==============================================================================
90
+ def get_other_index_em(index_code,start,end):
91
+ """
92
+ 功能:获取另类指数历史行情,东方财富
93
+ 参数:
94
+ index_code:指数代码
95
+ start,end:开始/结束日期
96
+ """
97
+ symbol,name,source=other_index_translate(index_code)
98
+ if symbol == index_code:
99
+ return None
100
+
101
+ import akshare as ak
102
+ dft = ak.index_global_hist_em(symbol=symbol)
103
+ dft.rename(columns={'日期':'Date','代码':'ticker','名称':'Name','今开':'Open', \
104
+ '最新价':'Close','最高':'High','最低':'Low','振幅':'Change'}, \
105
+ inplace=True)
106
+ dft['Change']=dft['Change']/100.00
107
+ dft['Adj Close']=dft['Close']
108
+ dft['source']=source
109
+ dft['Volume']=0
110
+ dft['Name']=name
111
+
112
+ import pandas as pd
113
+ dft['date']=dft['Date'].apply(lambda x: pd.to_datetime(x))
114
+ dft.set_index('date',inplace=True)
115
+
116
+ startpd=pd.to_datetime(start); endpd=pd.to_datetime(end)
117
+ df=dft[(dft.index >= startpd) & (dft.index <= endpd)]
118
+
119
+ return df
120
+
121
+ if __name__=='__main__':
122
+ index_code='KSE100'
123
+ start='2025-2-1'; end='2025-3-31'
124
+ get_other_index_em(index_code,start,end)
125
+ #==============================================================================
126
+ def get_other_index_sina(index_code,start,end):
127
+ """
128
+ 功能:获取另类指数历史行情,新浪财经
129
+ 参数:
130
+ index_code:指数代码
131
+ start,end:开始/结束日期
132
+ """
133
+ symbol,name,source=other_index_translate(index_code)
134
+ if symbol == index_code:
135
+ return None
136
+
137
+ import akshare as ak
138
+ dft = ak.index_global_hist_sina(symbol=symbol)
139
+ dft.rename(columns={'open':'Open','high':'High','low':'Low','close':'Close', \
140
+ 'volume':'Volume'},inplace=True)
141
+ dft['ticker']=index_code; dft['Name']=name; dft['Date']=dft['date']
142
+ dft['Adj Close']=dft['Close']
143
+ dft['source']=source
144
+
145
+ import pandas as pd
146
+ dft['date']=dft['Date'].apply(lambda x: pd.to_datetime(x))
147
+ dft.set_index('date',inplace=True)
148
+
149
+ startpd=pd.to_datetime(start); endpd=pd.to_datetime(end)
150
+ df=dft[(dft.index >= startpd) & (dft.index <= endpd)]
151
+
152
+ return df
153
+
154
+ if __name__=='__main__':
155
+ index_code='CASE'
156
+ start='2025-2-1'; end='2025-3-31'
157
+ get_other_index_sina(index_code,start,end)
158
+ #==============================================================================
159
+ def get_other_index_ak(index_code,start,end):
160
+ """
161
+ 功能:获取另类指数历史行情,新浪财经或东方财富
162
+ 参数:
163
+ index_code:指数代码
164
+ start,end:开始/结束日期
165
+ """
166
+ symbol,name,source=other_index_translate(index_code)
167
+ if symbol == index_code:
168
+ return None
169
+
170
+ if source == 'em':
171
+ df=get_other_index_em(index_code,start,end)
172
+ elif source == 'sina':
173
+ df=get_other_index_sina(index_code,start,end)
174
+ else:
175
+ df=None
176
+
177
+ return df
178
+
179
+ if __name__=='__main__':
180
+ index_code='CASE'
181
+ index_code='KSE100'
182
+ index_code='VNINDEX'
183
+ start='2025-2-1'; end='2025-3-31'
184
+ get_other_index(index_code,start,end)
185
+ #==============================================================================
186
+ #==============================================================================
187
+ #==============================================================================
188
+
189
+
siat/security_price2.py CHANGED
@@ -14,6 +14,7 @@ import warnings; warnings.filterwarnings('ignore')
14
14
  from siat.common import *
15
15
  from siat.translate import *
16
16
  from siat.security_prices import *
17
+ from siat.other_indexes import *
17
18
  #==============================================================================
18
19
  import pandas as pd
19
20
  #==============================================================================
@@ -67,6 +68,7 @@ if __name__=='__main__':
67
68
 
68
69
  # 新测试组
69
70
  ticker="XAUUSD"
71
+ ticker="^NSEI"
70
72
  fromdate='2024-5-1'; todate='2024-5-20'
71
73
  ticker_type='auto';source='auto'
72
74
  adjust='';fill=False
@@ -119,7 +121,7 @@ def get_price_1ticker(ticker,fromdate,todate, \
119
121
  ticker_type=ticker_type_preprocess_1str(ticker,ticker_type)
120
122
 
121
123
  #数据源情形1:akshare
122
- if source in ['auto','sina']:
124
+ if source in ['auto','sina','em']:
123
125
  #中国的证券
124
126
  if suffix in SUFFIX_LIST_CN:
125
127
  #含处理证券类型优先级
@@ -185,7 +187,11 @@ def get_price_1ticker(ticker,fromdate,todate, \
185
187
  if source in ['auto'] and found not in ['Found','Empty']:
186
188
  dft=get_index_fred(ticker1,fromdate,todate)
187
189
  found=df_have_data(dft)
188
-
190
+
191
+ #数据源情形6:仅用于几个另类非常用指数,例如胡志明指数/卡拉奇指数/埃及指数等,新浪/东方财富
192
+ if source in ['auto','sina','em'] and found not in ['Found','Empty']:
193
+ dft=get_other_index_ak(ticker1,fromdate,todate)
194
+ found=df_have_data(dft)
189
195
  #数据源情形6:pandas_datareader,其他数据源,暂不支持
190
196
  """
191
197
  Tiingo:获取股票,共同基金和信息和交易所交易基金的信息,可以免费注册获得API_KEY
siat/translate.py CHANGED
@@ -1150,7 +1150,19 @@ def codetranslate0(code):
1150
1150
 
1151
1151
  ['^XU100','伊斯坦布尔100指数'], ['10TRY.B','土耳其10年期国债收益率%'],
1152
1152
 
1153
-
1153
+ # 另类指数
1154
+ ['INDEXCF','俄罗斯MICEX指数'],
1155
+ ['RTS','俄罗斯RTS指数'],
1156
+ ['CASE','埃及CASE30指数'],
1157
+ ['VNINDEX','越南胡志明指数'],
1158
+ ['HSCEI','港股国企指数'],
1159
+ ['HSCCI','港股红筹指数'],
1160
+ ['CSEALL','斯里兰卡科伦坡全指'],
1161
+ ['UDI','美元指数'],
1162
+ ['CRB','路透CRB商品指数'],
1163
+ ['BDI','波罗的海BDI指数'],
1164
+ ['KSE100','巴基斯坦卡拉奇指数'],
1165
+
1154
1166
 
1155
1167
  #债券==================================================================
1156
1168
  ['sh019521','15国债21'],['sz128086','国轩转债'],['sz123027','蓝晓转债'],
@@ -2035,6 +2047,20 @@ def codetranslate1(code):
2035
2047
  ['^XU100','ISE National-100 index'], ['10TRY.B','Turkey 10-year Treasurybond Yield%'],
2036
2048
  ['10CNY.B','10-Year China Treasurybond Yield%'],
2037
2049
 
2050
+ # 另类指数
2051
+ ['INDEXCF','Russia MICEX Index'],
2052
+ ['RTS','Russia RTS Index'],
2053
+ ['CASE','Egypt CASE30 Index'],
2054
+ ['VNINDEX','Ho Chi-Ming Index'],
2055
+ ['HSCEI','HK H-share Index'],
2056
+ ['HSCCI','HK Red-share Index'],
2057
+ ['CSEALL','Colombo Index'],
2058
+ ['UDI','US Dollar Index'],
2059
+ ['CRB','Reuters CRB Index'],
2060
+ ['BDI','Baltic Dry Index'],
2061
+ ['KSE100','Pakistan KSE100 Index'],
2062
+
2063
+
2038
2064
  #债券==================================================================
2039
2065
  ['sh019521','15国债21'],['sz128086','国轩转债'],['sz123027','蓝晓转债'],
2040
2066
  ['^IRX','13-week Treasury Yield%'],['^FVX','5-year Treasury Yield%'],
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: siat
3
- Version: 3.8.48
3
+ Version: 3.9.10
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
@@ -1,7 +1,7 @@
1
1
  siat/__init__ -20240701.py,sha256=gP5uajXnJesnH5SL0ZPwq_Qhv59AG1bs4qwZv26Fo2Y,2894
2
2
  siat/__init__.py,sha256=tpSBf8BYpWOzBDF2iNQ4tlVxjx7bmkVQ3kPUu9X3iog,2227
3
3
  siat/__init__.py.backup_20250214.py,sha256=pIo4CV3lNPKIhitmhIh_6aAfZrmzQWGNDcEnvZ7GXoc,3216
4
- siat/allin.py,sha256=9xwa97S6KPHXGuqDtyN9b6Y4lCSM1VdBqpFBrlRvV8I,3001
4
+ siat/allin.py,sha256=--32Bt2Mfg7l38w7X9cLJCdWtYRB3tTtVHnS9WnqKDI,3035
5
5
  siat/alpha_vantage_test.py,sha256=tKr-vmuFH3CZAqwmISz6jzjPHzV1JJl3sPfZdz8aTfM,747
6
6
  siat/assets_liquidity.py,sha256=o_UZdLs693uNWPEQB2OzxDH0mdWimOmq4qe_vx1pue0,28987
7
7
  siat/assets_liquidity_test.py,sha256=UWk6HIUlizU7LQZ890fGx8LwU1jMMrIZswg8cFUJWZ8,1285
@@ -34,7 +34,7 @@ siat/economy2.py,sha256=inmArHl43HFnSn6O4uY-xcsQY93IyMlFet3pQ7JpsjM,81089
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
37
- siat/event_study.py,sha256=30ji4TP4xztNVjQdkBlwWstkCIGg6McTYe8dWlbloTg,34341
37
+ siat/event_study.py,sha256=xhWpKMcLbXxyFWADxgEeMLp_370CsPonGlELbpOJVLA,36978
38
38
  siat/exchange_bond_china.pickle,sha256=zDqdPrFacQ0nqjP_SuF6Yy87EgijIRsFvFroW7FAYYY,1265092
39
39
  siat/fama_french.py,sha256=aUTC-67t_CEPbLk4u79woW_zfZ7OCP6Fo4z5EdWCSkQ,48051
40
40
  siat/fama_french_test.py,sha256=M4O23lBKsJxhWHRluwCb3l7HSEn3OFTjzGMpehcevRg,4678
@@ -64,7 +64,7 @@ siat/future_china.py,sha256=F-HsIf2Op8Z22RzTjet1g8COzldgnMjFNSXsAkeGyWo,17595
64
64
  siat/future_china_test.py,sha256=BrSzmDVaOHki6rntOtosmRn-6dkfOBuLulJNqh7MOpc,1163
65
65
  siat/global_index_test.py,sha256=hnFp3wqqzzL-kAP8mgxDZ54Bd5Ijf6ENi5YJlGBgcXw,2402
66
66
  siat/google_authenticator.py,sha256=ZUbZR8OW0IAKDbcYtlqGqIpZdERpFor9NccFELxg9yI,1637
67
- siat/grafix.py,sha256=X9eWpD6ndQSAkOEcbfC9b8KrY-rlYEhz63kE8JALs8E,139802
67
+ siat/grafix.py,sha256=8aL8z5TF963T7GgW62iNL5h5P_HA_AxAVxmBJK3Os28,141240
68
68
  siat/grafix_test.py,sha256=kXvcpLgQNO7wd30g_bWljLj5UH7bIVI0_dUtXbfiKR0,3150
69
69
  siat/holding_risk.py,sha256=uWRtMMJqKr-puQn26g6Fq5N3mFB70c0B99zLQug8hAo,30774
70
70
  siat/holding_risk_test.py,sha256=FRlw_9wFG98BYcg_cSj95HX5WZ1TvkGaOUdXD7-V86s,474
@@ -89,6 +89,7 @@ siat/option_china_test.py,sha256=UQ-YUHUjoGBQyanLcM-yzqeEIUQP_gCQIeT0W6rnUnA,163
89
89
  siat/option_pricing.py,sha256=vyQNgBsjcJi70Pa-fJTVVIGK_3jWh80tkd1ESnn3sE4,74069
90
90
  siat/option_pricing_test.py,sha256=eeorV5Ja5vjlRXnP6fWJHetGU5Vb8SnLopkC6RV3GfA,2203
91
91
  siat/option_sina_api_test.py,sha256=dn-k_wrQnAaNKHoROvWJEc7lqlU0bwiV2Aa4usWAFGM,5908
92
+ siat/other_indexes.py,sha256=DXijuTBhXWj7xEAIGzeczbt1CcJlfxV0hQ_UIuqIdfk,6859
92
93
  siat/proxy_test.py,sha256=erQJrmGs2X46z8Gb1h-7GYQ0rTUcaR8dxHExWoBz2eM,2610
93
94
  siat/quandl_test.py,sha256=EcPoXnLuqzPl5dKyVEZi3j3PJZFpsnU_iNPhLWC9p-A,1552
94
95
  siat/risk_adjusted_return.py,sha256=6F8CpKm-HKO4wfnndri0ew-D3lDAH1fs5O9K5cphoLg,55096
@@ -101,7 +102,7 @@ siat/risk_free_rate_test.py,sha256=CpmhUf8aEAEZeNu4gvWP2Mz2dLoIgBX5bI41vfUBEr8,4
101
102
  siat/sector_china.py,sha256=9zjdORWx5ia_gUezidhOKWmCnVDwWcnnjjugHudelaQ,157411
102
103
  siat/sector_china_test.py,sha256=1wq7ef8Bb_L8F0h0W6FvyBrIcBTEbrTV7hljtpj49U4,5843
103
104
  siat/security_price.py,sha256=2oHskgiw41KMGfqtnA0i2YjNNV6cYgtlUK0j3YeuXWs,29185
104
- siat/security_price2.py,sha256=dYwvz9H-uWp-Gyc1g_MId9k8cITS6ZHmjW-Fc2ypp-0,26587
105
+ siat/security_price2.py,sha256=2my4JgVIoQunQ-xDlHPGZRyBJ4KFuM6nVQTwqmauIK0,26966
105
106
  siat/security_prices.py,sha256=HoCZ7YPrQYZHgKC-LyXFeeBCTfRc3EMMEiEg52SVv2w,109073
106
107
  siat/security_prices_test.py,sha256=OEphoJ87NPKoNow1QA8EU_5MUYrJF-qKoWKNapVfZNI,10779
107
108
  siat/security_trend.py,sha256=o0vpWdrJkmODCP94X-Bvn-w7efHhj9HpUYBHtLl55D0,17240
@@ -135,7 +136,7 @@ siat/transaction_test.py,sha256=Z8g1LJCN4-mnUByXMUMoFmN0t105cbmsz2QmvSuIkbU,1858
135
136
  siat/translate-20230125.py,sha256=NPPSXhT38s5t9fzMvl_fvi4ckSB73ThLmZetVI-xGdU,117953
136
137
  siat/translate-20230206.py,sha256=-vtI125WyaJhmPotOpDAmclt_XnYVaWU9ByLWZ6FyYE,118133
137
138
  siat/translate-20230215.py,sha256=TJgtPE3n8IjljmZ4Pefy8dmHoNdFF-1zpML6BhA9FKE,121657
138
- siat/translate.py,sha256=6kIzzzdh04J2BkR2XSnKkl4rTZWSHarW-4AdarTZJvI,262334
139
+ siat/translate.py,sha256=m8mDVHilsw9nSIGBcvl_pS-aMy3W7UVKEZsLwhfuIEg,263300
139
140
  siat/translate_20240606.py,sha256=63IyHWEU3Uz9mjwyuAX3fqY4nUMdwh0ICQAgmgPXP7Y,215121
140
141
  siat/translate_241003_keep.py,sha256=un7Fqe1v35MXsja5exZgjmLzrZtt66NARZIGlyFuGGU,218747
141
142
  siat/universal_test.py,sha256=CDAOffW1Rvs-TcNN5giWVvHMlch1w4dp-w5SIV9jXL0,3936
@@ -144,8 +145,8 @@ siat/valuation_china.py,sha256=eSKIDckyjG8QkENlW_OKkqbQHno8pzDcomBO9iGNJVM,83079
144
145
  siat/valuation_market_china_test.py,sha256=gbJ0ioauuo4koTPH6WKUkqcXiQPafnbhU5eKJ6lpdLA,1571
145
146
  siat/var_model_validation.py,sha256=R0caWnuZarrRg9939hxh3vJIIpIyPfvelYmzFNZtPbo,14910
146
147
  siat/yf_name.py,sha256=laNKMTZ9hdenGX3IZ7G0a2RLBKEWtUQJFY9CWuk_fp8,24058
147
- siat-3.8.48.dist-info/LICENSE,sha256=NTEMMROY9_4U1szoKC3N2BLHcDd_o5uTgqdVH8tbApw,1071
148
- siat-3.8.48.dist-info/METADATA,sha256=dvMkCPc4aEw3Msl0BeSKOOaLDHSglS26AXleOlmktTk,8335
149
- siat-3.8.48.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
150
- siat-3.8.48.dist-info/top_level.txt,sha256=r1cVyL7AIKqeAmEJjNR8FMT20OmEzufDstC2gv3NvEY,5
151
- siat-3.8.48.dist-info/RECORD,,
148
+ siat-3.9.10.dist-info/LICENSE,sha256=NTEMMROY9_4U1szoKC3N2BLHcDd_o5uTgqdVH8tbApw,1071
149
+ siat-3.9.10.dist-info/METADATA,sha256=tcyrbbCQ4PKsHAi4jCkJXdIAXyCicGRom6snzC3cqso,8335
150
+ siat-3.9.10.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
151
+ siat-3.9.10.dist-info/top_level.txt,sha256=r1cVyL7AIKqeAmEJjNR8FMT20OmEzufDstC2gv3NvEY,5
152
+ siat-3.9.10.dist-info/RECORD,,
File without changes
File without changes