siat 3.2.59__py3-none-any.whl → 3.3.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.
siat/allin.py CHANGED
@@ -123,3 +123,6 @@ from siat.google_authenticator import *
123
123
  # 提问记录
124
124
  from siat.luchy_draw import *
125
125
 
126
+ # 搜索全球上市公司的英文名称,需要访问雅虎
127
+ from siat.yf_name import *
128
+
siat/security_prices.py CHANGED
@@ -417,13 +417,16 @@ def get_price_ak_em(ticker,fromdate,todate,adjust='',ticker_type='auto'):
417
417
  df1['footnote']=adjust
418
418
 
419
419
  num=len(df1)
420
+ """
420
421
  ptname=ticker_name(ticker,ticker_type)
421
422
  if ptname == ticker: ptname=''
422
-
423
+ """
423
424
  if num > 0:
424
- print(" Successfully retrieved",num,"records for",ticker,ptname)
425
+ #print(" Successfully retrieved",num,"records for",ticker,ptname)
426
+ print(" Successfully retrieved",num,"records for",ticker)
425
427
  else:
426
- print(" Sorry, no records retrieved for",ticker,ptname)
428
+ #print(" Sorry, no records retrieved for",ticker,ptname)
429
+ print(" Sorry, no records retrieved for",ticker)
427
430
 
428
431
  return df1
429
432
 
@@ -610,15 +613,17 @@ def get_price_stooq(ticker,start,end):
610
613
 
611
614
  _,start1,end1=check_period(start,end)
612
615
  prices2=prices[(prices.index >= start1) & (prices.index <= end1)]
616
+
613
617
  num=len(prices2)
618
+ """
614
619
  ptname=ticker_name(ticker,'stock')
615
620
  if ptname == ticker: ptname=''
616
-
621
+ """
617
622
  if num > 0:
618
- print(" Successfully retrieved",num,"records for",ticker,ptname)
623
+ print(" Successfully retrieved",num,"records for",ticker)
619
624
  return prices2
620
625
  else:
621
- print(" Sorry, no records found from stooq for",ticker,ptname,"from",start,'to',end)
626
+ print(" Sorry, no records found from stooq for",ticker,"from",start,'to',end)
622
627
  return None
623
628
  else:
624
629
  return None
@@ -930,13 +935,15 @@ def get_price_ak_cn(ticker,fromdate,todate,adjust='',ticker_type='auto'):
930
935
  df2['ticker']=str(ticker)
931
936
  if 'Adj Close' not in list(df2):
932
937
  df2['Adj Close']=df2['Close']
933
- df2['footnote']=adjust
934
-
938
+ df2['footnote']=adjust
939
+
940
+ """
935
941
  ptname=ticker_name(ticker,ticker_type)
936
942
  if ptname == ticker: ptname=''
943
+ """
937
944
 
938
945
  if len(df2) > 0:
939
- print(" Successfully retrieved",len(df2),"records for",ticker,ptname)
946
+ print(" Successfully retrieved",len(df2),"records for",ticker)
940
947
 
941
948
  return df2
942
949
 
@@ -1019,10 +1026,12 @@ def get_price_ak_us(symbol, fromdate, todate, adjust=""):
1019
1026
  df2['source']=text_lang('新浪','Sina')
1020
1027
  df2['footnote']=adjust
1021
1028
 
1029
+ """
1022
1030
  ptname=ticker_name(symbol,'stock')
1023
1031
  if ptname == symbol: ptname=''
1024
-
1025
- print(" Successfully retrieved",num,"records for",symbol,ptname)
1032
+ """
1033
+
1034
+ print(" Successfully retrieved",num,"records for",symbol)
1026
1035
 
1027
1036
  return df2
1028
1037
 
@@ -1106,10 +1115,12 @@ def get_price_ak_hk(symbol,fromdate,todate,adjust=""):
1106
1115
  df2['Adj Close']=df2['Close']
1107
1116
  df2['source']=text_lang('新浪','Sina')
1108
1117
 
1118
+ """
1109
1119
  ptname=ticker_name(symbol,'stock')
1110
1120
  if ptname == symbol: ptname=''
1121
+ """
1111
1122
 
1112
- print(" Successfully retrieved",num,"records for",symbol,ptname)
1123
+ print(" Successfully retrieved",num,"records for",symbol)
1113
1124
 
1114
1125
  return df2
1115
1126
 
@@ -1301,10 +1312,12 @@ def get_prices_yahoo(ticker,start,end,retry_count=3,pause=1):
1301
1312
  #p['Adj Close']=p['Close']
1302
1313
  p['source']=text_lang('雅虎','Yahoo')
1303
1314
 
1315
+ """
1304
1316
  ptname=ticker_name(ticker,'stock')
1305
1317
  if ptname == ticker: ptname=''
1306
-
1307
- print(" Successfully retrieved",len(p),"records for",ticker,ptname)
1318
+ """
1319
+
1320
+ print(" Successfully retrieved",len(p),"records for",ticker)
1308
1321
 
1309
1322
  #去掉时区
1310
1323
  p=df_index_timezone_remove(p)
@@ -1389,10 +1402,12 @@ def get_prices_yf(ticker,start,end,threads=False):
1389
1402
  p['source']=text_lang('雅虎','Yahoo')
1390
1403
 
1391
1404
  if len(p) > 0:
1405
+ """
1392
1406
  ptname=ticker_name(ticker1,'stock')
1393
1407
  if ptname == ticker: ptname=''
1394
-
1395
- print(" Successfully retrieved",len(p),"records for",ticker1,ptname)
1408
+ """
1409
+
1410
+ print(" Successfully retrieved",len(p),"records for",ticker1)
1396
1411
 
1397
1412
  #去掉时区
1398
1413
  p=df_index_timezone_remove(p)
@@ -1458,10 +1473,12 @@ def get_index_fred(ticker,start,end):
1458
1473
 
1459
1474
  num=len(df)
1460
1475
  if num > 0:
1476
+ """
1461
1477
  ptname=ticker_name(ticker,'stock')
1462
1478
  if ptname == ticker: ptname=''
1463
-
1464
- print(" Successfully retrieved",num,"records for",ticker,ptname)
1479
+ """
1480
+
1481
+ print(" Successfully retrieved",num,"records for",ticker)
1465
1482
  else:
1466
1483
  print(" Sorry, no records retrieved for",ticker)
1467
1484
 
siat/translate.py CHANGED
@@ -3328,11 +3328,11 @@ def ticker1_name(ticker,ticker_type='auto'):
3328
3328
  if '基金' not in tname: tname=tname + '基金'
3329
3329
  break
3330
3330
 
3331
- #如未查到,尝试雅虎名称
3331
+ #如未查到,尝试stooq和雅虎名称,限英文名称
3332
3332
  if tname==symbol:
3333
3333
  #不包括中国大陆和香港证券,这些都应在前面查到?新上市的可能查不到
3334
3334
  #if ('.SS' not in symbol) and ('.SH' not in symbol) and ('.SZ' not in symbol) and ('.BJ' not in symbol) and ('.HK' not in symbol):
3335
- tname=yahoo_name2(symbol)
3335
+ tname=get_stock_name1_en(symbol)
3336
3336
  if tname==symbol:
3337
3337
  return tname
3338
3338
 
siat/yf_name.py CHANGED
@@ -113,11 +113,12 @@ if __name__=='__main__':
113
113
 
114
114
  ticker_name(ticker)
115
115
 
116
- def yahoo_name1(ticker,short_name=False,add_suffix=True,maxlen=80):
116
+ def yahoo_name1x(ticker,short_name=False,add_suffix=True,maxlen=80):
117
117
  """
118
118
  功能:从雅虎财经取得全球证券名称,仅限英文。需要去掉常用词,如Corporation
119
119
  优点:对未定义的证券代码也可给出英文名称,即使在中文语言环境中
120
120
  现存问题:需要访问雅虎,且耗时稍长
121
+ 废弃!!!
121
122
  """
122
123
  #测试雅虎
123
124
  if not test_yahoo_access():
@@ -198,6 +199,11 @@ def yahoo_name1(ticker,short_name=False,add_suffix=True,maxlen=80):
198
199
 
199
200
  return t_name
200
201
 
202
+ #==============================================================================
203
+ def replace_multiple_spaces(s):
204
+ import re
205
+ return re.sub(r'\s+', ' ', s)
206
+
201
207
  #==============================================================================
202
208
  if __name__=='__main__':
203
209
  ticker='1155.KL'
@@ -220,6 +226,7 @@ if __name__=='__main__':
220
226
  ticker='600333.ss'
221
227
  ticker='600444.ss'
222
228
  ticker='600777.ss'
229
+ ticker='CPL.WA'
223
230
 
224
231
  yahoo_name2(ticker)
225
232
 
@@ -240,20 +247,12 @@ if __name__=='__main__':
240
247
 
241
248
  ticker_name(ticker)
242
249
 
243
- def yahoo_name2(ticker,short_name=False,add_suffix=True,maxlen=80):
250
+ def yahoo_name1(ticker,short_name=False,add_suffix=True,maxlen=80):
244
251
  """
245
252
  功能:从雅虎财经取得全球证券名称,仅限英文。需要去掉常用词,如Corporation
246
253
  优点:对未定义的证券代码也可给出英文名称,即使在中文语言环境中
247
254
  现存问题:需要访问雅虎,且耗时稍长
248
255
  """
249
- #定义需要去掉的单词,注意顺序不要轻易颠倒!子串包含的,要长文在前!前置留空格的为避免误删
250
- remove_list=[' CORPORATION',' BERHAD',' BHD',' PLC',' INC',' AG ST',' NA O N', \
251
- ' AKTIENGESELLSCHAFT','(PUBL)',' LLC', \
252
- ' CO LTD',' CO LIMITED',' LTD',' LIMITED',' COMPANY',' INCORPORATED', \
253
- ' CORP LTD',' CORP',' AB', \
254
- '(GROUP)',' GROUP', \
255
-
256
- ' SCIENCE & TECHNOLOGY',' HIGH-TECH',' HIGH TECHNOLOGY']
257
256
 
258
257
 
259
258
  #测试雅虎
@@ -284,8 +283,40 @@ def yahoo_name2(ticker,short_name=False,add_suffix=True,maxlen=80):
284
283
  pass
285
284
  return ticker #未找到ticker
286
285
 
286
+ #过滤名称中多余的尾部词汇
287
+ t_name=filter_stock_name(t_name0)
288
+
289
+ #增加交易所后缀
290
+ if add_suffix:
291
+ tlist=ticker.split('.')
292
+ if len(tlist)==2:
293
+ sid=tlist[1]
294
+ if sid not in ['SS','SZ','BJ']:
295
+ t_name=t_name+'('+sid+')'
296
+
297
+ return t_name
298
+ #==============================================================================
299
+ if __name__=='__main__':
300
+ original_name='Oponeo.pl SA'
301
+ original_name='Apple Inc'
302
+
303
+ filter_stock_name(original_name)
304
+
305
+ def filter_stock_name(original_name):
306
+ """
307
+ 功能:过滤从网站上抓取到的证券名称,去掉尾部的公司类别词汇,缩短长度,便于显示
308
+ """
309
+ #定义需要去掉的单词,注意顺序不要轻易颠倒!子串包含的,要长文在前!前置留空格的为避免误删
310
+ remove_list=[' CORPORATION',' BERHAD',' BHD',' PLC',' INC',' AG ST',' NA O N', \
311
+ ' AKTIENGESELLSCHAFT','(PUBL)',' LLC', \
312
+ ' CO LTD',' CO LIMITED',' LTD',' LIMITED',' COMPANY',' INCORPORATED', \
313
+ ' CORP LTD',' CORP',' AB', \
314
+ ' GROUP CO','(GROUP)',' GROUP', \
315
+ ' PL S A',' PL SA',' AG', \
316
+ ' SCIENCE & TECHNOLOGY',' HIGH-TECH',' HIGH TECHNOLOGY']
317
+
287
318
  #去掉逗号和句点
288
- name1=t_name0.replace(',',' ')
319
+ name1=original_name.replace(',',' ')
289
320
  name2=name1.replace('.',' ')
290
321
 
291
322
  #将字符串中的多个空格变为单个空格
@@ -300,21 +331,134 @@ def yahoo_name2(ticker,short_name=False,add_suffix=True,maxlen=80):
300
331
 
301
332
  name6=name5.strip()
302
333
 
303
- name7=t_name0[:len(name6)]
334
+ name7=original_name[:len(name6)]
335
+
336
+ shorter_name=name7
337
+ return shorter_name
338
+
304
339
 
340
+ #==============================================================================
341
+ if __name__ == '__main__':
342
+ stock_code='OPN.PL'
343
+ stock_code='AAPL'
344
+ stock_code='600519.SS'
345
+ stock_code='6758.T'
346
+ stock_code='6758.JP'
347
+ stock_code='ULVR.L'
348
+ stock_code='ULVR.UK'
349
+
350
+ stock_code='1155.KL'
351
+ stock_code='MSFT'
352
+
353
+ stooq_name1(stock_code)
354
+
355
+
356
+ def stooq_name1(stock_code,add_suffix=True):
357
+
358
+ import requests
359
+ from bs4 import BeautifulSoup
360
+
361
+ stock_code1=stock_code.lower()
362
+
363
+ #美股:尾部增加.us
364
+ stock_code_list=stock_code1.split('.')
365
+ if len(stock_code_list)==1:
366
+ stock_code1=stock_code1+'.us'
367
+
368
+ #其他国家股票
369
+ if len(stock_code_list)==2:
370
+ code=stock_code_list[0]
371
+ sid=stock_code_list[1]
372
+
373
+ #中国股票:尾部变为.cn
374
+ if sid in ['ss','sz','bj']:
375
+ stock_code1=code+'.cn'
376
+
377
+ #日本股票:尾部变为.jp
378
+ if sid in ['t']:
379
+ stock_code1=code+'.jp'
380
+
381
+ #英国股票:尾部变为.uk
382
+ if sid in ['l']:
383
+ stock_code1=code+'.uk'
384
+
385
+ #XX国股票
386
+
387
+ #波兰股票:去掉尾部.PL
388
+ stock_code1=stock_code1.replace('.pl','')
389
+
390
+ #抓取证券名称
391
+ url = f"https://stooq.com/q/?s={stock_code1}"
392
+ response = requests.get(url)
393
+ if response.status_code == 200:
394
+ soup = BeautifulSoup(response.text, 'html.parser')
395
+ soup_title=soup.title
396
+ soup_text=soup_title.text
397
+ soup_text_list=soup_text.split(' - ')
398
+
399
+ t_name = soup_text_list[1].strip()
400
+ else:
401
+ pass
402
+ return stock_code
403
+
404
+ #未找到证券代码
405
+ if t_name == 'Stooq':
406
+ return stock_code
407
+
408
+ #过滤名称中多余的尾部词汇
409
+ t_name=filter_stock_name(t_name)
410
+
305
411
  #增加交易所后缀
306
- t_name=name7
307
412
  if add_suffix:
308
- tlist=ticker.split('.')
413
+ tlist=stock_code1.split('.')
414
+ if len(tlist)==1: sid='PL'
309
415
  if len(tlist)==2:
310
- sid=tlist[1]
311
- if sid not in ['SS','SZ','BJ']:
312
- t_name=t_name+'('+sid+')'
416
+ sid=tlist[1].upper()
417
+
418
+ if sid not in ['CN','US']:
419
+ t_name=t_name+'('+sid+')'
313
420
 
314
- return t_name
315
- #==============================================================================
316
- #==============================================================================
421
+ return t_name
422
+
317
423
  #==============================================================================
424
+ if __name__=='__main__':
425
+ ticker='1155.KL'
426
+ ticker='MSFT'
427
+ ticker='G13.SI'
428
+ ticker='S63.SI'
429
+ ticker='SUS.ST'
430
+ ticker='SUN.UK'
431
+ ticker='IUI1.DE'
432
+
433
+ ticker='600519.SS'
434
+ ticker='U11.SI'
435
+ ticker='1295.KL'
436
+ ticker='BMW.DE'
437
+ ticker='MBG.DE'
438
+ ticker='005930.KS'
439
+ ticker='LI'
440
+
441
+ get_stock_name1_en(ticker)
442
+
443
+ def get_stock_name1_en(ticker,short_name=False,add_suffix=True,maxlen=80):
444
+ """
445
+ 功能:分别从stooq和yahoo网站获取证券名称,优先stooq(因为不需要vpn)
446
+ """
447
+ sname=ticker
448
+
449
+ try:
450
+ sname=stooq_name1(ticker,add_suffix=add_suffix)
451
+ except:
452
+ pass
453
+
454
+ if sname==ticker:
455
+ try:
456
+ sname=yahoo_name1(ticker,short_name=short_name,add_suffix=add_suffix,maxlen=maxlen)
457
+ except:
458
+ pass
459
+
460
+ return sname
461
+
318
462
  #==============================================================================
319
463
  #==============================================================================
320
464
  #==============================================================================
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: siat
3
- Version: 3.2.59
3
+ Version: 3.3.1
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,6 +1,6 @@
1
1
  siat/__init__ -20240701.py,sha256=gP5uajXnJesnH5SL0ZPwq_Qhv59AG1bs4qwZv26Fo2Y,2894
2
2
  siat/__init__.py,sha256=NJn2HSa0cdet21YFoJs5nafHgrM3H3J3wdtFYi1KzfM,2065
3
- siat/allin.py,sha256=f8mlMSQJUgx4mRVOJNlHH2SZP0jUyWaeDPT2V6AGfY8,2757
3
+ siat/allin.py,sha256=mGm28SxvGGiNAsg6RleiqgyFQvrpgQZERYqpPkdDzPw,2851
4
4
  siat/alpha_vantage_test.py,sha256=tKr-vmuFH3CZAqwmISz6jzjPHzV1JJl3sPfZdz8aTfM,747
5
5
  siat/assets_liquidity.py,sha256=o_UZdLs693uNWPEQB2OzxDH0mdWimOmq4qe_vx1pue0,28987
6
6
  siat/assets_liquidity_test.py,sha256=UWk6HIUlizU7LQZ890fGx8LwU1jMMrIZswg8cFUJWZ8,1285
@@ -98,7 +98,7 @@ siat/sector_china.py,sha256=nP6kfYsnaQWZj8dK-zklwSDW8FDS-obZWp_zL0ec2Ig,118603
98
98
  siat/sector_china_test.py,sha256=1wq7ef8Bb_L8F0h0W6FvyBrIcBTEbrTV7hljtpj49U4,5843
99
99
  siat/security_price.py,sha256=2oHskgiw41KMGfqtnA0i2YjNNV6cYgtlUK0j3YeuXWs,29185
100
100
  siat/security_price2.py,sha256=4xvc9AzRhLKJMu6AxVzIqcn1-NrHoeCF2Ao2p9nwYjU,25978
101
- siat/security_prices.py,sha256=LqTrS20mTmM_ACENOXU5qrLmxczGtxnuziAdAynSG_Q,105871
101
+ siat/security_prices.py,sha256=9T4RVZNDlxAGursIb4hZqGeekjYgjBgo3uALhzhWWLw,106181
102
102
  siat/security_prices_test.py,sha256=OEphoJ87NPKoNow1QA8EU_5MUYrJF-qKoWKNapVfZNI,10779
103
103
  siat/security_trend.py,sha256=o0vpWdrJkmODCP94X-Bvn-w7efHhj9HpUYBHtLl55D0,17240
104
104
  siat/security_trend2-20240620.py,sha256=QVnEcb7AyVbO77jVqfFsJffGXrX8pgJ9xCfoAKmWBPk,24854
@@ -131,15 +131,15 @@ siat/transaction_test.py,sha256=Z8g1LJCN4-mnUByXMUMoFmN0t105cbmsz2QmvSuIkbU,1858
131
131
  siat/translate-20230125.py,sha256=NPPSXhT38s5t9fzMvl_fvi4ckSB73ThLmZetVI-xGdU,117953
132
132
  siat/translate-20230206.py,sha256=-vtI125WyaJhmPotOpDAmclt_XnYVaWU9ByLWZ6FyYE,118133
133
133
  siat/translate-20230215.py,sha256=TJgtPE3n8IjljmZ4Pefy8dmHoNdFF-1zpML6BhA9FKE,121657
134
- siat/translate.py,sha256=v4__NZBhC7cVevl_lKxwhcKQa_UFuyVK1pdB6_KEflI,217855
134
+ siat/translate.py,sha256=GjuJTXsZKpmAEtljUxs1T-TT-aGZ726zWCAqQM03ElU,217888
135
135
  siat/translate_20240606.py,sha256=63IyHWEU3Uz9mjwyuAX3fqY4nUMdwh0ICQAgmgPXP7Y,215121
136
136
  siat/universal_test.py,sha256=CDAOffW1Rvs-TcNN5giWVvHMlch1w4dp-w5SIV9jXL0,3936
137
137
  siat/valuation.py,sha256=NKfeZMdDJOW42oLVHob6eSVBXUqlN1OCnnzwyGAst8c,48855
138
138
  siat/valuation_china.py,sha256=EkZQaVkoBjM0c4MCNbaX-bMnlG0e3FXeaWczZDnkptU,67784
139
139
  siat/valuation_market_china_test.py,sha256=gbJ0ioauuo4koTPH6WKUkqcXiQPafnbhU5eKJ6lpdLA,1571
140
140
  siat/var_model_validation.py,sha256=R0caWnuZarrRg9939hxh3vJIIpIyPfvelYmzFNZtPbo,14910
141
- siat/yf_name.py,sha256=CI3xZJSMGbDCKhmpL8_6DdebH6EDnVUaSfdTSf-FnA8,10199
142
- siat-3.2.59.dist-info/METADATA,sha256=suq3jI9DoMGKMeRXn-DbMpSlZhVwWtopNKsfiBjgOjw,7310
143
- siat-3.2.59.dist-info/WHEEL,sha256=2wepM1nk4DS4eFpYrW1TTqPcoGNfHhhO_i5m4cOimbo,92
144
- siat-3.2.59.dist-info/top_level.txt,sha256=r1cVyL7AIKqeAmEJjNR8FMT20OmEzufDstC2gv3NvEY,5
145
- siat-3.2.59.dist-info/RECORD,,
141
+ siat/yf_name.py,sha256=H1EM8YYXA8nQHIqsJlso0I3HKPiJLT3QujO4gRVQXWs,13945
142
+ siat-3.3.1.dist-info/METADATA,sha256=vdhsH9jtHlGhPaJ_YFcUYY7skJN7j4b663c9NWnTQRg,7309
143
+ siat-3.3.1.dist-info/WHEEL,sha256=2wepM1nk4DS4eFpYrW1TTqPcoGNfHhhO_i5m4cOimbo,92
144
+ siat-3.3.1.dist-info/top_level.txt,sha256=r1cVyL7AIKqeAmEJjNR8FMT20OmEzufDstC2gv3NvEY,5
145
+ siat-3.3.1.dist-info/RECORD,,
File without changes