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,811 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- """
3
- 本模块功能:SIAT公共转换函数,获取雅虎证券代码英文名称
4
- 所属工具包:证券投资分析工具SIAT
5
- SIAT:Security Investment Analysis Tool
6
- 创建日期:2024年7月12日
7
- 最新修订日期:
8
- 作者:王德宏 (WANG Dehong, Peter)
9
- 作者单位:北京外国语大学国际商学院
10
- 作者邮件:wdehong2000@163.com
11
- 版权所有:王德宏
12
- 用途限制:仅限研究与教学使用,不可商用!商用需要额外授权。
13
- 特别声明:作者不对使用本工具进行证券投资导致的任何损益负责!
14
- """
15
- #==============================================================================
16
- #关闭所有警告
17
- import warnings; warnings.filterwarnings('ignore')
18
-
19
- #==============================================================================
20
- if __name__=='__main__':
21
- test_yahoo_access()
22
-
23
- def test_yahoo_access():
24
- """
25
- 功能:测试雅虎财经是否可达
26
- """
27
- url="https://finance.yahoo.com/"
28
- result=test_website(url)
29
-
30
- return result
31
-
32
- if __name__=='__main__':
33
- url="https://finance.yahoo.com"
34
- test_website(url)
35
-
36
- def test_website(url):
37
- import requests
38
- headers = {
39
- "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"
40
- }
41
- try:
42
- response = requests.get(url,headers=headers)
43
- if response.status_code == 200:
44
- #print(f"Website {url} is accessible")
45
- return True
46
- else:
47
- #print(f"Website {url} access failed,Code:{response.status_code}")
48
- return False
49
- except requests.exceptions.RequestException:
50
- print(f" #Warning: website {url} is inaccessible")
51
- return False
52
-
53
- if __name__=='__main__':
54
- s = "Hello, world. Python is fun!"
55
- split_string(s)
56
-
57
- def split_string(s):
58
- import re
59
- # 使用正则表达式匹配空格、逗号或句点
60
- return re.split(r'[ ,.]', s)
61
-
62
- if __name__=='__main__':
63
- s = "Hello, world. Python is fun!"
64
- filter_string(s)
65
-
66
- def filter_string(s):
67
- #排除证券名称中的多余空格、逗号和句号
68
- slist=split_string(s)
69
- s1=''
70
- for sl in slist:
71
- if sl != '':
72
- if s1=='':
73
- s1=sl
74
- else:
75
- s1=s1+' '+sl
76
-
77
- return s1
78
- #==============================================================================
79
- if __name__=='__main__':
80
- ticker='1155.KL'
81
- ticker='MSFT'
82
- ticker='G13.SI'
83
- ticker='S63.SI'
84
- ticker='SUS.ST'
85
- ticker='600519.SS'
86
- ticker='U11.SI'
87
- ticker='1295.KL'
88
- ticker='BMW.DE'
89
- ticker='MBG.DE'
90
- ticker='005930.KS'
91
- ticker='LI'
92
- ticker='600599.SS'
93
- ticker='600123.SS'
94
- ticker='600123.ss'
95
- ticker='600999.ss'
96
- ticker='600111.ss'
97
- ticker='600333.ss'
98
- ticker='600444.ss'
99
- ticker='600777.ss'
100
- ticker='GC=F'
101
-
102
- yahoo_name1(ticker)
103
-
104
- #极端测试
105
- inamelist=[]
106
- for i in range(100,150+1):
107
- icode=str(600000+i)+'.SS'
108
- iname=yahoo_name1(icode)
109
- print(icode+':',iname)
110
- inamelist=inamelist+[iname]
111
-
112
- #发现问题后单独测试
113
- ticker='600087.SS'
114
- yahoo_name1(ticker)
115
-
116
- yahoo_name1(ticker,short_name=True)
117
-
118
- ticker_name(ticker)
119
-
120
- def yahoo_name1x(ticker,short_name=False,add_suffix=True,maxlen=80):
121
- """
122
- 功能:从雅虎财经取得全球证券名称,仅限英文。需要去掉常用词,如Corporation
123
- 优点:对未定义的证券代码也可给出英文名称,即使在中文语言环境中
124
- 现存问题:需要访问雅虎,且耗时稍长
125
- 废弃!!!
126
- """
127
- #测试雅虎
128
- if not test_yahoo_access():
129
- return ticker
130
-
131
- #需要去掉的单词,注意顺序不要轻易颠倒!子串包含的,要长文在前!
132
- remove_list=['Corporation','Berhad','Bhd','PLC','plc','Plc', \
133
- ', Inc.','Inc.', \
134
- 'AG ST','AG','NA O.N.', \
135
- 'Aktiengesellschaft','(publ)', \
136
- ', LLC','LLC', \
137
- 'Co., Ltd.','Co., Ltd','Co.,Ltd.','Co.,Ltd','Co,.Ltd','co.,ltd', \
138
- 'Co. LTD','CO.,LTD','Co., Limited', \
139
- 'Ltd.','Ltd', \
140
- 'Company', \
141
- 'Incorporated', \
142
- 'Corp., Ltd.','Corp.','Corp','AB', \
143
- 'Limited', \
144
-
145
- #强行缩短名称长度,去掉不影响名称的花哨词语
146
- '(Group)','Group', \
147
- 'Science & Technology','High-Tech','High Technology', \
148
-
149
- #扫尾漏网之逗号句点
150
- '.',',']
151
-
152
- """
153
- remove_list=['Corporation','Berhad','Bhd','PLC','plc','Limited', \
154
- 'Inc', \
155
- 'AG ST','AG','NA O.N.', \
156
- 'Aktiengesellschaft','(publ)', \
157
- 'LLC', \
158
- 'Co., Ltd.','Ltd.','Ltd', \
159
- 'Company', \
160
- 'Incorporated','Corp.','AB']
161
- """
162
- #去掉ticker中的.US后缀
163
- ticker=ticker.upper()
164
- ticker1=ticker.replace('.US', "")
165
-
166
- import yfinance as yf
167
- ticker_info = yf.Ticker(ticker1)
168
-
169
- try:
170
- t_info=ticker_info.info
171
- except:
172
- pass
173
- return ticker
174
-
175
- try:
176
- if short_name:
177
- t_name0=t_info['shortName']
178
- else:
179
- t_name0=t_info['longName']
180
- if len(t_name0) > maxlen:
181
- t_name0=t_info['shortName']
182
- except:
183
- pass
184
- return ticker #未找到ticker
185
-
186
- #过滤逗号句点?过滤也可能带来更多复杂性!
187
- #t_name1=filter_string(t_name0)
188
- t_name1=t_name0
189
-
190
- for r in remove_list:
191
- t_name1=t_name1.replace(r, "")
192
-
193
- #排除前后空格
194
- t_name=t_name1.strip()
195
-
196
- #增加交易所后缀
197
- if add_suffix:
198
- tlist=ticker.split('.')
199
- if len(tlist)==2:
200
- sid=tlist[1]
201
- if sid not in ['SS','SZ','BJ']:
202
- t_name=t_name+'('+sid+')'
203
-
204
- return t_name
205
-
206
- #==============================================================================
207
- def replace_multiple_spaces(s):
208
- import re
209
- return re.sub(r'\s+', ' ', s)
210
-
211
- #==============================================================================
212
- if __name__=='__main__':
213
- ticker='1155.KL'
214
- ticker='MSFT'
215
- ticker='G13.SI'
216
- ticker='S63.SI'
217
- ticker='SUS.ST'
218
- ticker='600519.SS'
219
- ticker='U11.SI'
220
- ticker='1295.KL'
221
- ticker='BMW.DE'
222
- ticker='MBG.DE'
223
- ticker='005930.KS'
224
- ticker='LI'
225
- ticker='600599.SS'
226
- ticker='600123.SS'
227
- ticker='600123.ss'
228
- ticker='600999.ss'
229
- ticker='600111.ss'
230
- ticker='600333.ss'
231
- ticker='600444.ss'
232
- ticker='600777.ss'
233
- ticker='CPL.WA'
234
-
235
- ticker='SWMCX'
236
-
237
- yahoo_name1(ticker)
238
-
239
- #极端测试
240
- inamelist=[]
241
- for i in range(0,50+1):
242
- icode=str(600000+i)+'.SS'
243
- iname=yahoo_name2(icode)
244
- print(icode+':',iname)
245
- inamelist=inamelist+[iname]
246
-
247
- #发现问题后单独测试
248
- ticker='600088.SS'
249
- ticker="ALI=F"
250
- ticker="ZS=F"
251
- ticker="ES=F"
252
-
253
- ticker_info(ticker)
254
-
255
- yahoo_name1(ticker)
256
- yahoo_name2(ticker)
257
-
258
- yahoo_name2(ticker,short_name=True)
259
-
260
- ticker_name(ticker)
261
-
262
- numeric_to_date(1734652800)
263
-
264
- def numeric_to_date(numeric):
265
- # 数值转日期
266
- from datetime import datetime, timedelta
267
- epoch = datetime(1970, 1, 1)
268
- return (epoch + timedelta(seconds=numeric)).strftime('%Y-%m-%d')
269
-
270
- if __name__=='__main__':
271
- ticker="ES=F" #期货
272
- ticker="VIX241120C00035000" #期权
273
-
274
- ticker_info(ticker, info="interest")
275
- ticker_info(ticker, info="open interest")
276
- ticker_info(ticker, info="volume")
277
- ticker_info(ticker, info="average volume")
278
- ticker_info(ticker, info="REGULAR CLOSE")
279
- ticker_info(ticker, info="day average")
280
-
281
- ticker_info(ticker, info=["regular close","fifty day average","two hundred day average"])
282
-
283
- def ticker_info(ticker,info="all"):
284
- """
285
-
286
- 功能:显示yahoo证券代码的信息,可多个信息类型
287
- """
288
- if isinstance(info,str):
289
- infos=[info]
290
- elif isinstance(info,list):
291
- infos=info
292
- else:
293
- print(" Sorry, unsupported info type:",info)
294
- return
295
-
296
- first_time=True
297
- for i in infos:
298
- if first_time:
299
- ticker_info1(ticker,info=i,test_access=True,print_title=True)
300
- first_time=False
301
- else:
302
- ticker_info1(ticker,info=i,test_access=False,print_title=False)
303
-
304
- return
305
-
306
- if __name__=='__main__':
307
- ticker="TSLA260618C00330000"
308
-
309
- ticker_info1(ticker)
310
- ticker_info1(ticker, info="open interest")
311
-
312
- def ticker_info1(ticker,info="all",test_access=True,print_title=True):
313
- """
314
-
315
- 功能:显示yahoo证券代码的信息,1个信息类型
316
- """
317
- #测试雅虎
318
- if test_access:
319
- if not test_yahoo_access():
320
- print(" Sorry, data source Yahoo is currently not reachable")
321
- return
322
-
323
- #去掉ticker中的.US后缀
324
- ticker=ticker.upper()
325
- ticker1=ticker.replace('.US', "")
326
-
327
- import yfinance as yf
328
- ticker_info = yf.Ticker(ticker1)
329
-
330
- import datetime
331
- stoday = datetime.date.today().strftime("%Y-%m-%d")
332
-
333
- info_list=info.split(); found=False
334
- """
335
- info_yahoo=(info_list[0]).lower()
336
- for i in info_list[1:]:
337
- info_yahoo=info_yahoo+(i.lower()).capitalize()
338
- """
339
-
340
- try:
341
- t_info=ticker_info.info
342
-
343
- if print_title:
344
- print("*** Ticker",ticker,'Information @'+stoday)
345
-
346
- if ('all' in info) or ('All' in info) or ('ALL' in info):
347
- for k in t_info.keys():
348
- if not 'Date' in k:
349
- print(' '+k+':',t_info[k])
350
- else:
351
- print(' '+k+':',numeric_to_date(t_info[k]))
352
- #display(t_info)
353
- else:
354
- for k in t_info.keys():
355
- for i in info_list:
356
- if (not i.lower() in k) and (not (i.lower()).capitalize() in k):
357
- found=False; break
358
- else:
359
- found=True
360
- if not found: continue
361
-
362
- if not 'Date' in k:
363
- print(' '+k+':',t_info[k])
364
- else:
365
- print(' '+k+':',numeric_to_date(t_info[k]))
366
-
367
- except:
368
- print(" Sorry, ticker",ticker,"is not found in data source Yahoo")
369
-
370
- return
371
-
372
-
373
- if __name__=='__main__':
374
- ticker="SGC=F"
375
- ticker="XAUUSD"
376
- short_name=False;add_suffix=True;maxlen=80
377
-
378
- yahoo_name1y(ticker)
379
-
380
- def yahoo_name1y(ticker,short_name=False,add_suffix=True,maxlen=80):
381
- """
382
- 功能:从雅虎财经取得全球证券名称,仅限英文。需要去掉常用词,如Corporation
383
- 优点:对未定义的证券代码也可给出英文名称,即使在中文语言环境中
384
- 现存问题:需要访问雅虎,且耗时稍长;当ticker不存在时会提示一大堆错误信息
385
- 仅作备用
386
- """
387
-
388
- #测试雅虎
389
- if not test_yahoo_access():
390
- return ticker
391
-
392
- #去掉ticker中的.US后缀
393
- ticker=ticker.upper()
394
- ticker1=ticker.replace('.US', "")
395
-
396
- import yfinance as yf
397
- ticker_info = yf.Ticker(ticker1)
398
-
399
- import os, sys
400
- class HiddenPrints:
401
- def __enter__(self):
402
- self._original_stdout = sys.stdout
403
- sys.stdout = open(os.devnull, 'w')
404
-
405
- def __exit__(self, exc_type, exc_val, exc_tb):
406
- sys.stdout.close()
407
- sys.stdout = self._original_stdout
408
-
409
- try:
410
- with HiddenPrints():
411
- t_info=ticker_info.info
412
- except:
413
- pass
414
- return ticker
415
-
416
- try:
417
- if short_name:
418
- try:
419
- t_name0=t_info['shortName']
420
- except:
421
- t_name0=t_info['longName']
422
- else:
423
- try:
424
- t_name0=t_info['longName']
425
- except:
426
- try:
427
- t_name0=t_info['shortName']
428
- except:
429
- pass
430
- return ticker
431
-
432
-
433
- if len(t_name0) > maxlen:
434
- t_name0=t_info['shortName']
435
- except:
436
- pass
437
- return ticker #未找到ticker
438
-
439
- #过滤名称中多余的尾部词汇
440
- t_name=filter_stock_name(t_name0)
441
-
442
- #增加交易所后缀
443
- if add_suffix:
444
- tlist=ticker.split('.')
445
- if len(tlist)==2:
446
- sid=tlist[1]
447
- if sid not in ['SS','SZ','BJ']:
448
- t_name=t_name+'('+sid+')'
449
-
450
- return t_name
451
-
452
- #==============================================================================
453
- if __name__ == '__main__':
454
- stock_code='KSL.AX'
455
- stock_code='AAPL'
456
- stock_code='600519.SS'
457
- stock_code='6758.T'
458
- stock_code='6758.JP'
459
- stock_code='ULVR.L'
460
- stock_code='ULVR.UK'
461
-
462
- stock_code='1155.KL'
463
- stock_code='MSFT'
464
-
465
- stock_code='SWMCX'
466
- stock_code='SGC=F'
467
-
468
- yahoo_name1_direct(stock_code)
469
-
470
-
471
- def yahoo_name1_direct(stock_code,add_suffix=True):
472
- """
473
- 功能:网页直接抓取,有的带后缀的股票代码可能失败,原因未知
474
- """
475
- import requests
476
- from bs4 import BeautifulSoup
477
-
478
- stock_code1=stock_code.upper()
479
-
480
- #抓取证券名称
481
- headers = {
482
- "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"
483
- }
484
- # https://finance.yahoo.com/quote/SWMCX/
485
- url = f"https://finance.yahoo.com/quote/{stock_code1}/"
486
- response = requests.get(url,headers=headers)
487
- if response.status_code == 200:
488
- soup = BeautifulSoup(response.text, 'html.parser')
489
- soup_title=soup.title
490
- soup_text=soup_title.text
491
- soup_text_list=soup_text.split('(')
492
-
493
- t_name = soup_text_list[0].strip()
494
- else:
495
- #未找到证券代码
496
- pass
497
- return stock_code
498
-
499
- #过滤名称中多余的尾部词汇
500
- t_name=filter_stock_name(t_name)
501
-
502
-
503
- return t_name
504
- #==============================================================================
505
- if __name__=='__main__':
506
- original_name='Oponeo.pl SA'
507
- original_name='Apple Inc'
508
- original_name='Schwab US Mid-Cap Index'
509
-
510
- original_name='Shanghai Gold (CNH) Futures,Apr'
511
-
512
- filter_stock_name(original_name)
513
-
514
- def filter_stock_name(original_name):
515
- """
516
- 功能:过滤从网站上抓取到的证券名称,去掉尾部的公司类别词汇,缩短长度,便于显示
517
- """
518
-
519
- #将字符串中的多个空格变为单个空格
520
- original_name=replace_multiple_spaces(original_name)
521
-
522
- #定义需要去掉的单词,注意顺序不要轻易颠倒!子串包含的,要长文在前!前置留空格的为避免误删
523
- remove_list=[' CORPORATION',' BERHAD',' BHD',' PLC',' INC',' AG ST',' NA O N', \
524
- ' AKTIENGESELLSCHAFT','(PUBL)',' LLC', \
525
- ' CO LTD',' CO LIMITED',' LTD',' LIMITED',' COMPANY',' INCORPORATED', \
526
- ' CORP LTD',' CORP',' AB',' CO', \
527
- ' GROUP CO','(GROUP)',' GROUP', \
528
- ' PL S A',' PL SA',' AG', \
529
- ' SCIENCE & TECHNOLOGY',' HIGH-TECH',' HIGH TECHNOLOGY', \
530
-
531
- ' APR',' MAY',' JUN',' JUL',' AUG',' SEP',' SEPT',' OCT',' NOV',' DEC',
532
- ' JAN',' FEB',' MAR',
533
-
534
- ]
535
-
536
- #去掉逗号和句点
537
- name1=original_name.replace(',',' ')
538
- name1=name1.replace(' ',' ')
539
- name2=name1.replace('.',' ')
540
-
541
- #将字符串字母全部大写
542
- name4=name2.upper()
543
-
544
- name5=name4
545
- for ss in remove_list:
546
- name5=name5.replace(ss,'')
547
-
548
- name6=name5.strip()
549
-
550
- name7=original_name[:len(name6)+1]
551
- name7=name7.replace(',','').replace('.','')
552
-
553
- shorter_name=name7
554
- return shorter_name
555
-
556
-
557
- #==============================================================================
558
- if __name__ == '__main__':
559
- stock_code='OPN.PL'
560
- stock_code='AAPL'
561
- stock_code='600519.SS'
562
- stock_code='6758.T'
563
- stock_code='6758.JP'
564
- stock_code='ULVR.L'
565
- stock_code='ULVR.UK'
566
-
567
- stock_code='1155.KL'
568
- stock_code='MSFT'
569
-
570
- stock_code='GC.F'
571
- stock_code='XAUUSD'
572
-
573
- stooq_name1(stock_code)
574
-
575
-
576
- def stooq_name1(stock_code,add_suffix=True):
577
-
578
- import requests
579
- from bs4 import BeautifulSoup
580
-
581
- stock_code1=stock_code.lower()
582
-
583
- #美股:尾部增加.us
584
- stock_code_list=stock_code1.split('.')
585
- if len(stock_code_list)==1:
586
- stock_code1=stock_code1+'.us'
587
-
588
- #其他国家股票
589
- if len(stock_code_list)==2:
590
- code=stock_code_list[0]
591
- sid=stock_code_list[1]
592
-
593
- #中国股票:尾部变为.cn
594
- if sid in ['ss','sz','bj']:
595
- stock_code1=code+'.cn'
596
-
597
- #日本股票:尾部变为.jp
598
- if sid in ['t']:
599
- stock_code1=code+'.jp'
600
-
601
- #英国股票:尾部变为.uk
602
- if sid in ['l']:
603
- stock_code1=code+'.uk'
604
-
605
- #XX国股票
606
-
607
- #波兰股票:去掉尾部.PL
608
- stock_code1=stock_code1.replace('.pl','')
609
-
610
- #抓取证券名称
611
- headers = {
612
- "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"
613
- }
614
- url = f"https://stooq.com/q/?s={stock_code1}"
615
- response = requests.get(url,headers=headers)
616
- if response.status_code == 200:
617
- soup = BeautifulSoup(response.text, 'html.parser')
618
- soup_title=soup.title
619
- soup_text=soup_title.text
620
- soup_text_list=soup_text.split(' - ')
621
-
622
- t_name = soup_text_list[1].strip()
623
- else:
624
- pass
625
- return stock_code
626
-
627
- #未找到证券代码
628
- if t_name == 'Stooq':
629
-
630
- #尝试不加后缀'.us'
631
- url = f"https://stooq.com/q/?s={stock_code}"
632
- response = requests.get(url,headers=headers)
633
- if response.status_code == 200:
634
- soup = BeautifulSoup(response.text, 'html.parser')
635
- soup_title=soup.title
636
- soup_text=soup_title.text
637
- soup_text_list=soup_text.split(' - ')
638
-
639
- t_name = soup_text_list[1].strip()
640
- else:
641
- pass
642
- return stock_code
643
-
644
- if t_name == 'Stooq':
645
- return stock_code
646
-
647
- #过滤名称中多余的尾部词汇
648
- t_name=filter_stock_name(t_name)
649
-
650
- #增加交易所后缀
651
- if add_suffix:
652
- tlist=stock_code1.split('.')
653
- if len(tlist)==1: sid='PL'
654
- if len(tlist)==2:
655
- sid=tlist[1].upper()
656
-
657
- if sid not in ['CN','US']:
658
- t_name=t_name+'('+sid+')'
659
-
660
- t_name=t_name.strip()
661
-
662
- return t_name
663
-
664
- #==============================================================================
665
- #==============================================================================
666
- if __name__ == '__main__':
667
- stock_code='AAPL'
668
- stock_code='600519.SS'
669
- stock_code='6758.T'
670
- stock_code='6758.JP'
671
- stock_code='ULVR.L'
672
- stock_code='1155.KL'
673
- stock_code='MSFT'
674
-
675
- stock_code='GC=F'
676
- stock_code='XAUUSD'
677
-
678
- yahoo_name1(stock_code)
679
-
680
-
681
- def yahoo_name1(stock_code):
682
-
683
- import requests
684
- from bs4 import BeautifulSoup
685
-
686
- stock_code1=stock_code.lower()
687
-
688
- #抓取证券名称
689
- headers = {
690
- "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"
691
- }
692
- url = f"https://finance.yahoo.com/quote/{stock_code1}"
693
- response = requests.get(url,headers=headers)
694
- if response.status_code == 200:
695
- soup = BeautifulSoup(response.text, 'html.parser')
696
- soup_title=soup.title
697
- soup_text=soup_title.text
698
-
699
- stock_code2=stock_code1.upper()
700
- try:
701
- pos=soup_text.index(stock_code2)
702
- except:
703
- pass
704
- return stock_code
705
- t_name = soup_text[:pos-1].strip()
706
- else:
707
- pass
708
- return stock_code
709
-
710
- #过滤名称中多余的尾部词汇
711
- t_name=filter_stock_name(t_name).strip()
712
- t_name=filter_stock_name(t_name).strip()
713
-
714
- return t_name
715
-
716
- #==============================================================================
717
-
718
-
719
-
720
-
721
- if __name__=='__main__':
722
- ticker='1155.KL'
723
- ticker='MSFT'
724
- ticker='G13.SI'
725
- ticker='S63.SI'
726
- ticker='SUS.ST'
727
- ticker='SUN.UK'
728
- ticker='IUI1.DE'
729
-
730
- ticker='600519.SS'
731
- ticker='U11.SI'
732
- ticker='1295.KL'
733
- ticker='BMW.DE'
734
- ticker='MBG.DE'
735
- ticker='005930.KS'
736
- ticker='LI'
737
- ticker='ULVR.L'
738
- ticker='KSL.AX'
739
-
740
- ticker='SGC=F'
741
-
742
- ticker='IBM'
743
-
744
- ticker='XAUUSD'
745
- short_name=False;add_suffix=True;maxlen=80
746
-
747
- get_stock_name1_en(ticker)
748
-
749
- def get_stock_name1_en(ticker,short_name=False,add_suffix=True,maxlen=80):
750
- """
751
- 功能:分别从stooq和yahoo网站获取证券名称,优先stooq(因为不需要vpn)
752
- """
753
- sname=ticker
754
-
755
- try:
756
- sname=stooq_name1(ticker,add_suffix=add_suffix)
757
- except:
758
- pass
759
-
760
- if sname==ticker:
761
- try:
762
- sname=yahoo_name1(ticker,short_name=short_name,add_suffix=add_suffix,maxlen=maxlen)
763
- except:
764
- pass
765
-
766
- return sname
767
-
768
- #==============================================================================
769
- #==============================================================================
770
- if __name__ == '__main__':
771
- ticker='600519.SS'
772
- ticker='600305.SS'
773
- ticker='200725.SZ'
774
- ticker='000725.SZ'
775
-
776
- get_stock_name_china_sina(ticker)
777
-
778
- def get_stock_name_china_sina(ticker):
779
- """
780
- 功能:抓取股票的申万行业分类名称
781
- """
782
-
783
- import requests
784
- from bs4 import BeautifulSoup
785
-
786
- ticker6=ticker[:6]
787
- headers = {
788
- "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"
789
- }
790
- url=f"https://vip.stock.finance.sina.com.cn/corp/go.php/vCI_CorpOtherInfo/stockid/{ticker6}/menu_num/2.phtml"
791
- response = requests.get(url,headers=headers)
792
-
793
- if response.status_code == 200:
794
- soup = BeautifulSoup(response.text, 'html.parser')
795
- soup_text=soup.find(id="stockName").text
796
-
797
- soup_text_list=soup_text.split('(')
798
-
799
- t_name = soup_text_list[0].strip()
800
-
801
- return t_name
802
- else:
803
- return ticker
804
-
805
- #==============================================================================
806
- #==============================================================================
807
- #==============================================================================
808
- #==============================================================================
809
- #==============================================================================
810
- #==============================================================================
811
- #==============================================================================