siat 3.9.32__py3-none-any.whl → 3.10.11__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/capm_beta2.py CHANGED
@@ -335,7 +335,7 @@ if __name__=='__main__':
335
335
  betas=compare_mticker_1beta(ticker,start,end)
336
336
 
337
337
  def compare_mticker_1beta(ticker,start,end, \
338
- adjust='', \
338
+ adjust='qfq', \
339
339
  RF=0,regression_period=365, \
340
340
  attention_value='',attention_value_area='', \
341
341
  attention_point='',attention_point_area='', \
@@ -343,7 +343,8 @@ def compare_mticker_1beta(ticker,start,end, \
343
343
  band_area='', \
344
344
  graph=True,facecolor='whitesmoke',loc='best', \
345
345
  annotate=False,annotate_value=False, \
346
- mark_top=False,mark_bottom=False,mark_end=False, \
346
+ mark_top=False,mark_bottom=False, \
347
+ mark_start=False,mark_end=False, \
347
348
  mktidx='auto',source='auto',ticker_type='auto'):
348
349
  """
349
350
  功能:多只股票,对比其贝塔系数
@@ -448,7 +449,8 @@ def compare_mticker_1beta(ticker,start,end, \
448
449
  attention_point=attention_point,attention_point_area=attention_point_area, \
449
450
  band_area=band_area, \
450
451
  annotate=annotate,annotate_value=annotate, \
451
- mark_top=mark_top,mark_bottom=mark_bottom,mark_end=mark_end,
452
+ mark_top=mark_top,mark_bottom=mark_bottom, \
453
+ mark_start=mark_start,mark_end=mark_end, \
452
454
  facecolor=facecolor,loc=loc)
453
455
 
454
456
  return df
@@ -473,7 +475,7 @@ if __name__=='__main__':
473
475
  betas=compare_1ticker_mRF(ticker,start,end,RF)
474
476
 
475
477
  def compare_1ticker_mRF(ticker,start,end, \
476
- adjust='', \
478
+ adjust='qfq', \
477
479
  RF=[0,0.02,0.05], \
478
480
  regression_period=365, \
479
481
  attention_value='',attention_value_area='', \
@@ -482,7 +484,8 @@ def compare_1ticker_mRF(ticker,start,end, \
482
484
  band_area='', \
483
485
  graph=True,facecolor='whitesmoke',loc='best', \
484
486
  annotate=False,annotate_value=False, \
485
- mark_top=False,mark_bottom=False,mark_end=False, \
487
+ mark_top=False,mark_bottom=False, \
488
+ mark_start=False,mark_end=False, \
486
489
  mktidx='auto',source='auto', \
487
490
  ticker_type='auto'):
488
491
  """
@@ -585,7 +588,8 @@ def compare_1ticker_mRF(ticker,start,end, \
585
588
  attention_point=attention_point,attention_point_area=attention_point_area, \
586
589
  band_area=band_area, \
587
590
  annotate=annotate,annotate_value=annotate, \
588
- mark_top=mark_top,mark_bottom=mark_bottom,mark_end=mark_end, \
591
+ mark_top=mark_top,mark_bottom=mark_bottom, \
592
+ mark_start=mark_start,mark_end=mark_end, \
589
593
  facecolor=facecolor,loc=loc)
590
594
 
591
595
  return df
@@ -608,7 +612,7 @@ if __name__=='__main__':
608
612
  betas=compare_1ticker_mregression_period(ticker,start,end,RF,regression_period)
609
613
 
610
614
  def compare_1ticker_mregression_period(ticker,start,end, \
611
- adjust='', \
615
+ adjust='qfq', \
612
616
  RF=0, \
613
617
  regression_period=[183,365,730], \
614
618
  attention_value='',attention_value_area='', \
@@ -617,7 +621,8 @@ def compare_1ticker_mregression_period(ticker,start,end, \
617
621
  band_area='', \
618
622
  graph=True,facecolor='whitesmoke',loc='best', \
619
623
  annotate=False,annotate_value=False, \
620
- mark_top=False,mark_bottom=False,mark_end=False, \
624
+ mark_top=False,mark_bottom=False, \
625
+ mark_start=False,mark_end=False, \
621
626
  mktidx='auto',source='auto', \
622
627
  ticker_type='auto'):
623
628
  """
@@ -716,7 +721,8 @@ def compare_1ticker_mregression_period(ticker,start,end, \
716
721
  attention_point=attention_point,attention_point_area=attention_point_area, \
717
722
  band_area=band_area, \
718
723
  annotate=annotate,annotate_value=annotate, \
719
- mark_top=mark_top,mark_bottom=mark_bottom,mark_end=mark_end, \
724
+ mark_top=mark_top,mark_bottom=mark_bottom, \
725
+ mark_start=mark_start,mark_end=mark_end, \
720
726
  facecolor=facecolor,loc=loc)
721
727
 
722
728
  return df
@@ -751,7 +757,8 @@ def compare_beta_security(ticker,start,end, \
751
757
  band_area='', \
752
758
  graph=True,facecolor='whitesmoke', \
753
759
  annotate=False,annotate_value=False, \
754
- mark_top=False,mark_bottom=False,mark_end=False, \
760
+ mark_top=False,mark_bottom=False, \
761
+ mark_start=False,mark_end=False, \
755
762
  mktidx='auto',source='auto', \
756
763
  ticker_type='auto',loc="best"):
757
764
  """
@@ -773,7 +780,8 @@ def compare_beta_security(ticker,start,end, \
773
780
  band_area=band_area, \
774
781
  graph=graph,facecolor=facecolor,loc=loc, \
775
782
  annotate=annotate,annotate_value=annotate, \
776
- mark_top=mark_top,mark_bottom=mark_bottom,mark_end=mark_end, \
783
+ mark_top=mark_top,mark_bottom=mark_bottom, \
784
+ mark_start=mark_start,mark_end=mark_end, \
777
785
  mktidx=mktidx,source=source, \
778
786
  ticker_type=ticker_type)
779
787
  return df
@@ -792,7 +800,8 @@ def compare_beta_security(ticker,start,end, \
792
800
  band_area=band_area, \
793
801
  graph=graph,facecolor=facecolor,loc=loc, \
794
802
  annotate=annotate,annotate_value=annotate, \
795
- mark_top=mark_top,mark_bottom=mark_bottom,mark_end=mark_end, \
803
+ mark_top=mark_top,mark_bottom=mark_bottom, \
804
+ mark_start=mark_start,mark_end=mark_end, \
796
805
  mktidx=mktidx,source=source, \
797
806
  ticker_type=ticker_type)
798
807
  return df
@@ -811,7 +820,8 @@ def compare_beta_security(ticker,start,end, \
811
820
  band_area=band_area, \
812
821
  graph=graph,facecolor=facecolor,loc=loc, \
813
822
  annotate=annotate,annotate_value=annotate, \
814
- mark_top=mark_top,mark_bottom=mark_bottom,mark_end=mark_end, \
823
+ mark_top=mark_top,mark_bottom=mark_bottom, \
824
+ mark_start=mark_start,mark_end=mark_end, \
815
825
  mktidx=mktidx,source=source, \
816
826
  ticker_type=ticker_type)
817
827
  return df
@@ -828,7 +838,8 @@ def compare_beta_security(ticker,start,end, \
828
838
  band_area=band_area, \
829
839
  graph=graph,facecolor=facecolor,loc=loc, \
830
840
  annotate=annotate,annotate_value=annotate, \
831
- mark_top=mark_top,mark_bottom=mark_bottom,mark_end=mark_end, \
841
+ mark_top=mark_top,mark_bottom=mark_bottom, \
842
+ mark_start=mark_start,mark_end=mark_end, \
832
843
  mktidx=mktidx,source=source, \
833
844
  ticker_type=ticker_type)
834
845
 
siat/other_indexes.py CHANGED
@@ -185,6 +185,7 @@ if __name__=='__main__':
185
185
  #==============================================================================
186
186
  if __name__=='__main__':
187
187
  ticker='AAPL'
188
+ ticker='^TVX'
188
189
  ticker='Apple'
189
190
  start='2025-4-1'; end='2025-4-30'
190
191
 
@@ -291,6 +292,7 @@ if __name__=='__main__':
291
292
  api_key='VTRR3TA7L9O2DIX6'
292
293
  keyword='AAPL'
293
294
  keyword='Apple'
295
+ keyword='^TYX'
294
296
 
295
297
  search_av("microsoft")
296
298
  search_av("Apple")
@@ -299,6 +301,8 @@ def search_av(keyword,api_key='VTRR3TA7L9O2DIX6'):
299
301
  """
300
302
  过程:给定上市公司关键名称或不带后缀的股票代码,找出Alpha Vantage的股票代码。
301
303
  """
304
+ DEBUG=False
305
+
302
306
  import requests
303
307
  url = f"https://www.alphavantage.co/query?function=SYMBOL_SEARCH&keywords={keyword}&apikey={api_key}"
304
308
  response = requests.get(url)
@@ -308,13 +312,21 @@ def search_av(keyword,api_key='VTRR3TA7L9O2DIX6'):
308
312
 
309
313
  data = response.json()
310
314
  if "bestMatches" in data:
311
- firstcode=data["bestMatches"][0]['1. symbol']
312
- firstname=data["bestMatches"][0]['2. name']
315
+ try:
316
+ firstcode=data["bestMatches"][0]['1. symbol']
317
+ firstname=data["bestMatches"][0]['2. name']
318
+ except:
319
+ if DEBUG:
320
+ print(f" #Warning(search_av): no contents found for {keyword} in Alpha Vantage")
321
+ #未找到可匹配的股票代码
322
+ return None,None,None
323
+
313
324
  else:
314
- if "Information" in data:
315
- print(f" Warning(search_av): exceeded the limit of max requests per day")
316
- else:
317
- print(f" Warning(search_av): keyword {keyword} not found in Alpha Vantage")
325
+ if DEBUG:
326
+ if "Information" in data:
327
+ print(f" #Warning(search_av): exceeded limit of requests per day in Alpha Vantage")
328
+ else:
329
+ print(f" #Warning(search_av): keyword {keyword} not found in Alpha Vantage")
318
330
  #未找到可匹配的股票代码
319
331
  return None,None,None
320
332
 
@@ -323,6 +335,7 @@ def search_av(keyword,api_key='VTRR3TA7L9O2DIX6'):
323
335
  #==============================================================================
324
336
  if __name__=='__main__':
325
337
  ticker='AAPL'
338
+ ticker='^TVX'
326
339
  start='2025-4-1'; end='2025-4-30'
327
340
 
328
341
  get_price_tiingo(ticker,start,end)
@@ -337,7 +350,6 @@ def get_price_tiingo(ticker,start,end):
337
350
  api_token='0892bdb0533f8114535f354db596e6c244f5618d'
338
351
 
339
352
  from tiingo import TiingoClient
340
-
341
353
  # 通过配置字典
342
354
  config = {
343
355
  'api_key': api_token, # 替换为实际密钥
@@ -345,18 +357,18 @@ def get_price_tiingo(ticker,start,end):
345
357
  }
346
358
  client = TiingoClient(config)
347
359
 
360
+
348
361
  # 获取历史行情(默认返回DataFrame)
349
362
  try:
350
363
  dft = client.get_dataframe(
351
- ticker,
352
- startDate=start,
353
- endDate=end,
354
- frequency='daily'
355
- )
364
+ ticker,
365
+ startDate=start,
366
+ endDate=end,
367
+ frequency='daily'
368
+ )
356
369
  except Exception as e:
357
370
  if DEBUG:
358
371
  print(f" #Error(get_price_tiingo): {e}")
359
- else:
360
372
  print(f" #Error(get_price_tiingo): {ticker} not found or exceeded max requests per day")
361
373
  return None
362
374
 
@@ -816,7 +816,8 @@ def compare_1ticker_mrar(ticker,start,end,rar=['sharpe','sortino','treynor','alp
816
816
  axhline_value=0,axhline_label='',facecolor='whitesmoke', \
817
817
  printout=False,sortby='tpw_mean',trailing=7,trend_threshhold=0.01, \
818
818
  annotate=False,annotate_value=False, \
819
- mark_top=False,mark_bottom=False,mark_end=False, \
819
+ mark_top=False,mark_bottom=False, \
820
+ mark_start=False,mark_end=False, \
820
821
  mktidx='auto',source='auto',ticker_type='auto'):
821
822
  """
822
823
  功能:一只股票,对比其多个rar,支持股票和投资组合
@@ -923,7 +924,8 @@ def compare_1ticker_mrar(ticker,start,end,rar=['sharpe','sortino','treynor','alp
923
924
  attention_point=attention_point,attention_point_area=attention_point_area, \
924
925
  annotate=annotate,annotate_value=annotate, \
925
926
  band_area=band_area, \
926
- mark_top=mark_top,mark_bottom=mark_bottom,mark_end=mark_end, \
927
+ mark_top=mark_top,mark_bottom=mark_bottom, \
928
+ mark_start=mark_start,mark_end=mark_end, \
927
929
  facecolor=facecolor,loc=loc1)
928
930
 
929
931
  #制表
@@ -988,7 +990,8 @@ def compare_mticker_1rar(ticker,start,end,rar='sharpe', \
988
990
  axhline_value=0,axhline_label='', \
989
991
  printout=False,sortby='tpw_mean',trailing=7,trend_threshhold=0.01, \
990
992
  annotate=False,annotate_value=False, \
991
- mark_top=False,mark_bottom=False,mark_end=False, \
993
+ mark_top=False,mark_bottom=False, \
994
+ mark_start=False,mark_end=False, \
992
995
  mktidx='auto',source='auto', \
993
996
  style_print=True,ticker_type='auto',facecolor='whitesmoke'):
994
997
  """
@@ -1116,7 +1119,8 @@ def compare_mticker_1rar(ticker,start,end,rar='sharpe', \
1116
1119
  attention_point=attention_point,attention_point_area=attention_point_area, \
1117
1120
  band_area=band_area, \
1118
1121
  annotate=annotate,annotate_value=annotate, \
1119
- mark_top=mark_top,mark_bottom=mark_bottom,mark_end=mark_end, \
1122
+ mark_top=mark_top,mark_bottom=mark_bottom, \
1123
+ mark_start=mark_start,mark_end=mark_end, \
1120
1124
  facecolor=facecolor,loc=loc1)
1121
1125
 
1122
1126
  #制表
@@ -1177,7 +1181,8 @@ def compare_mticker_mrar(ticker,start,end,rar=['sharpe','alpha','sortino','treyn
1177
1181
  axhline_value=0,axhline_label='', \
1178
1182
  printout=True,sortby='tpw_mean',trailing=7,trend_threshhold=0.01, \
1179
1183
  annotate=False,annotate_value=False, \
1180
- mark_top=False,mark_bottom=False,mark_end=False, \
1184
+ mark_top=False,mark_bottom=False, \
1185
+ mark_start=False,mark_end=False, \
1181
1186
  mktidx='auto',source='auto', \
1182
1187
  ticker_type='auto',facecolor='whitesmoke'):
1183
1188
  """
@@ -1209,7 +1214,8 @@ def compare_mticker_mrar(ticker,start,end,rar=['sharpe','alpha','sortino','treyn
1209
1214
  printout=printout,sortby=sortby, \
1210
1215
  trailing=trailing,trend_threshhold=trend_threshhold, \
1211
1216
  annotate=annotate,annotate_value=annotate, \
1212
- mark_top=mark_top,mark_bottom=mark_bottom,mark_end=mark_end, \
1217
+ mark_top=mark_top,mark_bottom=mark_bottom, \
1218
+ mark_start=mark_start,mark_end=mark_end, \
1213
1219
  mktidx=mktidx,source=source,style_print=True, \
1214
1220
  ticker_type=ticker_type,loc1=loc1)
1215
1221
  if df_tmp is None:
@@ -1386,7 +1392,8 @@ def compare_1ticker_1rar_mret(ticker,start,end,rar='sharpe', \
1386
1392
  axhline_value=0,axhline_label='',facecolor='whitesmoke', \
1387
1393
  printout=False,sortby='tpw_mean',trailing=7,trend_threshhold=0.01, \
1388
1394
  annotate=False,annotate_value=False, \
1389
- mark_top=False,mark_bottom=False,mark_end=False, \
1395
+ mark_top=False,mark_bottom=False, \
1396
+ mark_start=False,mark_end=False, \
1390
1397
  mktidx='auto',source='auto',ticker_type='auto'):
1391
1398
  """
1392
1399
  功能:一只股票,同一个rar,对比其不同的收益率类型,支持股票和投资组合
@@ -1486,7 +1493,8 @@ def compare_1ticker_1rar_mret(ticker,start,end,rar='sharpe', \
1486
1493
  attention_point=attention_point,attention_point_area=attention_point_area, \
1487
1494
  annotate=annotate,annotate_value=annotate, \
1488
1495
  band_area=band_area, \
1489
- mark_top=mark_top,mark_bottom=mark_bottom,mark_end=mark_end, \
1496
+ mark_top=mark_top,mark_bottom=mark_bottom, \
1497
+ mark_start=mark_start,mark_end=mark_end, \
1490
1498
  facecolor=facecolor,loc=loc1)
1491
1499
 
1492
1500
  #制表
@@ -1548,7 +1556,8 @@ def compare_1ticker_1rar_1ret_mRF(ticker,start,end,rar='sharpe', \
1548
1556
  axhline_value=0,axhline_label='',facecolor='whitesmoke', \
1549
1557
  printout=False,sortby='tpw_mean',trailing=7,trend_threshhold=0.01, \
1550
1558
  annotate=False,annotate_value=False, \
1551
- mark_top=False,mark_bottom=False,mark_end=False, \
1559
+ mark_top=False,mark_bottom=False, \
1560
+ mark_start=False,mark_end=False, \
1552
1561
  mktidx='auto',source='auto',ticker_type='auto'):
1553
1562
  """
1554
1563
  功能:一只股票,相同的rar,相同的收益率类型,不同的无风险收益率
@@ -1643,7 +1652,8 @@ def compare_1ticker_1rar_1ret_mRF(ticker,start,end,rar='sharpe', \
1643
1652
  attention_point=attention_point,attention_point_area=attention_point_area, \
1644
1653
  annotate=annotate,annotate_value=annotate, \
1645
1654
  band_area=band_area, \
1646
- mark_top=mark_top,mark_bottom=mark_bottom,mark_end=mark_end, \
1655
+ mark_top=mark_top,mark_bottom=mark_bottom, \
1656
+ mark_start=mark_start,mark_end=mark_end, \
1647
1657
  facecolor=facecolor,loc=loc1)
1648
1658
 
1649
1659
  #制表
@@ -1722,7 +1732,8 @@ def compare_rar_security(ticker,start,end,rar='sharpe', \
1722
1732
  axhline_value=0,axhline_label='',facecolor='whitesmoke', \
1723
1733
  printout=False,sortby='tpw_mean',trailing=7,trend_threshhold=0.05, \
1724
1734
  annotate=False,annotate_value=False, \
1725
- mark_top=False,mark_bottom=False,mark_end=False, \
1735
+ mark_top=False,mark_bottom=False, \
1736
+ mark_start=False,mark_end=False, \
1726
1737
  mktidx='auto',source='auto', \
1727
1738
  ticker_type='auto'):
1728
1739
  """
@@ -1757,7 +1768,8 @@ def compare_rar_security(ticker,start,end,rar='sharpe', \
1757
1768
  printout=printout, \
1758
1769
  sortby=sortby,trailing=trailing,trend_threshhold=trend_threshhold, \
1759
1770
  annotate=annotate,annotate_value=annotate, \
1760
- mark_top=mark_top,mark_bottom=mark_bottom,mark_end=mark_end, \
1771
+ mark_top=mark_top,mark_bottom=mark_bottom, \
1772
+ mark_start=mark_start,mark_end=mark_end, \
1761
1773
  mktidx=mktidx,source=source, \
1762
1774
  ticker_type=ticker_type,facecolor=facecolor)
1763
1775
  return df
@@ -1774,7 +1786,8 @@ def compare_rar_security(ticker,start,end,rar='sharpe', \
1774
1786
  printout=printout, \
1775
1787
  sortby=sortby,trailing=trailing,trend_threshhold=trend_threshhold, \
1776
1788
  annotate=annotate,annotate_value=annotate, \
1777
- mark_top=mark_top,mark_bottom=mark_bottom,mark_end=mark_end, \
1789
+ mark_top=mark_top,mark_bottom=mark_bottom, \
1790
+ mark_start=mark_start,mark_end=mark_end, \
1778
1791
  mktidx=mktidx,source=source, \
1779
1792
  ticker_type=ticker_type,facecolor=facecolor)
1780
1793
  return df
@@ -1800,7 +1813,8 @@ def compare_rar_security(ticker,start,end,rar='sharpe', \
1800
1813
  printout=printout,facecolor=facecolor, \
1801
1814
  sortby=sortby,trailing=trailing,trend_threshhold=trend_threshhold, \
1802
1815
  annotate=annotate,annotate_value=annotate, \
1803
- mark_top=mark_top,mark_bottom=mark_bottom,mark_end=mark_end, \
1816
+ mark_top=mark_top,mark_bottom=mark_bottom, \
1817
+ mark_start=mark_start,mark_end=mark_end, \
1804
1818
  mktidx=mktidx,source=source, \
1805
1819
  ticker_type=ticker_type)
1806
1820
  return df
@@ -1824,7 +1838,8 @@ def compare_rar_security(ticker,start,end,rar='sharpe', \
1824
1838
  printout=printout, \
1825
1839
  sortby=sortby,trailing=trailing,trend_threshhold=trend_threshhold, \
1826
1840
  annotate=annotate,annotate_value=annotate, \
1827
- mark_top=mark_top,mark_bottom=mark_bottom,mark_end=mark_end, \
1841
+ mark_top=mark_top,mark_bottom=mark_bottom, \
1842
+ mark_start=mark_start,mark_end=mark_end, \
1828
1843
  mktidx=mktidx,source=source, \
1829
1844
  ticker_type=ticker_type,facecolor=facecolor)
1830
1845
  return df
@@ -1846,7 +1861,8 @@ def compare_rar_security(ticker,start,end,rar='sharpe', \
1846
1861
  printout=printout,facecolor=facecolor, \
1847
1862
  sortby=sortby,trailing=trailing,trend_threshhold=trend_threshhold, \
1848
1863
  annotate=annotate,annotate_value=annotate, \
1849
- mark_top=mark_top,mark_bottom=mark_bottom,mark_end=mark_end, \
1864
+ mark_top=mark_top,mark_bottom=mark_bottom, \
1865
+ mark_start=mark_start,mark_end=mark_end, \
1850
1866
  mktidx=mktidx,source=source, \
1851
1867
  ticker_type=ticker_type)
1852
1868
  return df
@@ -1864,7 +1880,8 @@ def compare_rar_security(ticker,start,end,rar='sharpe', \
1864
1880
  printout=printout,sortby=sortby, \
1865
1881
  trailing=trailing,trend_threshhold=trend_threshhold, \
1866
1882
  annotate=annotate,annotate_value=annotate, \
1867
- mark_top=mark_top,mark_bottom=mark_bottom,mark_end=mark_end, \
1883
+ mark_top=mark_top,mark_bottom=mark_bottom, \
1884
+ mark_start=mark_start,mark_end=mark_end, \
1868
1885
  mktidx=mktidx,source=source, \
1869
1886
  ticker_type=ticker_type,facecolor=facecolor)
1870
1887
 
siat/security_price2.py CHANGED
@@ -171,9 +171,14 @@ def get_price_1ticker(ticker,fromdate,todate, \
171
171
  if source in ['auto','yahoo'] and found not in ['Found','Empty']:
172
172
  dft=None
173
173
  if test_yahoo_finance():
174
- #数据源情形3:yahoo, yfinance, 需要访问yahoo,直接为复权价?
175
- dft=get_price_yf(ticker1,fromdate,todate)
174
+ #数据源情形3a:yahoo, yahooquery, 需要访问yahoo
175
+ dft=get_price_yq(ticker1,fromdate,todate)
176
176
  found=df_have_data(dft)
177
+
178
+ #数据源情形3b:yahoo, yfinance, 需要访问yahoo,直接为复权价
179
+ if found not in ['Found','Empty']:
180
+ dft=get_price_yf(ticker1,fromdate,todate)
181
+ found=df_have_data(dft)
177
182
 
178
183
  #数据源情形4:yahoo, pandas_datareader,需要访问yahoo,似乎不工作了!
179
184
  if found not in ['Found','Empty']:
siat/security_prices.py CHANGED
@@ -1449,6 +1449,88 @@ if __name__=='__main__':
1449
1449
  df4=get_prices_yf(['0700.HK','600519.SS'],'2020-12-1','2021-1-31')
1450
1450
  df5=get_prices_yf(['AAPL','MSFT','0700.HK','600519.SS'],'2020-12-1','2021-1-31')
1451
1451
  df6=get_prices_yf(['ABCD','EFGH','0700.HK','600519.SS'],'2020-12-1','2021-1-31')
1452
+
1453
+ #==============================================================================
1454
+ if __name__=='__main__':
1455
+ ticker='^TYX'
1456
+ start='2024-12-1'
1457
+ end='2025-1-31'
1458
+
1459
+ get_price_yq(ticker,start,end)
1460
+
1461
+ def get_price_yq(ticker,start,end):
1462
+ """
1463
+ 功能:从雅虎财经抓取股价,使用yahooquery(注意插件版本问题)
1464
+ 输入:股票代码或股票代码列表,开始日期,结束日期
1465
+ ticker: 股票代码或股票代码列表。大陆股票代码加上后缀.SZ或.SS或.BJ,港股代码去掉前导0加后缀.HK
1466
+ start: 样本开始日期,尽量远的日期,以便取得足够多的原始样本,yyyy-mm-dd
1467
+ end: 样本结束日期,既可以是今天日期,也可以是一个历史日期
1468
+
1469
+ 输出:指定收盘价格序列,最新日期的股价排列在前
1470
+ """
1471
+ DEBUG=False
1472
+
1473
+ p=None
1474
+
1475
+ #支持多个证券
1476
+ import yahooquery as yq
1477
+ ticker1,islist=cvt_yftickerlist(ticker)
1478
+
1479
+ try:
1480
+ #下载单一股票的股价;下载股票列表的股价,与单股票情况相同,但需注意MultiInex结构
1481
+ stock=yq.Ticker(ticker1, asynchronous=True)
1482
+ except:
1483
+ if DEBUG:
1484
+ print(" Yahoo api is tentatively inaccessible, recovering ...")
1485
+ sleep_random(max_sleep=60)
1486
+ try:
1487
+ stock=yq.Ticker(ticker1, asynchronous=True)
1488
+ except:
1489
+ if DEBUG:
1490
+ print(f" Sorry, failed to retrieve info from Yahoo for {ticker}")
1491
+ p=None
1492
+ return p
1493
+
1494
+ if not islist:
1495
+ try:
1496
+ p=stock.history(start=start,end=end)
1497
+ #仅针对雅虎情况
1498
+ if p is not None:
1499
+ if len(p)==0: p=None
1500
+ except:
1501
+ p=None
1502
+ else:
1503
+ try:
1504
+ p=stock.history(start=start,end=end)
1505
+ #仅针对雅虎情况
1506
+ if p is not None:
1507
+ if len(p)==0: p=None
1508
+ except:
1509
+ p=None
1510
+
1511
+ found=df_have_data(p)
1512
+ if found in ['Found','Empty']:
1513
+ p.rename(columns={'open':'Open','high':'High','low':'Low','close':'Close', \
1514
+ 'adjclose':'Adj Close','volume':'Volume'},inplace=True)
1515
+
1516
+ if 'Adj Close' not in list(p):
1517
+ p['Adj Close']=p['Close']
1518
+ p['ticker']=ticker
1519
+ p['source']=text_lang('雅虎','Yahoo')
1520
+
1521
+ # 去掉一级Index
1522
+ p=p.droplevel('symbol')
1523
+ p['date']=p.index
1524
+ if len(p) > 0:
1525
+ print(" Successfully retrieved",len(p),"records for",ticker1)
1526
+
1527
+ #去掉时区
1528
+ p=df_index_timezone_remove(p)
1529
+ else:
1530
+ pass
1531
+ #print(" #Error(get_prices_yf):",ticker1,"not found or no prices in the period or inaccessible to yahoo")
1532
+
1533
+ return p
1452
1534
 
1453
1535
  #==============================================================================
1454
1536
  if __name__=='__main__':
siat/security_trend2.py CHANGED
@@ -150,7 +150,8 @@ def security_trend(ticker,indicator='Close',adjust='', \
150
150
  preprocess='none',scaling_option='change%', \
151
151
 
152
152
  annotate=False,annotate_value=False, \
153
- mark_top=False,mark_bottom=False,mark_end=False, \
153
+ mark_top=False,mark_bottom=False, \
154
+ mark_start=False,mark_end=False, \
154
155
 
155
156
  printout=False,source='auto', \
156
157
  ticker_type='auto', \
@@ -235,9 +236,10 @@ def security_trend(ticker,indicator='Close',adjust='', \
235
236
  indicator='Exp Ret%',
236
237
  start='MRY')
237
238
  """
238
-
239
239
  DEBUG=False
240
240
 
241
+ print(f" Looking for info of specified securities ...")
242
+
241
243
  #critical_value=attention_value
242
244
 
243
245
  portfolio_flag=False #标志:ticker中是否含有投资组合
@@ -436,7 +438,8 @@ def security_trend(ticker,indicator='Close',adjust='', \
436
438
  datatag=datatag,power=power,graph=graph, \
437
439
  source=source,loc=loc1, \
438
440
  mark_top=mark_top,mark_bottom=mark_bottom, \
439
- mark_end=mark_end,ticker_type=ticker_type, \
441
+ mark_start=mark_start,mark_end=mark_end, \
442
+ ticker_type=ticker_type, \
440
443
  facecolor=facecolor)
441
444
  return df
442
445
 
@@ -472,7 +475,8 @@ def security_trend(ticker,indicator='Close',adjust='', \
472
475
  date_range=date_range,date_freq=date_freq, \
473
476
  annotate=annotate,annotate_value=annotate_value, \
474
477
  source=source,
475
- mark_top=mark_top,mark_bottom=mark_bottom,mark_end=mark_end, \
478
+ mark_top=mark_top,mark_bottom=mark_bottom, \
479
+ mark_start=mark_start,mark_end=mark_end, \
476
480
  ticker_type=ticker_type,facecolor=facecolor)
477
481
  return df
478
482
 
@@ -528,7 +532,8 @@ def security_trend(ticker,indicator='Close',adjust='', \
528
532
  annotate=annotate,annotate_value=annotate_value, \
529
533
  smooth=smooth, \
530
534
  source=source, \
531
- mark_top=mark_top,mark_bottom=mark_bottom,mark_end=mark_end, \
535
+ mark_top=mark_top,mark_bottom=mark_bottom, \
536
+ mark_start=mark_start,mark_end=mark_end, \
532
537
  ticker_type=ticker_type,facecolor=facecolor)
533
538
  return df
534
539
 
@@ -552,7 +557,8 @@ def security_trend(ticker,indicator='Close',adjust='', \
552
557
  printout=printout, \
553
558
  sortby=sortby,trailing=trailing,trend_threshhold=trend_threshhold, \
554
559
  annotate=annotate,annotate_value=annotate_value, \
555
- mark_top=mark_top,mark_bottom=mark_bottom,mark_end=mark_end, \
560
+ mark_top=mark_top,mark_bottom=mark_bottom, \
561
+ mark_start=mark_start,mark_end=mark_end, \
556
562
  mktidx=market_index,source=source, \
557
563
  ticker_type=ticker_type,facecolor=facecolor)
558
564
  return df
@@ -572,7 +578,8 @@ def security_trend(ticker,indicator='Close',adjust='', \
572
578
  band_area=band_area, \
573
579
  graph=graph,facecolor=facecolor,loc=loc1, \
574
580
  annotate=annotate,annotate_value=annotate_value, \
575
- mark_top=mark_top,mark_bottom=mark_bottom,mark_end=mark_end, \
581
+ mark_top=mark_top,mark_bottom=mark_bottom, \
582
+ mark_start=mark_start,mark_end=mark_end, \
576
583
  mktidx=market_index,source=source, \
577
584
  ticker_type=ticker_type)
578
585
 
@@ -589,7 +596,8 @@ def security_trend(ticker,indicator='Close',adjust='', \
589
596
  attention_point=attention_point,attention_point_area=attention_point_area, \
590
597
  band_area=band_area, \
591
598
  annotate=annotate,annotate_value=annotate_value, \
592
- mark_top=mark_top,mark_bottom=mark_bottom,mark_end=mark_end)
599
+ mark_top=mark_top,mark_bottom=mark_bottom, \
600
+ mark_start=mark_start,mark_end=mark_end)
593
601
  return df
594
602
 
595
603
  # 其他未预料情形
siat/stock.py CHANGED
@@ -656,7 +656,8 @@ def security_indicator(ticker,indicator, \
656
656
  attention_point='',attention_point_area='', \
657
657
  average_value=False, \
658
658
  datatag=False,power=0,graph=True,source='auto', \
659
- mark_top=True,mark_bottom=True,mark_end=True, \
659
+ mark_top=True,mark_bottom=True, \
660
+ mark_start=True,mark_end=True, \
660
661
  ticker_type='auto',facecolor='whitesmoke',loc='best'):
661
662
  """
662
663
  功能:单只证券的全部指标
@@ -767,7 +768,8 @@ def security_indicator(ticker,indicator, \
767
768
  average_value=average_value, \
768
769
  attention_value=attention_value,attention_value_area=attention_value_area, \
769
770
  attention_point=attention_point,attention_point_area=attention_point_area, \
770
- mark_top=mark_top,mark_bottom=mark_bottom,mark_end=mark_end, \
771
+ mark_top=mark_top,mark_bottom=mark_bottom, \
772
+ mark_start=mark_start,mark_end=mark_end, \
771
773
  facecolor=facecolor,loc=loc)
772
774
 
773
775
  return erdf3
@@ -895,7 +897,8 @@ def security_mindicators(ticker,measures,
895
897
  date_range=False,date_freq=False, \
896
898
  annotate=False,annotate_value=False, \
897
899
  source='auto', \
898
- mark_top=True,mark_bottom=True,mark_end=True, \
900
+ mark_top=True,mark_bottom=True, \
901
+ mark_start=True,mark_end=True, \
899
902
  ticker_type='auto'):
900
903
  """
901
904
  功能:单个证券,多个指标对比
@@ -1001,7 +1004,9 @@ def security_mindicators(ticker,measures,
1001
1004
  attention_value=attention_value,attention_value_area=attention_value_area, \
1002
1005
  attention_point=attention_point,attention_point_area=attention_point_area, \
1003
1006
  annotate=annotate,annotate_value=annotate_value, \
1004
- mark_top=mark_top,mark_bottom=mark_bottom,mark_end=mark_end,facecolor=facecolor, \
1007
+ mark_top=mark_top,mark_bottom=mark_bottom, \
1008
+ mark_start=mark_start,mark_end=mark_end, \
1009
+ facecolor=facecolor, \
1005
1010
  band_area=band_area,loc=loc)
1006
1011
 
1007
1012
  return df
@@ -1977,7 +1982,8 @@ def compare_msecurity(tickers,measure,start,end, \
1977
1982
  annotate=False,annotate_value=False, \
1978
1983
  smooth=True, \
1979
1984
  source='auto', \
1980
- mark_top=True,mark_bottom=True,mark_end=False, \
1985
+ mark_top=True,mark_bottom=True, \
1986
+ mark_start=False,mark_end=False, \
1981
1987
  ticker_type='auto'):
1982
1988
  """
1983
1989
  功能:比较并绘制多条证券指标曲线(多于2条),个数可为双数或单数
@@ -2160,7 +2166,8 @@ def compare_msecurity(tickers,measure,start,end, \
2160
2166
  attention_point=attention_point,attention_point_area=attention_point_area, \
2161
2167
  band_area=band_area, \
2162
2168
  annotate=annotate,annotate_value=annotate_value,plus_sign=plus_sign, \
2163
- mark_top=mark_top,mark_bottom=mark_bottom,mark_end=mark_end,facecolor=facecolor)
2169
+ mark_top=mark_top,mark_bottom=mark_bottom, \
2170
+ mark_start=mark_start,mark_end=mark_end,facecolor=facecolor)
2164
2171
 
2165
2172
  return dfs2
2166
2173
 
siat/valuation.py CHANGED
@@ -946,7 +946,8 @@ def security_valuation(tickers,indicators,start,end, \
946
946
  attention_point='',attention_point_area='', \
947
947
  band_area='', \
948
948
  annotate=False,annotate_value=False, \
949
- mark_top=False,mark_bottom=False,mark_end=False):
949
+ mark_top=False,mark_bottom=False, \
950
+ mark_start=False,mark_end=False):
950
951
  """
951
952
  功能:绘制估值走势
952
953
  """
@@ -1030,7 +1031,8 @@ def security_valuation(tickers,indicators,start,end, \
1030
1031
  attention_value=attention_value,attention_value_area=attention_value_area, \
1031
1032
  attention_point=attention_point,attention_point_area=attention_point_area, \
1032
1033
  annotate=annotate,annotate_value=annotate_value, \
1033
- mark_top=mark_top,mark_bottom=mark_bottom,mark_end=mark_end)
1034
+ mark_top=mark_top,mark_bottom=mark_bottom, \
1035
+ mark_start=mark_start,mark_end=mark_end)
1034
1036
 
1035
1037
  return df
1036
1038
 
@@ -1148,7 +1150,8 @@ def security_valuation(tickers,indicators,start,end, \
1148
1150
  facecolor=facecolor, \
1149
1151
  attention_value=attention_value,attention_value_area=attention_value_area, \
1150
1152
  attention_point=attention_point,attention_point_area=attention_point_area, \
1151
- mark_top=mark_top,mark_bottom=mark_bottom,mark_end=mark_end)
1153
+ mark_top=mark_top,mark_bottom=mark_bottom, \
1154
+ mark_start=mark_start,mark_end=mark_end)
1152
1155
 
1153
1156
  return df
1154
1157
 
@@ -1195,7 +1198,8 @@ def security_valuation(tickers,indicators,start,end, \
1195
1198
  facecolor=facecolor, \
1196
1199
  attention_value=attention_value,attention_value_area=attention_value_area, \
1197
1200
  attention_point=attention_point,attention_point_area=attention_point_area, \
1198
- mark_top=mark_top,mark_bottom=mark_bottom,mark_end=mark_end)
1201
+ mark_top=mark_top,mark_bottom=mark_bottom, \
1202
+ mark_start=mark_start,mark_end=mark_end)
1199
1203
 
1200
1204
  return df
1201
1205
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: siat
3
- Version: 3.9.32
3
+ Version: 3.10.11
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
@@ -16,7 +16,7 @@ siat/bond_china.py,sha256=WzUhjYYk8tsr3BDWLQcpuj9DqNxTzBSIi_wuAOZ48kY,3082
16
16
  siat/bond_test.py,sha256=yUOFw7ddGU-kb1rJdnsjkJWziDNgUR7OLDA7F7Ub91A,5246
17
17
  siat/bond_zh_sina.py,sha256=26BohGcS120utwqg9dJvdGm5OkuNpNu5bco80uOuQpU,4423
18
18
  siat/capm_beta.py,sha256=cxXdRVBQBllhbfz1LeTJAIWvyRYhW54nhtNUXv4HwS0,29063
19
- siat/capm_beta2.py,sha256=wGF_HmK_AiGWjpSAx79XHIxDghtI_ueYozvh06-2JEQ,33707
19
+ siat/capm_beta2.py,sha256=LmrfFhm4A-HLGolJ5rdlZFDGJkClS2I3Wv7gaHM3Tdw,34275
20
20
  siat/capm_beta_test.py,sha256=ImR0c5mc4hIl714XmHztdl7qg8v1E2lycKyiqnFj6qs,1745
21
21
  siat/cmat_commons.py,sha256=Nj9Kf0alywaztVoMVeVVL_EZk5jRERJy8R8kBw88_Tg,38116
22
22
  siat/common.py,sha256=J0qSvKtPS1gAfb2_GJNKxFkWJJaNbkQzg4fzaBvKwjM,183440
@@ -89,11 +89,11 @@ 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=i-yj2wU7mErlSCoNSOSQjY3_HNcI_8gJBs7H0PhiE5U,13353
92
+ siat/other_indexes.py,sha256=vx9am_kqogvKiJ82qrw5vqv-4wG4qdvHI0XCdAW9n7s,13842
93
93
  siat/proxy_test.py,sha256=erQJrmGs2X46z8Gb1h-7GYQ0rTUcaR8dxHExWoBz2eM,2610
94
94
  siat/quandl_test.py,sha256=EcPoXnLuqzPl5dKyVEZi3j3PJZFpsnU_iNPhLWC9p-A,1552
95
95
  siat/risk_adjusted_return.py,sha256=6F8CpKm-HKO4wfnndri0ew-D3lDAH1fs5O9K5cphoLg,55096
96
- siat/risk_adjusted_return2.py,sha256=92GXCpJPVVsYpQ-X3WXaADZvCqxsuJXQN5vG5trVX9I,86296
96
+ siat/risk_adjusted_return2.py,sha256=VzW3GOumNAoHcZL-0eOdsQma9w6JRTmBKU7gXdsl5DQ,87136
97
97
  siat/risk_adjusted_return_test.py,sha256=m_VHL5AtT74cJv5i7taTeTfnkX48y0AFJk5phawyYWg,3416
98
98
  siat/risk_evaluation.py,sha256=HK6U2G85-AxjSoeARbmTuiCNwTVdPdB9Znfgvslo0Os,76455
99
99
  siat/risk_evaluation_test.py,sha256=YEXM96gKzTfwN4U61AS4Rr1tV7KgUvn4rRC6f3iMw9s,3731
@@ -102,15 +102,15 @@ siat/risk_free_rate_test.py,sha256=CpmhUf8aEAEZeNu4gvWP2Mz2dLoIgBX5bI41vfUBEr8,4
102
102
  siat/sector_china.py,sha256=9zjdORWx5ia_gUezidhOKWmCnVDwWcnnjjugHudelaQ,157411
103
103
  siat/sector_china_test.py,sha256=1wq7ef8Bb_L8F0h0W6FvyBrIcBTEbrTV7hljtpj49U4,5843
104
104
  siat/security_price.py,sha256=2oHskgiw41KMGfqtnA0i2YjNNV6cYgtlUK0j3YeuXWs,29185
105
- siat/security_price2.py,sha256=35AV6zcL-u26uM1MGtyO5bj9uY6CCrdk3MTff5Q-0rc,27465
106
- siat/security_prices.py,sha256=HoCZ7YPrQYZHgKC-LyXFeeBCTfRc3EMMEiEg52SVv2w,109073
105
+ siat/security_price2.py,sha256=uC-wA6w3IlA9ZOJYINqIB7LexCbrnnqTkHTPuCSCwpo,27697
106
+ siat/security_prices.py,sha256=W6_K6mbwlPTrhxQDIGPjfx--jGD8Tdijxt-qOXeXcjk,111941
107
107
  siat/security_prices_test.py,sha256=OEphoJ87NPKoNow1QA8EU_5MUYrJF-qKoWKNapVfZNI,10779
108
108
  siat/security_trend.py,sha256=o0vpWdrJkmODCP94X-Bvn-w7efHhj9HpUYBHtLl55D0,17240
109
109
  siat/security_trend2-20240620.py,sha256=QVnEcb7AyVbO77jVqfFsJffGXrX8pgJ9xCfoAKmWBPk,24854
110
- siat/security_trend2.py,sha256=8-Z-PWaX8fjnyAyfxEp3qXdVllgDpRISOASKEn7Zeoc,30706
110
+ siat/security_trend2.py,sha256=CS2dMIC4dtTrFJ-X6DmVeujw_twzbJ0ou9cYuhbG7FM,31144
111
111
  siat/setup.py,sha256=up65rQGLmTBkhtaMLowjoQXYmIsnycnm4g1SYmeQS6o,1335
112
112
  siat/shenwan index history test.py,sha256=JCVAzOSEldHalhSFa3pqD8JI_8_djPMQOxpkuYU-Esg,1418
113
- siat/stock.py,sha256=ixl9NWhFS-z9cQUnBOaQ_u2gqsCiG02zZZrLVBSqPwQ,159941
113
+ siat/stock.py,sha256=ZTsewPKh_sDz-nd4GxR9af7V1ajTSqTAYUop_sf3PcM,160225
114
114
  siat/stock_advice_linear.py,sha256=-twT7IGP-NEplkL1WPSACcNJjggRB2j4mlAQCkzOAuo,31655
115
115
  siat/stock_base.py,sha256=uISvbRyOGy8p9QREA96CVydgflBkn5L3OXOGKl8oanc,1312
116
116
  siat/stock_china.py,sha256=85Ggb21E2mrCYMdSSTTrkoyyLGXMK2V-BtlweHomSRg,93460
@@ -140,13 +140,13 @@ siat/translate.py,sha256=m8mDVHilsw9nSIGBcvl_pS-aMy3W7UVKEZsLwhfuIEg,263300
140
140
  siat/translate_20240606.py,sha256=63IyHWEU3Uz9mjwyuAX3fqY4nUMdwh0ICQAgmgPXP7Y,215121
141
141
  siat/translate_241003_keep.py,sha256=un7Fqe1v35MXsja5exZgjmLzrZtt66NARZIGlyFuGGU,218747
142
142
  siat/universal_test.py,sha256=CDAOffW1Rvs-TcNN5giWVvHMlch1w4dp-w5SIV9jXL0,3936
143
- siat/valuation.py,sha256=K7epQC_UtELjRR5cyjJp4gskSyJMxXy-jHIAS0SUEj8,51801
143
+ siat/valuation.py,sha256=xGizcKJZ3ADLWWHm2TFQub18FxiDv2doQwBwbEqyqz0,51980
144
144
  siat/valuation_china.py,sha256=eSKIDckyjG8QkENlW_OKkqbQHno8pzDcomBO9iGNJVM,83079
145
145
  siat/valuation_market_china_test.py,sha256=gbJ0ioauuo4koTPH6WKUkqcXiQPafnbhU5eKJ6lpdLA,1571
146
146
  siat/var_model_validation.py,sha256=R0caWnuZarrRg9939hxh3vJIIpIyPfvelYmzFNZtPbo,14910
147
147
  siat/yf_name.py,sha256=laNKMTZ9hdenGX3IZ7G0a2RLBKEWtUQJFY9CWuk_fp8,24058
148
- siat-3.9.32.dist-info/LICENSE,sha256=NTEMMROY9_4U1szoKC3N2BLHcDd_o5uTgqdVH8tbApw,1071
149
- siat-3.9.32.dist-info/METADATA,sha256=nrawbbVkm08ig_snc7NU6XTo8pCuFWPU2FmgDCBhKxk,8396
150
- siat-3.9.32.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
151
- siat-3.9.32.dist-info/top_level.txt,sha256=r1cVyL7AIKqeAmEJjNR8FMT20OmEzufDstC2gv3NvEY,5
152
- siat-3.9.32.dist-info/RECORD,,
148
+ siat-3.10.11.dist-info/LICENSE,sha256=NTEMMROY9_4U1szoKC3N2BLHcDd_o5uTgqdVH8tbApw,1071
149
+ siat-3.10.11.dist-info/METADATA,sha256=oCWBelUMSlhnoyP16cqkkknPak8vHOaUUD8cHfVx9YM,8397
150
+ siat-3.10.11.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
151
+ siat-3.10.11.dist-info/top_level.txt,sha256=r1cVyL7AIKqeAmEJjNR8FMT20OmEzufDstC2gv3NvEY,5
152
+ siat-3.10.11.dist-info/RECORD,,
File without changes