siat 3.10.132__py3-none-any.whl → 3.11.1__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.
Files changed (221) hide show
  1. siat/__init__.py +0 -0
  2. siat/allin.py +8 -0
  3. siat/assets_liquidity.py +0 -0
  4. siat/beta_adjustment.py +0 -0
  5. siat/beta_adjustment_china.py +0 -0
  6. siat/blockchain.py +0 -0
  7. siat/bond.py +0 -0
  8. siat/bond_base.py +0 -0
  9. siat/bond_china.py +0 -0
  10. siat/bond_zh_sina.py +0 -0
  11. siat/capm_beta.py +0 -0
  12. siat/capm_beta2.py +4 -4
  13. siat/common.py +9 -6
  14. siat/compare_cross.py +0 -0
  15. siat/copyrights.py +0 -0
  16. siat/cryptocurrency.py +0 -0
  17. siat/economy.py +0 -0
  18. siat/economy2.py +0 -0
  19. siat/esg.py +0 -0
  20. siat/event_study.py +0 -0
  21. siat/exchange_bond_china.pickle +0 -0
  22. siat/fama_french.py +0 -0
  23. siat/fin_stmt2_yahoo.py +0 -0
  24. siat/financial_base.py +0 -0
  25. siat/financial_statements.py +0 -0
  26. siat/financials.py +0 -0
  27. siat/financials2.py +0 -0
  28. siat/financials_china.py +0 -0
  29. siat/financials_china2.py +0 -0
  30. siat/fund.py +0 -0
  31. siat/fund_china.pickle +0 -0
  32. siat/fund_china.py +0 -0
  33. siat/future_china.py +0 -0
  34. siat/google_authenticator.py +0 -0
  35. siat/grafix.py +55 -4
  36. siat/holding_risk.py +0 -0
  37. siat/luchy_draw.py +0 -0
  38. siat/market_china.py +0 -0
  39. siat/markowitz.py +0 -0
  40. siat/markowitz2.py +1 -0
  41. siat/markowitz2_20250704.py +0 -0
  42. siat/markowitz2_20250705.py +0 -0
  43. siat/markowitz_simple.py +0 -0
  44. siat/ml_cases.py +0 -0
  45. siat/ml_cases_example.py +0 -0
  46. siat/option_china.py +0 -0
  47. siat/option_pricing.py +0 -0
  48. siat/other_indexes.py +0 -0
  49. siat/risk_adjusted_return.py +0 -0
  50. siat/risk_adjusted_return2.py +8 -4
  51. siat/risk_evaluation.py +0 -0
  52. siat/risk_free_rate.py +0 -0
  53. siat/save2docx.py +345 -0
  54. siat/save2pdf.py +145 -0
  55. siat/sector_china.py +0 -0
  56. siat/security_price2.py +0 -0
  57. siat/security_prices.py +168 -6
  58. siat/security_trend.py +0 -0
  59. siat/security_trend2.py +2 -2
  60. siat/stock.py +11 -1
  61. siat/stock_advice_linear.py +0 -0
  62. siat/stock_base.py +0 -0
  63. siat/stock_china.py +0 -0
  64. siat/stock_info.pickle +0 -0
  65. siat/stock_prices_kneighbors.py +0 -0
  66. siat/stock_prices_linear.py +0 -0
  67. siat/stock_profile.py +0 -0
  68. siat/stock_technical.py +0 -0
  69. siat/stooq.py +0 -0
  70. siat/transaction.py +0 -0
  71. siat/translate.py +0 -0
  72. siat/valuation.py +0 -0
  73. siat/valuation_china.py +0 -0
  74. siat/var_model_validation.py +0 -0
  75. siat/yf_name.py +0 -0
  76. {siat-3.10.132.dist-info/licenses → siat-3.11.1.dist-info}/LICENSE +0 -0
  77. {siat-3.10.132.dist-info → siat-3.11.1.dist-info}/METADATA +234 -235
  78. siat-3.11.1.dist-info/RECORD +80 -0
  79. {siat-3.10.132.dist-info → siat-3.11.1.dist-info}/WHEEL +1 -1
  80. {siat-3.10.132.dist-info → siat-3.11.1.dist-info}/top_level.txt +0 -1
  81. build/lib/build/lib/siat/__init__.py +0 -75
  82. build/lib/build/lib/siat/allin.py +0 -137
  83. build/lib/build/lib/siat/assets_liquidity.py +0 -915
  84. build/lib/build/lib/siat/beta_adjustment.py +0 -1058
  85. build/lib/build/lib/siat/beta_adjustment_china.py +0 -548
  86. build/lib/build/lib/siat/blockchain.py +0 -143
  87. build/lib/build/lib/siat/bond.py +0 -2900
  88. build/lib/build/lib/siat/bond_base.py +0 -992
  89. build/lib/build/lib/siat/bond_china.py +0 -100
  90. build/lib/build/lib/siat/bond_zh_sina.py +0 -143
  91. build/lib/build/lib/siat/capm_beta.py +0 -783
  92. build/lib/build/lib/siat/capm_beta2.py +0 -887
  93. build/lib/build/lib/siat/common.py +0 -5360
  94. build/lib/build/lib/siat/compare_cross.py +0 -642
  95. build/lib/build/lib/siat/copyrights.py +0 -18
  96. build/lib/build/lib/siat/cryptocurrency.py +0 -667
  97. build/lib/build/lib/siat/economy.py +0 -1471
  98. build/lib/build/lib/siat/economy2.py +0 -1853
  99. build/lib/build/lib/siat/esg.py +0 -536
  100. build/lib/build/lib/siat/event_study.py +0 -815
  101. build/lib/build/lib/siat/fama_french.py +0 -1521
  102. build/lib/build/lib/siat/fin_stmt2_yahoo.py +0 -982
  103. build/lib/build/lib/siat/financial_base.py +0 -1160
  104. build/lib/build/lib/siat/financial_statements.py +0 -598
  105. build/lib/build/lib/siat/financials.py +0 -2339
  106. build/lib/build/lib/siat/financials2.py +0 -1278
  107. build/lib/build/lib/siat/financials_china.py +0 -4433
  108. build/lib/build/lib/siat/financials_china2.py +0 -2212
  109. build/lib/build/lib/siat/fund.py +0 -629
  110. build/lib/build/lib/siat/fund_china.py +0 -3307
  111. build/lib/build/lib/siat/future_china.py +0 -551
  112. build/lib/build/lib/siat/google_authenticator.py +0 -47
  113. build/lib/build/lib/siat/grafix.py +0 -3636
  114. build/lib/build/lib/siat/holding_risk.py +0 -867
  115. build/lib/build/lib/siat/luchy_draw.py +0 -638
  116. build/lib/build/lib/siat/market_china.py +0 -1168
  117. build/lib/build/lib/siat/markowitz.py +0 -2363
  118. build/lib/build/lib/siat/markowitz2.py +0 -3150
  119. build/lib/build/lib/siat/markowitz2_20250704.py +0 -2969
  120. build/lib/build/lib/siat/markowitz2_20250705.py +0 -3158
  121. build/lib/build/lib/siat/markowitz_simple.py +0 -373
  122. build/lib/build/lib/siat/ml_cases.py +0 -2291
  123. build/lib/build/lib/siat/ml_cases_example.py +0 -60
  124. build/lib/build/lib/siat/option_china.py +0 -3069
  125. build/lib/build/lib/siat/option_pricing.py +0 -1925
  126. build/lib/build/lib/siat/other_indexes.py +0 -409
  127. build/lib/build/lib/siat/risk_adjusted_return.py +0 -1576
  128. build/lib/build/lib/siat/risk_adjusted_return2.py +0 -1900
  129. build/lib/build/lib/siat/risk_evaluation.py +0 -2218
  130. build/lib/build/lib/siat/risk_free_rate.py +0 -351
  131. build/lib/build/lib/siat/sector_china.py +0 -4140
  132. build/lib/build/lib/siat/security_price2.py +0 -727
  133. build/lib/build/lib/siat/security_prices.py +0 -3408
  134. build/lib/build/lib/siat/security_trend.py +0 -402
  135. build/lib/build/lib/siat/security_trend2.py +0 -646
  136. build/lib/build/lib/siat/stock.py +0 -4284
  137. build/lib/build/lib/siat/stock_advice_linear.py +0 -934
  138. build/lib/build/lib/siat/stock_base.py +0 -26
  139. build/lib/build/lib/siat/stock_china.py +0 -2095
  140. build/lib/build/lib/siat/stock_prices_kneighbors.py +0 -910
  141. build/lib/build/lib/siat/stock_prices_linear.py +0 -386
  142. build/lib/build/lib/siat/stock_profile.py +0 -707
  143. build/lib/build/lib/siat/stock_technical.py +0 -3305
  144. build/lib/build/lib/siat/stooq.py +0 -74
  145. build/lib/build/lib/siat/transaction.py +0 -347
  146. build/lib/build/lib/siat/translate.py +0 -5183
  147. build/lib/build/lib/siat/valuation.py +0 -1378
  148. build/lib/build/lib/siat/valuation_china.py +0 -2076
  149. build/lib/build/lib/siat/var_model_validation.py +0 -444
  150. build/lib/build/lib/siat/yf_name.py +0 -811
  151. build/lib/siat/__init__.py +0 -75
  152. build/lib/siat/allin.py +0 -137
  153. build/lib/siat/assets_liquidity.py +0 -915
  154. build/lib/siat/beta_adjustment.py +0 -1058
  155. build/lib/siat/beta_adjustment_china.py +0 -548
  156. build/lib/siat/blockchain.py +0 -143
  157. build/lib/siat/bond.py +0 -2900
  158. build/lib/siat/bond_base.py +0 -992
  159. build/lib/siat/bond_china.py +0 -100
  160. build/lib/siat/bond_zh_sina.py +0 -143
  161. build/lib/siat/capm_beta.py +0 -783
  162. build/lib/siat/capm_beta2.py +0 -887
  163. build/lib/siat/common.py +0 -5360
  164. build/lib/siat/compare_cross.py +0 -642
  165. build/lib/siat/copyrights.py +0 -18
  166. build/lib/siat/cryptocurrency.py +0 -667
  167. build/lib/siat/economy.py +0 -1471
  168. build/lib/siat/economy2.py +0 -1853
  169. build/lib/siat/esg.py +0 -536
  170. build/lib/siat/event_study.py +0 -815
  171. build/lib/siat/fama_french.py +0 -1521
  172. build/lib/siat/fin_stmt2_yahoo.py +0 -982
  173. build/lib/siat/financial_base.py +0 -1160
  174. build/lib/siat/financial_statements.py +0 -598
  175. build/lib/siat/financials.py +0 -2339
  176. build/lib/siat/financials2.py +0 -1278
  177. build/lib/siat/financials_china.py +0 -4433
  178. build/lib/siat/financials_china2.py +0 -2212
  179. build/lib/siat/fund.py +0 -629
  180. build/lib/siat/fund_china.py +0 -3307
  181. build/lib/siat/future_china.py +0 -551
  182. build/lib/siat/google_authenticator.py +0 -47
  183. build/lib/siat/grafix.py +0 -3636
  184. build/lib/siat/holding_risk.py +0 -867
  185. build/lib/siat/luchy_draw.py +0 -638
  186. build/lib/siat/market_china.py +0 -1168
  187. build/lib/siat/markowitz.py +0 -2363
  188. build/lib/siat/markowitz2.py +0 -3150
  189. build/lib/siat/markowitz2_20250704.py +0 -2969
  190. build/lib/siat/markowitz2_20250705.py +0 -3158
  191. build/lib/siat/markowitz_simple.py +0 -373
  192. build/lib/siat/ml_cases.py +0 -2291
  193. build/lib/siat/ml_cases_example.py +0 -60
  194. build/lib/siat/option_china.py +0 -3069
  195. build/lib/siat/option_pricing.py +0 -1925
  196. build/lib/siat/other_indexes.py +0 -409
  197. build/lib/siat/risk_adjusted_return.py +0 -1576
  198. build/lib/siat/risk_adjusted_return2.py +0 -1900
  199. build/lib/siat/risk_evaluation.py +0 -2218
  200. build/lib/siat/risk_free_rate.py +0 -351
  201. build/lib/siat/sector_china.py +0 -4140
  202. build/lib/siat/security_price2.py +0 -727
  203. build/lib/siat/security_prices.py +0 -3408
  204. build/lib/siat/security_trend.py +0 -402
  205. build/lib/siat/security_trend2.py +0 -646
  206. build/lib/siat/stock.py +0 -4284
  207. build/lib/siat/stock_advice_linear.py +0 -934
  208. build/lib/siat/stock_base.py +0 -26
  209. build/lib/siat/stock_china.py +0 -2095
  210. build/lib/siat/stock_prices_kneighbors.py +0 -910
  211. build/lib/siat/stock_prices_linear.py +0 -386
  212. build/lib/siat/stock_profile.py +0 -707
  213. build/lib/siat/stock_technical.py +0 -3305
  214. build/lib/siat/stooq.py +0 -74
  215. build/lib/siat/transaction.py +0 -347
  216. build/lib/siat/translate.py +0 -5183
  217. build/lib/siat/valuation.py +0 -1378
  218. build/lib/siat/valuation_china.py +0 -2076
  219. build/lib/siat/var_model_validation.py +0 -444
  220. build/lib/siat/yf_name.py +0 -811
  221. siat-3.10.132.dist-info/RECORD +0 -218
@@ -1,815 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- """
3
- 本模块功能:证券事件分析法
4
- 所属工具包:证券投资分析工具SIAT
5
- SIAT:Security Investment Analysis Tool
6
- 创建日期:2024年11月14日
7
- 最新修订日期:
8
- 作者:王德宏 (WANG Dehong, Peter)
9
- 作者单位:北京外国语大学国际商学院
10
- 作者邮件:wdehong2000@163.com
11
- 版权所有:王德宏
12
- 用途限制:仅限研究与教学使用!
13
- 特别声明:作者不对使用本工具进行证券投资导致的任何损益负责!
14
- """
15
-
16
- #==============================================================================
17
- #关闭所有警告
18
- import warnings; warnings.filterwarnings('ignore')
19
- #==============================================================================
20
- from siat.common import *
21
- from siat.translate import *
22
- #from siat.security_trend2 import *
23
-
24
- from siat.stock import *
25
- #from siat.security_prices import *
26
- #from siat.security_price2 import *
27
- #from siat.capm_beta2 import *
28
- #from siat.risk_adjusted_return2 import *
29
- #from siat.valuation import *
30
-
31
- from siat.grafix import *
32
-
33
- import pandas as pd; import numpy as np
34
-
35
- import datetime as dt; stoday=str(dt.date.today())
36
- #==============================================================================
37
- #==============================================================================
38
- if __name__=='__main__':
39
- #测试组1
40
- ticker='600519.SS'
41
-
42
- event_date='2024-4-2' #贵州茅台2023年报于2024年4月2日晚披露
43
- start='2024-3-1'; end='2024-4-30'
44
- event_window=[1,1] #事件发生时股市已经收盘,故检测下一个交易日的股市反应
45
- market_index='000001.SS' #贵州茅台在上交所上市,故使用上证综合指数
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
56
-
57
- #测试组2
58
- ticker=['600519.SS','399997.SZ']
59
-
60
- event_date='2024-3-15' #315晚会
61
- start='2024-3-1'; end='2024-3-30'
62
- event_window=[1,2]
63
- market_index='000300.SS'
64
- RF="market model"
65
-
66
- #测试组3
67
- ticker=['600519.SS','399997.SZ']
68
-
69
- event_date='2024-4-2' #贵州茅台2023年报披露日
70
- start='auto'; end='auto'
71
- event_window=[0,1]
72
- method='CAPM'
73
- market_index='000001.SS'
74
- RF="1YCNY.B"
75
-
76
- #共同部分
77
- post_event_days=7
78
- method='CAPM'
79
- early_response_days=-2
80
- estimation_window_days=-365
81
-
82
- ret_type="Daily Adj Ret%"
83
- ticker_type='stock' #贵州茅台为股票
84
- facecolor="whitesmoke"
85
- show_AR=True
86
- show_RF=True
87
- show_BHAR=True
88
- loc='best'
89
-
90
- es=event_study("600519.SS",event_date="2024-4-2", \
91
- start='2024-3-1',end='2024-4-30', \
92
- event_window=[0,0],post_event_days=7, \
93
- method='CAPM', \
94
- market_index='000001.SS',RF=0.0143)
95
-
96
- es=event_study("600519.SS",event_date="2024-4-2", \
97
- start='2024-3-15',end='2024-4-20', \
98
- event_window=[0,1],post_event_days=7, \
99
- method='CAPM', \
100
- market_index='000001.SS',RF=0.0143)
101
-
102
- es=event_study("600519.SS",event_date="2024-4-2", \
103
- start='2024-3-1',end='2024-4-30', \
104
- event_window=[0,0],post_event_days=7, \
105
- method='market',market_index='000001.SS')
106
-
107
- es=event_study("600519.SS",event_date="2024-4-2", \
108
- start='2024-3-1',end='2024-4-30', \
109
- event_window=[0,0],post_event_days=7, \
110
- method='random walk')
111
-
112
-
113
- def event_study(ticker,event_date, \
114
- start='auto',end='auto', \
115
- event_window=[1,3], \
116
- post_event_days=0, \
117
- method='CAPM', \
118
- early_response_days=-2, \
119
- estimation_window_days=-365, \
120
- market_index='000300.SS', \
121
- RF="market index", \
122
- ret_type="Daily Adj Ret%", \
123
- ticker_type='auto', \
124
- show_AR='auto',show_RF=False,show_BHAR=False, \
125
- draw_CAR=True,draw_BHAR=False, \
126
- facecolor="whitesmoke",loc='best'):
127
- """
128
- ===========================================================================
129
- 功能:展示事件研究法的累计异常收益率CAR。
130
- 参数:
131
- ticker:证券代码,可为股票、债券、基金、指数、国债收益率等。可为单个或多个。
132
- event_date:事件发生日(注意时区的影响),以此日期为基期0,注意该日期可能在周末或假日。
133
- 注意:允许标注多个事件日,但仅以第一个事件日计算相关日期。
134
- start/end:展示事件影响的起止日期,至少需要将事件日、事件窗口和事件后窗口包括在内,主要用于绘图。
135
- 注意:如果不绘制AR仅绘制CAR,事件窗口前CAR均为空,start日期在绘图中将不起作用。
136
- event_window:事件窗口的起止日期,为相对事件日的相对日期
137
- 默认[0,0],即事件当日一天。注意窗口期不宜过长,因为过长的期间中可能混杂其他事件的影响。
138
- 注意:事件窗口不一定包括事件日(适用于事件日在非交易日的情形,例如周末或假日,或者在当日闭市后发生)
139
- 如果事件日为非交易日,事件窗口需要后移至事件日后的第一个交易日。
140
- 如果怀疑市场提前对事件发生反应,可以考虑前移事件窗口的开始日期。
141
- 使用CAR时,事件窗口长度一般为数日;使用BHAR时可长达数月。
142
- post_event_days:用于分析事件窗口后的漂移效应,取事件窗口后多少天。
143
- 默认不分析,取0天。可以指定天数,注意是否跨过非交易日情形,过长的窗口期也可能混杂其他事件的影响。
144
- method:估计事件窗口以及事件后窗口收益率预期值的方法
145
- 默认为CAPM(主要用于ticker为股票等),即通常所说的市场模型法。
146
- 如果ticker为股票等,也可直接使用指数收益率为其预期收益率,此时method为Market或Index,即常说的市场调整模型。
147
- 如果ticker为指数,无法再借助指数,method只能使用Random Walk,即使用前一个收益率为预期收益率。
148
- 注意:不管多个ticker时里面的不同证券类型,仅按第一个ticker的类型判断,并使用同一种证券类型。
149
- 使用CAR时,对每日异常收益率相加,反映短期逐日异常收益的累积;使用BHAR时则为复利累积,反映长期异常收益。
150
- early_response_days:默认为-2,即提前2天市场就开始有反应。
151
- 市场很可能对事件提前发生反应(因为泄密等原因),例如中国市场规定上市公司董事会开完后两天内必须披露。
152
- 很可能刚开完董事会,市场就得到了消息。为规避这种情况对估计窗口的影响,可以调节此参数。
153
- estimation_window_days:当method使用CAPM时,用于估计贝塔系数和截距项,以便计算预期收益率。
154
- 默认在事件窗口开始日期+提前反应天数前的365个自然日(约250个交易日)。
155
- market_index:当method为CAPM时,用于计算市场收益率。默认中国市场采用000300.SS。
156
- 注意:需要根据不同市场采取不同的市场指数,例如香港市场为恒生指数,美国市场为标普500指数等。
157
- RF:年化无风险收益率
158
- 默认使用市场模型"market index"自动计算,无需指定。
159
- 可直接指定具体数值。
160
- 也可指定特定指标替代,例如一年期中国国债收益率"1YCNY.B"或一年期美债收益率"1YUSY.B"等。
161
- ticker_type:显式指明ticker的证券类型,当siat误判其类型(中国内地股票/债券/基金)时使用,默认'auto'。
162
- show_RF:在使用市场模型或指定指标时是否显示计算出的RF均值,默认为False。
163
- show_AR:是否绘图时绘制异常收益率AR
164
- 默认'auto'(单个ticker时绘制,多个时不绘制)。
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
-
172
-
173
- 示例:美的收购库卡事件对股价的影响
174
- es=event_study(["000333.SZ"],
175
- event_date="2021-11-24",
176
- start='2021-11-20',end='2021-12-25',
177
- event_window=[1,10],
178
- post_event_days=15,
179
- method='CAPM',
180
- market_index='399001.SZ')
181
- """
182
-
183
- DEBUG=False
184
- DEBUG2=False
185
-
186
- #=====事件研究各个日期的计算与调整===========================================
187
- if isinstance(event_date,str):
188
- event_date=[date_adjust(event_date,adjust=0)]
189
- elif isinstance(event_date,list):
190
- event_date=[date_adjust(ed,adjust=0) for ed in event_date]
191
- else:
192
- print(" #Warning(event_study): invalid date or list of dates {}".format(event_date))
193
- return None
194
- event_date.sort() #升序排序
195
-
196
- #事件窗口日期:遇到周末需要调整,提前或顺延至最近的工作日
197
- event_window_new=event_window.copy() #列表的普通赋值仅为指针,新列表的改动也会影响原列表
198
- adjust_start=0
199
- event_window_start=date_adjust(event_date[0],adjust=event_window[0])
200
- if week_day(event_window_start) == 5: #周六
201
- if event_window[0] >= 0:
202
- adjust_start=2
203
- else:
204
- adjust_start=-1
205
- elif week_day(event_window_start) == 6: #周日
206
- if event_window[0] >= 0:
207
- adjust_start=1
208
- else:
209
- adjust_start=-2
210
- event_window_start=date_adjust(event_window_start,adjust=adjust_start)
211
- event_window_new[0]=event_window[0]+adjust_start
212
-
213
- adjust_end=0
214
- event_window_end=date_adjust(event_window_start,adjust=event_window[1]-event_window[0])
215
- if week_day(event_window_end) == 5: #周六
216
- if event_window[1] >= 0:
217
- adjust_end=2
218
- else:
219
- adjust_end=-1
220
- elif week_day(event_window_end) == 6: #周日
221
- if event_window[1] >= 0:
222
- adjust_end=1
223
- else:
224
- adjust_end=-2
225
- event_window_end=date_adjust(event_window_end,adjust=adjust_end)
226
- event_window_new[1]=event_window[1]+adjust_start+adjust_end
227
-
228
- if DEBUG:
229
- print(" DEBUG: event window is between {0} to {1}".format(event_window_start,event_window_end))
230
-
231
- if event_window_new != event_window:
232
- print(" #Notice: event window adjusted from {0} to {1} because of weekend".format(event_window,event_window_new))
233
-
234
- #事件后窗口日期
235
- post_event_start=date_adjust(event_window_end,adjust=0)
236
- if week_day(post_event_start) == 5: #周六
237
- post_event_start=date_adjust(post_event_start,adjust=2)
238
- elif week_day(post_event_start) == 6: #周日
239
- post_event_start=date_adjust(post_event_start,adjust=1)
240
-
241
- post_event_end=date_adjust(post_event_start,adjust=post_event_days)
242
- if week_day(post_event_end) == 5: #周六
243
- post_event_end=date_adjust(post_event_end,adjust=2)
244
- elif week_day(post_event_end) == 6: #周日
245
- post_event_end=date_adjust(post_event_end,adjust=1)
246
-
247
- if post_event_end > stoday:
248
- post_event_end = stoday
249
-
250
- if DEBUG:
251
- print(" DEBUG: post event window is between {0} to {1}".format(post_event_start,post_event_end))
252
-
253
-
254
- #事件窗口前日期
255
- event_eve_date=date_adjust(event_window_start,adjust=-1)
256
- if week_day(event_eve_date) == 5: #周六
257
- event_eve_date=date_adjust(event_eve_date,adjust=-1)
258
- elif week_day(event_eve_date) == 6: #周日
259
- event_eve_date=date_adjust(event_eve_date,adjust=-2)
260
-
261
- if DEBUG:
262
- print(" DEBUG: event eve is on {}".format(event_eve_date))
263
-
264
- #提前反应日期
265
- early_response_date=date_adjust(event_date[0],adjust=early_response_days)
266
- if week_day(early_response_date) == 5: #周六
267
- early_response_date=date_adjust(early_response_date,adjust=-1)
268
- elif week_day(early_response_date) == 6: #周日
269
- early_response_date=date_adjust(early_response_date,adjust=-2)
270
-
271
- if DEBUG:
272
- print(" DEBUG: early response started on {}".format(early_response_date))
273
-
274
- #估计窗口日期的计算
275
- est_window_end=date_adjust(early_response_date,adjust=-1)
276
- est_window_start=date_adjust(est_window_end,adjust=estimation_window_days)
277
- if DEBUG:
278
- print(" DEBUG: regression period starts from {0} to {1}".format(est_window_start,est_window_end))
279
-
280
- #处理绘图时显示的日期范围
281
- if start=='auto':
282
- start=date_adjust(early_response_date,adjust=-7)
283
- if end=='auto':
284
- if len(ticker) == 1 or show_AR:
285
- end=date_adjust(post_event_end,adjust=7)
286
- else:
287
- end=date_adjust(post_event_end,adjust=2)
288
-
289
- #=====判断ticker是否为指数,调整预期收益率计算方法============================
290
- if isinstance(ticker,str):
291
- ticker=[ticker]
292
- elif isinstance(ticker,list):
293
- ticker=ticker
294
- else:
295
- print(" #Warning(event_study): unexpected type of ticker {}".format(ticker))
296
- return None
297
-
298
- if market_index in ticker:
299
- print(" #Warning(event_study): market_index {0} duplicated in and removed from ticker {1}".format(market_index,ticker))
300
- ticker.remove(market_index)
301
-
302
- #tname=ticker_name(ticker[0],ticker_type)
303
- #检查ticker是否为指数或国债收益率
304
- """
305
- if ("指数" in tname or "index" in tname.lower()) or ("收益率" in tname or "yield" in tname.lower()):
306
- if not ("random" in method.lower() or "walk" in method.lower()):
307
- print(" #Notice: check the applicability of ticker {0}, method {1} with market index {2}".format(ticker[0],method,market_index))
308
- """
309
-
310
- #=====获取证券价格和/或相关指数数据==========================================
311
- #基于CAPM获取数据
312
- if 'capm' in method.lower():
313
- method_type="capm"
314
- df_ret=compare_msecurity(tickers=ticker+[market_index],measure=ret_type, \
315
- start=est_window_start,end=end, \
316
- ticker_type=ticker_type, \
317
- graph=False)
318
-
319
- if isinstance(RF,int) or isinstance(RF,float):
320
- #RF为具体数值
321
- RF_type="value"
322
-
323
- elif "market" in (str(RF)).lower() or "index" in (str(RF)).lower():
324
- #RF通过市场模型计算,无需指定
325
- RF_type="model"
326
- else:
327
- #指定RF代码,例如1YCNY.B,注意1:得到的是年化收益率%,注意2:中国的只有近一年的数据
328
- RF_type="code"
329
-
330
- if RF_type=="code":
331
- df_rf=compare_msecurity(tickers=RF,measure='Close', \
332
- start=est_window_start,end=end, \
333
- graph=False)
334
- RF=df_rf[list(df_rf)[0]].mean() / 100.0
335
-
336
- #基于市场指数获取数据
337
- elif 'market' in method.lower() or 'index' in method.lower():
338
- method_type="market"
339
- df_ret=compare_msecurity(tickers=ticker+[market_index],measure=ret_type, \
340
- start=est_window_start,end=end, \
341
- ticker_type=ticker_type, \
342
- graph=False)
343
-
344
- elif 'random' in method.lower() or 'walk' in method.lower():
345
- method_type="random"
346
- df_ret=compare_msecurity(tickers=ticker,measure=ret_type, \
347
- start=est_window_start,end=end, \
348
- ticker_type=ticker_type, \
349
- graph=False)
350
- for t in ticker_name(ticker,ticker_type):
351
- try:
352
- df_ret[t+"_predicted"]=df_ret[t].shift(1)
353
- except:
354
- #print(" #Warning(event_study): info not found for ticker {}".format(t))
355
- continue
356
-
357
- else:
358
- print(" #Warning(event_study): unexpected type of AR method {}".format(method))
359
- return None
360
-
361
- #=====计算异常收益率AR=====
362
- df_cols=list(df_ret)
363
- if method_type=='market':
364
- for t in ticker_name(ticker,ticker_type):
365
- try:
366
- df_ret[t+'_AR']=df_ret[t] - df_ret[ticker_name(market_index)]
367
- except: continue
368
-
369
- elif method_type=='random':
370
- for t in ticker_name(ticker,ticker_type):
371
- try:
372
- df_ret[t+'_AR']=df_ret[t] - df_ret[t+"_predicted"]
373
- except: continue
374
-
375
- else: #按CAPM计算
376
- #CAPM回归期间数据
377
- est_window_startpd=pd.to_datetime(est_window_start)
378
- est_window_endpd =pd.to_datetime(est_window_end)
379
- df_reg=df_ret[(df_ret.index >=est_window_startpd) & (df_ret.index <=est_window_endpd)].copy()
380
-
381
- #删除空缺值,否则回归会出错
382
- df_reg=df_reg.replace([np.nan, None], np.nan).dropna()
383
-
384
- import statsmodels.api as sm
385
- if RF_type in ["value","code"]:
386
- if not ("%" in ret_type): #注意:RF是年化收益率(需要转化为日收益率),这里不是百分比
387
- X=df_reg[ticker_name(market_index)] - RF/365.0 #无截距项回归,指定RF具体数值
388
- else:
389
- X=df_reg[ticker_name(market_index)] - RF/365.0 * 100.0 #这里需要转化为日收益率百分比%
390
-
391
- else: #RF_type=="model"
392
- X=df_reg[ticker_name(market_index)]
393
- X=sm.add_constant(X) #有截距项回归,基于市场模型
394
-
395
- if DEBUG:
396
- print(" DEBUG: method_type={0}, RF_type={1}, RF={2}".format(method_type,RF_type,RF))
397
-
398
- #CAPM回归
399
- beta_dict={}; intercept_dict={}; pvalue_dict={}; rf_dict={}
400
- for t in ticker_name(ticker,ticker_type):
401
- try:
402
- if RF_type in ["value","code"]:
403
- if not ("%" in ret_type): #注意:RF是年化收益率(需要转化为日收益率),不是百分比
404
- y=df_reg[t] - RF/365.0
405
- else:
406
- y=df_reg[t] - RF/365.0 * 100.0
407
-
408
- else: #RF_type=="model"
409
- y=df_reg[t]
410
- except: continue
411
-
412
- model = sm.OLS(y,X) #定义回归模型y=X
413
- results = model.fit() #进行OLS回归
414
-
415
- if DEBUG2:
416
- print(" DEBUG: RF_type={0}, results.params={1},results.pvalues={2}".format(RF_type,results.params,results.pvalues))
417
-
418
- #提取回归系数,详细信息见results.summary()
419
- if RF_type=="model":
420
- intercept=results.params[0]
421
- beta=results.params[1]; pvalue=results.pvalues[1]
422
- try:
423
- #此处回归得到的rf应该为日收益率,转为年化收益率。
424
- #注意:不同证券回归出的结果可能差异较大,原因可能是混入了回归残差!
425
- if not ("%" in ret_type):
426
- rf=intercept / (1-beta) * 365.0
427
- else:
428
- rf=intercept / (1-beta) / 100.0 * 365.0
429
- except: rf=0
430
-
431
- else: #RF_type in ["value","code"]
432
- intercept=0
433
- beta=results.params[0]; pvalue=results.pvalues[0]
434
- rf=RF
435
-
436
- beta_dict[t] = beta; intercept_dict[t] = intercept; pvalue_dict[t] = pvalue; rf_dict[t]=rf
437
- if DEBUG2:
438
- print(" DEBUG: t={0}, intercept={1}, beta={2}, pvalue={3}, annualized rf={4}".format(t,round(intercept,4),round(beta,4),round(pvalue,4),round(rf,4)))
439
-
440
- #计算收益率预期和AR
441
- for t in ticker_name(ticker,ticker_type):
442
- try:
443
- if RF_type in ["value","code"]:
444
- #CAPM模型:E(R) = RF + (Rm-RF)*beta
445
- RF_text=str(round(RF*100.0,4))[:6]+'%'
446
- if not ("%" in ret_type): #注意:RF是年化收益率,此处不是百分比
447
- df_ret[t+"_predicted"]=(df_ret[ticker_name(market_index)] - RF/365.0)*beta_dict[t] + RF/365.0
448
- else:
449
- df_ret[t+"_predicted"]=(df_ret[ticker_name(market_index)] - RF*100.0/365.0)*beta_dict[t] + RF*100.0/365.0
450
-
451
- else: #RF_type=="model"
452
- #市场模型:E(R) = intercept + Rm*beta
453
- RF_text="基于市场模型回归"
454
- df_ret[t+"_predicted"]=df_ret[ticker_name(market_index)]*beta_dict[t] + intercept_dict[t]
455
-
456
- df_ret[t+"_AR"]=df_ret[t] - df_ret[t+"_predicted"]
457
- except: continue
458
-
459
- if DEBUG2:
460
- print(" DEBUG: RF_type={0}, RF_text={1}, rf_dict={2}".format(RF_type,RF_text, rf_dict))
461
-
462
- #=====计算CAR和BHAR==============================================================
463
- for t in ticker_name(ticker,ticker_type):
464
- try:
465
- df_ret[t+"_CAR"]=0
466
- df_ret[t+"_BHAR"]=0
467
- except: continue
468
-
469
- event_window_startpd=pd.to_datetime(event_window_start)
470
- event_window_endpd=pd.to_datetime(event_window_end)
471
- post_event_endpd=pd.to_datetime(post_event_end)
472
- startpd=pd.to_datetime(start); endpd=pd.to_datetime(end)
473
-
474
- #计算CAR和BHAR
475
- df_ret_event=df_ret[(df_ret.index >=event_window_startpd) & (df_ret.index <=endpd)]
476
- for t in ticker_name(ticker,ticker_type):
477
- try:
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
482
- except: continue
483
-
484
- #合成事件前期间
485
- df_ret_before_event=df_ret[(df_ret.index >=startpd) & (df_ret.index < event_window_startpd)]
486
- for t in ticker_name(ticker,ticker_type):
487
- try:
488
- df_ret_before_event[t+'_CAR']=np.nan
489
- df_ret_before_event[t+'_BHAR']=np.nan
490
- except: continue
491
-
492
- df_show=pd.concat([df_ret_before_event,df_ret_event])
493
-
494
- #是否显示AR:默认单证券显示,多证券时不显示
495
- df_show_cols=[]
496
- for c in list(df_show):
497
- if show_AR=='auto':
498
- if len(ticker)==1:
499
- if 'AR' in c or 'CAR' in c:
500
- df_show_cols=df_show_cols+[c]
501
- show_AR=True
502
- else:
503
- if 'CAR' in c:
504
- df_show_cols=df_show_cols+[c]
505
- show_AR=False
506
- elif show_AR==True:
507
- if 'AR' in c or 'CAR' in c:
508
- df_show_cols=df_show_cols+[c]
509
- else: #show_AR==False
510
- if 'CAR' in c:
511
- df_show_cols=df_show_cols+[c]
512
-
513
- df_show2=df_show[df_show_cols]
514
-
515
- #=====绘图=================================================================
516
- #设置标签
517
- df0=df_show2
518
-
519
- y_label="收益率%"
520
-
521
- #横轴注释
522
- footnote1="首事件日{0},事件窗口{1},事件后窗口天数{2},市场提前反应天数{3}".format(event_date[0],event_window_new,post_event_days,early_response_days)
523
- footnote2="收益率类型:"+ectranslate(ret_type)
524
-
525
- if method_type == "market":
526
- method_name="市场指数基准"
527
- elif method_type == "random":
528
- method_name="随机漫步模型"
529
- else:
530
- method_name="CAPM模型"
531
-
532
- footnote3=",收益率预期方法:"+method_name
533
- if not method_type == "random":
534
- footnote4=',市场指数:'+ticker_name(market_index)
535
- else:
536
- footnote4=''
537
-
538
- #显著性检验:异于零的t检验,事件窗口
539
- df_event_window=df0[(df0.index >=event_window_start) & (df0.index <=event_window_end)]
540
- #footnote5="事件窗口CAR(终值,p值):"
541
- footnote5="事件窗口CAR(终值,均值,中位数,p值):"
542
- for c in list(df_event_window):
543
- if 'CAR' in c.upper():
544
- c_name=c[:-4]
545
-
546
- event_window_endpd=pd.to_datetime(event_window_end)
547
- #car_value=df_event_window[df_event_window.index == event_window_endpd][c].values[0]
548
- car_value=df_event_window[c][-1]
549
- car_mean=df_event_window[c].mean()
550
- car_median=df_event_window[c].median()
551
-
552
- if car_value > 0:
553
- car_value_str=str(round(car_value,4))[:6]
554
- else:
555
- car_value_str=str(round(car_value,4))[:7]
556
-
557
- if car_mean > 0:
558
- car_mean_str=str(round(car_mean,4))[:6]
559
- else:
560
- car_mean_str=str(round(car_mean,4))[:7]
561
-
562
- if car_median > 0:
563
- car_median_str=str(round(car_median,4))[:6]
564
- else:
565
- car_median_str=str(round(car_median,4))[:7]
566
-
567
- if len(df_event_window[c])==1:
568
- if abs(df_event_window[c].values[0]) > 0.01:
569
- p_value=0.0
570
- else:
571
- p_value=1.0
572
- else:
573
- p_value=ttest(df_event_window[c],0)
574
- if p_value > 0:
575
- p_value_str=str(round(p_value,4))[:6]
576
- else:
577
- p_value_str=str(round(p_value,4))[:7]
578
- #footnote5=footnote5+c_name+p_value_str+","
579
- #footnote5=footnote5+"{0}({1}, {2}), ".format(c_name,car_value_str,p_value_str)
580
- footnote5=footnote5+"{0}({1}, {2}, {3}, {4}), ".format(c_name,car_value_str,car_mean_str, \
581
- car_median_str,p_value_str)
582
-
583
- if 'BHAR' in c.upper():
584
- bhar_value=df_event_window[c][-1]
585
- if bhar_value > 0:
586
- bhar_value_str=str(round(bhar_value,4))[:6]
587
- else:
588
- bhar_value_str=str(round(bhar_value,4))[:7]
589
-
590
- if show_BHAR:
591
- footnote5=footnote5+"BHAR终值: {0}; ".format(bhar_value_str)
592
-
593
- footnote5=footnote5.strip(", "); footnote5=footnote5.strip("; ")
594
-
595
- #显著性检验:异于零的t检验,事件后窗口
596
- df_post_event_window=df0[(df0.index >event_window_end) & (df0.index <=post_event_end)]
597
- if len(df_post_event_window) == 0:
598
- footnote6=''
599
- elif len(df_post_event_window) == 0:
600
- footnote6=''
601
- else:
602
- #footnote6="事件后窗口CAR(终值,p值):"
603
- footnote6="事件后窗口CAR(终值,均值,中位数,p值):"
604
- for c in list(df_post_event_window):
605
- if 'CAR' in c.upper():
606
- c_name=c[:-4]
607
- post_event_endpd=pd.to_datetime(post_event_end)
608
- if DEBUG2:
609
- print(" DEBUG: c={0},post_event_end={1},df_post_event_window={2}".format(c,post_event_end,df_post_event_window))
610
- #car_value=df_post_event_window[df_post_event_window.index == post_event_endpd][c].values[0]
611
- car_value=df_post_event_window[c][-1]
612
- car_mean=df_post_event_window[c].mean()
613
- car_median=df_post_event_window[c].median()
614
-
615
- if car_value > 0:
616
- car_value_str=str(round(car_value,4))[:6]
617
- else:
618
- car_value_str=str(round(car_value,4))[:7]
619
-
620
- if car_mean > 0:
621
- car_mean_str=str(round(car_mean,4))[:6]
622
- else:
623
- car_mean_str=str(round(car_mean,4))[:7]
624
-
625
- if car_median > 0:
626
- car_median_str=str(round(car_median,4))[:6]
627
- else:
628
- car_median_str=str(round(car_median,4))[:7]
629
-
630
- if len(df_post_event_window[c])==1:
631
- if abs(df_post_event_window[c].values[0]) > 0.01:
632
- p_value=0.0
633
- else:
634
- p_value=1.0
635
- else:
636
- p_value=ttest(df_post_event_window[c],0)
637
- if p_value > 0:
638
- p_value_str=str(round(p_value,4))[:6]
639
- else:
640
- p_value_str=str(round(p_value,4))[:7]
641
-
642
- #footnote6=footnote6+c[:-4]+str(p_value)[:6]+","
643
- footnote6=footnote6+"{0}({1}, {2}, {3}, {4}), ".format(c_name,car_value_str,car_mean_str,car_median_str,p_value_str)
644
-
645
- if 'BHAR' in c.upper():
646
- bhar_value=df_post_event_window[c][-1]
647
- if bhar_value > 0:
648
- bhar_value_str=str(round(bhar_value,4))[:6]
649
- else:
650
- bhar_value_str=str(round(bhar_value,4))[:7]
651
-
652
- if show_BHAR:
653
- footnote6=footnote6+"BHAR终值: {0}; ".format(bhar_value_str)
654
-
655
- footnote6=footnote6.strip(", "); footnote6=footnote6.strip("; ")
656
-
657
- footnote7="数据来源:Sina/EM/Yahoo/Stooq/SWHY,"+stoday
658
-
659
- #x_label=footnote1+'\n'+footnote2+footnote3+footnote4+'\n'+footnote5+'\n'+footnote6+'\n'+footnote7
660
- x_label=footnote1+'\n'+footnote2+footnote3+footnote4+'\n'+footnote7
661
-
662
-
663
- axhline_value=0
664
- axhline_label="零线"
665
- title_txt="事件影响分析:"
666
- for t in ticker_name(ticker,ticker_type):
667
- title_txt=title_txt+t+','
668
- title_txt=title_txt.strip(",")
669
-
670
- #判断最新可获得日期
671
- last_date=df0.index[-1].strftime("%Y-%m-%d")
672
- if DEBUG:
673
- print(" DEBUG: last_date={}".format(last_date))
674
- if post_event_end > last_date:
675
- post_event_end = last_date
676
-
677
- if event_window_new[0] != event_window_new[1]:
678
- attention_point_area=[event_window_start,event_window_end]
679
- else:
680
- attention_point_area=[event_window_start,post_event_end]
681
-
682
- #去掉重复日期项标注且不改变顺序
683
- event_date_new=[]
684
- for d in event_date:
685
- d_new=date_adjust(d,adjust=0)
686
- event_date_new=event_date_new+[d_new]
687
-
688
- attention_point=[event_eve_date,event_window_start,event_window_end,post_event_end]+event_date_new
689
- if not show_AR:
690
- period_days=calculate_days(event_eve_date,post_event_end)
691
- if DEBUG:
692
- print(" DEBUG: period_days={}".format(period_days))
693
-
694
- if period_days< 6:
695
- #绘图时横轴若少于6天会出现时间刻度,易误导需避免
696
- draw_start_date=date_adjust(event_eve_date,adjust=period_days-6)
697
- attention_point=[draw_start_date,event_window_start,event_window_end,post_event_end]+event_date_new
698
- """
699
- if show_AR:
700
- attention_point=[event_eve_date,event_window_start,event_window_end,post_event_end]+event_date_new
701
- else:
702
- attention_point=[event_eve_date,event_window_start,event_window_end,post_event_end]+event_date_new
703
- df0=df0[(df0.index >= start) & (df0.index <=post_event_end)]
704
- """
705
- attention_point.sort(reverse=False)
706
- attention_point=list({}.fromkeys(attention_point).keys())
707
-
708
- # 是否绘制CAR或BHAR曲线:对于短期窗口,CAR曲线和BHAR曲线很可能基本重合,建议仅绘制其中之一!
709
- df0draw=df0.copy()
710
- for c in list(df0draw):
711
- if not draw_CAR and 'CAR' in c:
712
- del df0draw[c]
713
- if not draw_BHAR and 'BHAR' in c:
714
- del df0draw[c]
715
-
716
- #绘图
717
- draw_lines(df0draw,y_label,x_label,axhline_value,axhline_label,title_txt, \
718
- data_label=False, \
719
- loc=loc,resample_freq='D',smooth=False, \
720
- annotate=True,annotate_value=False, \
721
- attention_point=attention_point, \
722
- attention_point_area=attention_point_area, \
723
- ticker_type=ticker_type,facecolor=facecolor)
724
-
725
- #=====输出AR和/或CAR或BHAR表格====================================================
726
- df1=df0.copy()
727
- #df1=df1.replace([np.nan, None], np.nan).dropna()
728
- df1=df1.replace([np.nan, None],'-')
729
- df1["日期"]=df1.index
730
- df1["日期"]=df1["日期"].apply(lambda x: x.strftime("%Y-%m-%d"))
731
-
732
- df1=df1[(df1["日期"] >= event_date[0]) & (df1["日期"] <= post_event_end)]
733
- df1["星期"]=df1["日期"].apply(lambda x: week_day(x)+1)
734
-
735
- df1["事件标记"]=''
736
- for d in event_date_new:
737
- if len(event_date_new)==1:
738
- event_text="事件日"
739
- else:
740
- pos=event_date_new.index(d)
741
- if pos==1:
742
- event_text="首事件日"
743
- else:
744
- event_text="事件日"+str(pos+1)
745
- df1["事件标记"]=df1.apply(lambda x: event_text if x["日期"]==d else x["事件标记"],axis=1)
746
-
747
- #event_text=",事件窗口开始日"
748
- event_text="\n事件窗开始"
749
- df1["事件标记"]=df1.apply(lambda x: x["事件标记"]+event_text if x["日期"]==event_window_start else x["事件标记"],axis=1)
750
- #event_text=",事件窗口结束日"
751
- event_text="\n事件窗结束"
752
- df1["事件标记"]=df1.apply(lambda x: x["事件标记"]+event_text if x["日期"]==event_window_end else x["事件标记"],axis=1)
753
-
754
- #event_text=",事件后窗口结束日"
755
- if post_event_end > event_window_end:
756
- event_text="\n事件后窗结束"
757
- df1["事件标记"]=df1.apply(lambda x: x["事件标记"]+event_text if x["日期"]==post_event_end else x["事件标记"],axis=1)
758
-
759
- event_text="\n事件窗"
760
- df1["事件标记"]=df1.apply(lambda x: x["事件标记"]+event_text if (x["日期"] > event_window_start) and (x["日期"] < event_window_end) else x["事件标记"],axis=1)
761
-
762
- event_text="\n事件后窗"
763
- df1["事件标记"]=df1.apply(lambda x: x["事件标记"]+event_text if (x["日期"] > event_window_end) and (x["日期"] < post_event_end) else x["事件标记"],axis=1)
764
-
765
- df1["事件标记"]=df1["事件标记"].apply(lambda x: x.strip('\n'))
766
-
767
- #显示表格
768
- df0_list=list(df0)
769
- df1_list=["事件标记","日期","星期"]+df0_list
770
- df1=df1[df1_list]
771
- #title_txt=title_txt+",窗口收益率"
772
-
773
- if "CAPM" in method.upper():
774
- footnotex="CAPM回归期间:{0}至{1},无风险收益率{2}".format(est_window_start,est_window_end,RF_text)
775
- footnotey="CAPM贝塔系数:"
776
- for k in beta_dict:
777
- footnotey=footnotey+k+str(round(beta_dict[k],4))[:6]+","
778
- footnotey=footnotey.strip(",")
779
-
780
- if show_RF:
781
- footnotez="无风险收益率均值:"
782
- for r in rf_dict:
783
- footnotez=footnotez+r+str(round(rf_dict[r]*100.0,4))[:6]+"%, "
784
-
785
- footnotez=footnotez.strip(", ")
786
- footnote=footnote2+footnote3+footnote4+'\n'+footnotex+'\n'+footnotey+'\n'+footnotez+'\n'+footnote5+'\n'+footnote6
787
- else:
788
- footnote=footnote2+footnote3+footnote4+'\n'+footnotex+'\n'+footnotey+'\n'+footnote5+'\n'+footnote6
789
- else:
790
- footnote=footnote2+footnote3+footnote4+'\n'+footnote5+'\n'+footnote6
791
-
792
- for c in list(df1):
793
- if not show_BHAR and 'BHAR' in c:
794
- del df1[c]
795
-
796
- #显示结果表格
797
- df_display_CSS(df1,titletxt=title_txt,footnote=footnote,facecolor=facecolor,decimals=4, \
798
- first_col_align='left',second_col_align='left', \
799
- last_col_align='center',other_col_align='center')
800
-
801
-
802
- return df_show2
803
-
804
-
805
-
806
-
807
-
808
-
809
-
810
-
811
-
812
-
813
-
814
-
815
-