siat 3.10.75__py3-none-any.whl → 3.10.125__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/security_prices.py CHANGED
@@ -131,12 +131,17 @@ if __name__=='__main__':
131
131
  ticker=['600519','000858']
132
132
  ticker_type='bond'
133
133
 
134
- fromdate="2024-1-1"
135
- todate="2024-4-1"
134
+ ticker='GEM25.CME'
135
+
136
+ ticker=['^SPX']
137
+
138
+ fromdate="2025-1-1"
139
+ todate="2025-6-1"
136
140
  adj=False
137
141
  retry_count=3
138
142
  pause=1
139
143
  source='auto'
144
+ ticker_type='auto'
140
145
 
141
146
  prices=get_prices(ticker,fromdate,todate,ticker_type=ticker_type)
142
147
 
@@ -151,6 +156,12 @@ def get_prices(ticker,fromdate,todate,adj=False,source='auto', \
151
156
  retry_count:网络失败时的重试次数,仅用于雅虎
152
157
  pause:每次重试前的间隔秒数,仅用于雅虎
153
158
  """
159
+ # yfinance可用性
160
+ YF=False
161
+ # pandas_datareader对yahoo可用性
162
+ PDR_yahoo=False
163
+
164
+ prices=None
154
165
 
155
166
  #检查日期期间的合理性
156
167
  result,start,end=check_period(fromdate,todate)
@@ -178,6 +189,7 @@ def get_prices(ticker,fromdate,todate,adj=False,source='auto', \
178
189
  return prices
179
190
  else:
180
191
  prices2=remove_timezone(prices)
192
+ #prices2=remove_df_index_timezone(prices)
181
193
  return prices2 #找到有效数据就返回,否则继续
182
194
 
183
195
  if source in ['auto','stooq']:
@@ -185,7 +197,7 @@ def get_prices(ticker,fromdate,todate,adj=False,source='auto', \
185
197
  #注意stooq代码与新浪/stooq的不同
186
198
  print(" Trying to capture info from stooq for",ticker)
187
199
  try:
188
- prices=get_price_stooq(ticker,fromdate,todate) #仅支持单只证券
200
+ prices=get_prices_stooq(ticker,fromdate,todate) #仅支持单只证券
189
201
  #prices=get_prices_stooq(ticker,fromdate,todate)?
190
202
  except:
191
203
  print(" #Warning(get_prices): info retrieving failed from stooq for",ticker)
@@ -198,6 +210,7 @@ def get_prices(ticker,fromdate,todate,adj=False,source='auto', \
198
210
  print(" #Warning(get_prices): zero record found for",ticker)
199
211
  else:
200
212
  prices2=remove_timezone(prices)
213
+ #prices2=remove_df_index_timezone(prices)
201
214
  return prices2 #找到有效数据就返回,否则继续
202
215
 
203
216
  if source in ['auto','yahoo']:
@@ -205,8 +218,13 @@ def get_prices(ticker,fromdate,todate,adj=False,source='auto', \
205
218
  #由于雅虎无法访问,建议暂时关闭,2021-10-24
206
219
  #抓取证券(列表)价格,需要调整收盘价:yfinance优先,线程极易出错,先尝试关闭线程
207
220
  try:
208
- print(" Trying to capture info from Yahoo Finance using non-threads")
209
- prices=get_prices_yf(ticker,start,end,threads=False) #支持多个证券
221
+ if YF:
222
+ print(" Trying to capture info from Yahoo Finance using non-threads")
223
+ prices=get_prices_yf(ticker,start,end,threads=False) #支持多个证券
224
+ else:
225
+ print(" Trying to capture info from Yahoo Finance ...")
226
+ prices=get_prices_yq(ticker,start,end)
227
+
210
228
  except:
211
229
  print(" #Warning(get_prices): retrieving using non-threads failed from yahoo")
212
230
  else:
@@ -218,12 +236,14 @@ def get_prices(ticker,fromdate,todate,adj=False,source='auto', \
218
236
  print(" #Warning(get_prices): zero record found")
219
237
  else:
220
238
  prices2=remove_timezone(prices)
239
+ #prices2=remove_df_index_timezone(prices)
221
240
  return prices2 #找到有效数据就返回,否则继续
222
241
 
223
242
  #抓取证券(列表)价格,需要调整收盘价:yfinance优先,尝试打开线程
224
243
  try:
225
- print(" Trying to capture info from Yahoo Finance using threads")
226
- prices=get_prices_yf(ticker,start,end,threads=True) #支持多个证券
244
+ if YF:
245
+ print(" Trying to capture info from Yahoo Finance using threads")
246
+ prices=get_prices_yf(ticker,start,end,threads=True) #支持多个证券
227
247
  except:
228
248
  print(" #Warning(get_prices): retrieving using threads failed from yahoo")
229
249
  else:
@@ -235,12 +255,14 @@ def get_prices(ticker,fromdate,todate,adj=False,source='auto', \
235
255
  print(" #Warning(get_prices): zero record found")
236
256
  else:
237
257
  prices2=remove_timezone(prices)
258
+ #prices2=remove_df_index_timezone(prices)
238
259
  return prices2 #找到有效数据就返回,否则继续
239
260
 
240
261
  #抓取证券(列表)价格,不考虑是否需要调整收盘价:pandas_datareader,使用雅虎
241
262
  try:
242
263
  print(" Trying to capture info from Yahoo Finance traditionally")
243
- prices=get_prices_yahoo(ticker,start,end,retry_count=retry_count,pause=pause)
264
+ if PDR_yahoo:
265
+ prices=get_prices_yahoo(ticker,start,end,retry_count=retry_count,pause=pause)
244
266
  except:
245
267
  print(" #Warning(get_prices): info retrieving failed from Yahoo traditionally")
246
268
  return None
@@ -254,6 +276,7 @@ def get_prices(ticker,fromdate,todate,adj=False,source='auto', \
254
276
  else:
255
277
  #print(" Successfully retrieved",num,"records for",ticker)
256
278
  prices2=remove_timezone(prices)
279
+ #prices2=remove_df_index_timezone(prices)
257
280
  return prices2
258
281
 
259
282
  #若能够抓取到数据均已提前返回,到达此处时表面未能抓取到任何数据
@@ -280,6 +303,7 @@ def get_price(ticker,fromdate,todate,adj=False,source='auto',ticker_type='auto')
280
303
  df=get_prices(ticker,fromdate,todate,adj=adj,source=source,ticker_type=ticker_type)
281
304
 
282
305
  df2=remove_timezone(df)
306
+ #df2=remove_df_index_timezone(df)
283
307
 
284
308
  return df2
285
309
 
@@ -340,9 +364,15 @@ if __name__=='__main__':
340
364
  ticker='430047.BJ'
341
365
  ticker='600519.SS'
342
366
  ticker='000001.SZ'
343
- fromdate='2022-11-1'
344
- todate='2022-12-15'
345
- adjust=''
367
+
368
+ ticker='GEM25.CME'
369
+
370
+ fromdate='2025-1-1'
371
+ todate='2025-6-15'
372
+
373
+ adjust=''; ticker_type='auto'
374
+
375
+ get_price_ak_em(ticker,fromdate,todate)
346
376
 
347
377
  #在common中定义SUFFIX_LIST_CN
348
378
 
@@ -564,9 +594,14 @@ if __name__=='__main__':
564
594
  ticker='XAUUSD' #一盎司黄金的现货美元价格
565
595
 
566
596
  ticker=['AAPL','MSFT']
567
-
568
597
  start='2025-6-1'; end='2025-6-1'
569
598
 
599
+ ticker='BMW.DE'
600
+ start='2022-6-1'; end='2025-6-15'
601
+
602
+ ticker='GEM25.CME'
603
+ start='2024-6-1'; end='2025-6-15'
604
+
570
605
  p=get_price_stooq(ticker,start,end)
571
606
 
572
607
  def get_price_stooq(ticker,start,end):
@@ -645,6 +680,88 @@ if __name__=='__main__':
645
680
  get_price_stooq('^N225','2021-11-1','2021-11-5')
646
681
  get_price_stooq('^DJI','2021-11-1','2021-11-5')
647
682
 
683
+ #==============================================================================
684
+ if __name__=='__main__':
685
+ ticker=['AAPL','MSFT']
686
+ ticker=['^SPX']
687
+ fromdate,todate='2025-1-1','2025-1-31'
688
+
689
+ prices=get_prices_stooq(ticker,fromdate,todate)
690
+
691
+ def get_prices_stooq(ticker,fromdate,todate):
692
+ """
693
+ 功能:获取stooq股票或指数的历史行情,多个股票
694
+ 注意:stooq不能抓取深交所和北交所的股票
695
+ """
696
+ #检查是否为多个证券:单个证券代码
697
+ if isinstance(ticker,str):
698
+ if security_in_China(ticker):
699
+ df=get_price_ak(ticker,fromdate,todate)
700
+ else:
701
+ df=get_price_stooq(ticker,fromdate,todate)
702
+ return df
703
+
704
+ #检查是否为多个证券:空的列表
705
+ if isinstance(ticker,list) and len(ticker) == 0:
706
+ pass
707
+ return None
708
+
709
+ #检查是否为多个证券:列表中只有一个代码
710
+ if isinstance(ticker,list) and len(ticker) == 1:
711
+ ticker1=ticker[0]
712
+ #抓取单个证券
713
+ if security_in_China(ticker1):
714
+ df=get_price_ak(ticker1,fromdate,todate)
715
+ else:
716
+ df=get_price_stooq(ticker1,fromdate,todate)
717
+ return df
718
+
719
+ import pandas as pd
720
+ #处理列表中的第一个证券
721
+ i=0
722
+ df=None
723
+ while df is None:
724
+ #注意列表序号超界
725
+ if i <= len(ticker)-1:
726
+ t=ticker[i]
727
+ else:
728
+ return df
729
+
730
+ #抓取单个证券
731
+ if security_in_China(t):
732
+ df=get_price_ak(t,fromdate,todate)
733
+ else:
734
+ df=get_price_stooq(t,fromdate,todate)
735
+
736
+ if not (df is None):
737
+ columns=create_tuple_for_columns(df,t)
738
+ df.columns=pd.MultiIndex.from_tuples(columns)
739
+ else:
740
+ i=i+1
741
+
742
+ if (i+1) == len(ticker):
743
+ pass
744
+ #已经到达代码列表末尾
745
+ return df
746
+
747
+ #处理列表中的其余证券
748
+ if i+1 <= len(ticker)-1:
749
+ for t in ticker[(i+1):]:
750
+ #抓取单个证券
751
+ if security_in_China(t):
752
+ df=get_price_ak(t,fromdate,todate)
753
+ else:
754
+ df=get_price_stooq(t,fromdate,todate)
755
+
756
+ if not (dft is None):
757
+ columns=create_tuple_for_columns(dft,t)
758
+ dft.columns=pd.MultiIndex.from_tuples(columns)
759
+
760
+ df=pd.merge(df,dft,how='inner',left_index=True,right_index=True)
761
+
762
+ return df
763
+
764
+
648
765
  #==============================================================================
649
766
  if __name__=='__main__':
650
767
  ticker='600340.SS'
@@ -981,8 +1098,9 @@ if __name__=='__main__':
981
1098
  #==============================================================================
982
1099
  if __name__=='__main__':
983
1100
  symbol='AAPL'
1101
+ symbol='GEM25.CME'
984
1102
  fromdate='2024-5-1'
985
- todate='2024-5-20'
1103
+ todate='2025-5-20'
986
1104
  adjust="qfq"
987
1105
 
988
1106
  get_price_ak_us(symbol, fromdate, todate, adjust)
@@ -1187,7 +1305,11 @@ def get_prices_ak(ticker,fromdate,todate,adjust='none',ticker_type='auto'):
1187
1305
  i=0
1188
1306
  df=None
1189
1307
  while df is None:
1190
- t=ticker[i]
1308
+ if i <= len(ticker)-1:
1309
+ t=ticker[i]
1310
+ else:
1311
+ return df
1312
+
1191
1313
  #抓取单个证券
1192
1314
  df=get_price_ak(t,fromdate,todate,adjust=adjust,ticker_type=ticker_type)
1193
1315
  if not (df is None):
@@ -1200,14 +1322,15 @@ def get_prices_ak(ticker,fromdate,todate,adjust='none',ticker_type='auto'):
1200
1322
  return df
1201
1323
 
1202
1324
  #处理列表中的其余证券
1203
- for t in ticker[(i+1):]:
1204
- #抓取单个证券
1205
- dft=get_price_ak(t,fromdate,todate,adjust=adjust,ticker_type=ticker_type)
1206
- if not (dft is None):
1207
- columns=create_tuple_for_columns(dft,t)
1208
- dft.columns=pd.MultiIndex.from_tuples(columns)
1209
-
1210
- df=pd.merge(df,dft,how='inner',left_index=True,right_index=True)
1325
+ if i+1 <= len(ticker)-1:
1326
+ for t in ticker[(i+1):]:
1327
+ #抓取单个证券
1328
+ dft=get_price_ak(t,fromdate,todate,adjust=adjust,ticker_type=ticker_type)
1329
+ if not (dft is None):
1330
+ columns=create_tuple_for_columns(dft,t)
1331
+ dft.columns=pd.MultiIndex.from_tuples(columns)
1332
+
1333
+ df=pd.merge(df,dft,how='inner',left_index=True,right_index=True)
1211
1334
 
1212
1335
  return df
1213
1336
 
@@ -1387,7 +1510,7 @@ if __name__=='__main__':
1387
1510
 
1388
1511
  def get_prices_yf(ticker,start,end,threads=False):
1389
1512
  """
1390
- 功能:从新浪/stooq抓取股价,使用yfinance(对非美股抓取速度快,但有时不太稳定)
1513
+ 功能:抓取股价,使用yfinance(对非美股抓取速度快,但有时不太稳定)
1391
1514
  输入:股票代码或股票代码列表,开始日期,结束日期
1392
1515
  ticker: 股票代码或股票代码列表。大陆股票代码加上后缀.SZ或.SS或.BJ,港股代码去掉前导0加后缀.HK
1393
1516
  start: 样本开始日期,尽量远的日期,以便取得足够多的原始样本,yyyy-mm-dd
@@ -1462,6 +1585,9 @@ if __name__=='__main__':
1462
1585
  ticker='AAPL'
1463
1586
  start='2020-12-1'; end='2025-1-31'
1464
1587
 
1588
+ ticker='GEM25.CME'
1589
+ start='2025-1-1'; end='2025-5-30'
1590
+
1465
1591
  p=get_price_yq(ticker,start,end)
1466
1592
 
1467
1593
  def get_price_yq(ticker,start,end):
@@ -1539,6 +1665,78 @@ def get_price_yq(ticker,start,end):
1539
1665
  return p
1540
1666
 
1541
1667
  #==============================================================================
1668
+ if __name__=='__main__':
1669
+ ticker=['600519.SS','000858.SZ']
1670
+ fromdate='2020-12-1'
1671
+ todate='2021-1-31'
1672
+
1673
+ ticker=['ICBC','SNP','HNP']
1674
+ fromdate,todate='2025-6-1','2025-6-20'
1675
+
1676
+
1677
+ prices=get_prices_yq(ticker,fromdate,todate)
1678
+
1679
+ def get_prices_yq(ticker,fromdate,todate):
1680
+ """
1681
+ 功能:获取yahooquery股票或指数的历史行情,多个股票
1682
+ """
1683
+ #检查是否为多个证券:单个证券代码
1684
+ if isinstance(ticker,str):
1685
+ df=get_price_yq(ticker,fromdate,todate)
1686
+ return df
1687
+
1688
+ #检查是否为多个证券:空的列表
1689
+ if isinstance(ticker,list) and len(ticker) == 0:
1690
+ pass
1691
+ return None
1692
+
1693
+ #检查是否为多个证券:列表中只有一个代码
1694
+ if isinstance(ticker,list) and len(ticker) == 1:
1695
+ ticker1=ticker[0]
1696
+ #抓取单个证券
1697
+ df=get_price_yq(ticker1,fromdate,todate)
1698
+ return df
1699
+
1700
+ import pandas as pd
1701
+ #处理列表中的第一个证券
1702
+ i=0
1703
+ df=None
1704
+ while df is None:
1705
+ if i <= len(ticker)-1:
1706
+ t=ticker[i]
1707
+ else:
1708
+ return df
1709
+
1710
+ #抓取单个证券
1711
+ df=get_price_yq(t,fromdate,todate)
1712
+ if not (df is None):
1713
+ columns=create_tuple_for_columns(df,t)
1714
+ df.columns=pd.MultiIndex.from_tuples(columns)
1715
+ else:
1716
+ i=i+1
1717
+
1718
+ if (i+1) == len(ticker):
1719
+ pass
1720
+ #已经到达代码列表末尾
1721
+ return df
1722
+
1723
+ #处理列表中的其余证券
1724
+ if i+1 <= len(ticker)-1:
1725
+ for t in ticker[(i+1):]:
1726
+ #抓取单个证券
1727
+ dft=get_price_yq(t,fromdate,todate)
1728
+ if not (dft is None):
1729
+ columns=create_tuple_for_columns(dft,t)
1730
+ dft.columns=pd.MultiIndex.from_tuples(columns)
1731
+
1732
+ df=pd.merge(df,dft,how='inner',left_index=True,right_index=True)
1733
+
1734
+ return df
1735
+
1736
+ if __name__=='__main__':
1737
+ dfm=get_prices_yq(['600519.SS','000858.SZ'],'2020-12-1','2021-1-31')
1738
+ dfm2=get_prices_yq(['600519.SS','AAPL'],'2020-12-1','2021-1-31')
1739
+ #==============================================================================
1542
1740
  if __name__=='__main__':
1543
1741
  ticker='AMZN'
1544
1742
  ticker='AAPL'
@@ -2412,6 +2610,7 @@ if __name__ =="__main__":
2412
2610
  portfolio={'Market':('US','^GSPC'),'AAPL':1}
2413
2611
  portfolio={'Market':('China','^HSI'),'0823.HK':1.0}
2414
2612
  portfolio={'Market':('China','000001.SS'),'000661.SZ':2,'603392.SS':3,'300601.SZ':4}
2613
+ portfolio={'Market':('US','^SPX'),'^SPX':1}
2415
2614
 
2416
2615
  fromdate='2019-7-19'
2417
2616
  todate='2020-7-20'
siat/security_trend2.py CHANGED
@@ -289,7 +289,7 @@ def security_trend(ticker,indicator='Close',adjust='', \
289
289
  fromdate=date_adjust(todate,adjust=-60)
290
290
  if not isinstance(mav,list):
291
291
  mav=[mav]
292
- df=candlestick(stkcd=tickers[0],fromdate=fromdate,todate=todate,mav=mav, \
292
+ df=candlestick(stkcd=tickers[0],start=fromdate,end=todate,mav=mav, \
293
293
  ticker_type=ticker_type,facecolor=facecolor,loc=loc1)
294
294
  return df
295
295
 
@@ -301,7 +301,7 @@ def security_trend(ticker,indicator='Close',adjust='', \
301
301
  if start in ['default']:
302
302
  fromdate=date_adjust(todate,adjust=-7)
303
303
 
304
- df=candlestick_demo(tickers[0],fromdate=fromdate,todate=todate, \
304
+ df=candlestick_demo(tickers[0],start=fromdate,end=todate, \
305
305
  ticker_type=ticker_type,facecolor=facecolor)
306
306
  return df
307
307
 
@@ -570,7 +570,7 @@ def security_trend(ticker,indicator='Close',adjust='', \
570
570
  print("attention_point=",attention_point)
571
571
 
572
572
  # ret_type要使用复权价
573
- df=compare_rar_security(ticker=tickers,start=fromdate,end=todate,rar=measures, \
573
+ df=compare_rar_security(ticker=tickers,start=fromdate,end=todate,indicator=measures, \
574
574
  ret_type=ret_type,RF=RF,regression_period=regression_period, \
575
575
  attention_value=attention_value,attention_value_area=attention_value_area, \
576
576
  attention_point=attention_point,attention_point_area=attention_point_area, \
siat/stock.py CHANGED
@@ -638,6 +638,17 @@ if __name__ =="__main__":
638
638
  ticker='XAUUSD'
639
639
  indicator='Close'
640
640
  fromdate='2024-5-1'; todate='2024-5-20'
641
+
642
+ # 测试组7
643
+ ticker='BMW.DE'
644
+ indicator='Close'
645
+ fromdate='2025-6-1'; todate='2025-6-15'
646
+
647
+ # 测试组8
648
+ ticker='GEM25.CME'
649
+ indicator='Close'
650
+ fromdate='2025-1-1'; todate='2025-6-15'
651
+
641
652
  zeroline=False
642
653
  attention_value='';attention_value_area=''
643
654
  attention_point='';attention_point_area=''
@@ -1968,6 +1979,27 @@ if __name__ =="__main__":
1968
1979
  start="2020-1-1"
1969
1980
  end="2020-6-30"
1970
1981
 
1982
+ # 测试组3
1983
+ tickers=["MBG.DE", "BMW.DE"]
1984
+ measure='Close'
1985
+ start="2025-6-1"
1986
+ end="2025-6-15"
1987
+
1988
+ attention_value='';attention_value_area=''
1989
+ attention_point='';attention_point_area=''
1990
+ adjust=''
1991
+ axhline_value=0;axhline_label=''
1992
+ preprocess='none';linewidth=1.5
1993
+ scaling_option='start'
1994
+ plus_sign=False
1995
+ band_area=''
1996
+ graph=True;loc='best';facecolor='whitesmoke'
1997
+ annotate=False;annotate_value=False
1998
+ smooth=True
1999
+ source='auto'
2000
+ mark_top=True;mark_bottom=True
2001
+ mark_start=False;mark_end=False
2002
+ ticker_type='auto'
1971
2003
 
1972
2004
  def compare_msecurity(tickers,measure,start,end, \
1973
2005
  attention_value='',attention_value_area='', \
siat/translate.py CHANGED
@@ -1243,7 +1243,9 @@ def codetranslate0(code):
1243
1243
  ["VOO",'Vanguard标普500ETF'],['VOOG','Vanguard标普500成长优先ETF'],
1244
1244
  ["VOOV",'Vanguard标普500价值优先ETF'],['IVV','iShares标普500ETF'],
1245
1245
  ["DGT",'SPDR Global Dow ETF'],['ICF','iShares C&S REIT ETF'],
1246
- ["FRI",'FT S&P REIT Index Fund'],['IEMG','iShares核心MSCI新兴市场ETF'],
1246
+ #["FRI",'FT S&P REIT Index Fund'],
1247
+ ["FRI",'FT标普REIT指数基金'],
1248
+ ['IEMG','iShares核心MSCI新兴市场ETF'],
1247
1249
  ['245710.KS','KINDEX越南VN30指数ETF'],['02801.HK','iShares核心MSCI中国指数ETF'],
1248
1250
 
1249
1251
  #基金REITs
@@ -1292,7 +1294,7 @@ def codetranslate0(code):
1292
1294
  ["S=F",'CBT大豆期货'],["C=F",'CBT玉米期货'],
1293
1295
  ["ES=F",'CME标普500指数期货'],["YM=F",'CBT道指期货'],
1294
1296
  ["NQ=F",'CME纳指100期货'],["RTY=F",'罗素2000指数期货'],
1295
- ["ZB=F",'10年期以上美债期货'],["ZT=F",'2年期美债期货'],
1297
+ ["ZB=F",'30年期美债期货'],["ZT=F",'2年期美债期货'],
1296
1298
  ["ZF=F",'5年期美债期货'],["ZN=F",'10年期美债期货'],
1297
1299
 
1298
1300
  #======================================================================
@@ -2136,7 +2138,7 @@ def codetranslate1(code):
2136
2138
  ["S=F",'CBT大豆期货'],["C=F",'CBT玉米期货'],
2137
2139
  ["ES=F",'CME标普500指数期货'],["YM=F",'CBT道指期货'],
2138
2140
  ["NQ=F",'CME纳指100期货'],["RTY=F",'罗素2000指数期货'],
2139
- ["ZB=F",'10年期以上美债期货'],["ZT=F",'2年期美债期货'],
2141
+ ["ZB=F",'30年期美债期货'],["ZT=F",'2年期美债期货'],
2140
2142
  ["ZF=F",'5年期美债期货'],["ZN=F",'10年期美债期货'],
2141
2143
 
2142
2144
  #======================================================================
@@ -2405,6 +2407,7 @@ if __name__=='__main__':
2405
2407
  fund='sh510170'
2406
2408
  fund='018021.SS'
2407
2409
  fund='320019.SS'
2410
+ fund='510580'
2408
2411
 
2409
2412
  get_fund_name_china2('sh510170')
2410
2413
  get_fund_name_china2(fund)
@@ -2507,8 +2510,9 @@ def get_bond_name_china(bond):
2507
2510
  if __name__=='__main__':
2508
2511
  bond="185851.SS"
2509
2512
  bond="102229.SZ"
2513
+ bond='sh111015'
2510
2514
 
2511
- get_exchange_bond_name_china("018021.SS")
2515
+ get_exchange_bond_name_china(bond)
2512
2516
 
2513
2517
  def get_exchange_bond_name_china(bond):
2514
2518
  """
@@ -2523,10 +2527,12 @@ def get_exchange_bond_name_china(bond):
2523
2527
  bond2=bond1[:6]
2524
2528
  bond3='sh'+bond2
2525
2529
 
2526
- if '.sz' in bond1:
2530
+ elif '.sz' in bond1:
2527
2531
  bond2=bond1[:6]
2528
2532
  bond3='sz'+bond2
2529
-
2533
+ else:
2534
+ bond3=bond1
2535
+
2530
2536
  import akshare as ak
2531
2537
  df=ak.bond_zh_hs_spot()
2532
2538
  try:
@@ -2540,8 +2546,9 @@ def get_exchange_bond_name_china(bond):
2540
2546
  if __name__=='__main__':
2541
2547
  bond="185851.SS"
2542
2548
  bond="102229.SZ"
2549
+ bond="sh111015"
2543
2550
 
2544
- get_exchange_bond_name_china2("018021.SS")
2551
+ get_exchange_bond_name_china2(bond)
2545
2552
 
2546
2553
  def get_exchange_bond_name_china2(bond):
2547
2554
  """
@@ -2557,10 +2564,12 @@ def get_exchange_bond_name_china2(bond):
2557
2564
  bond2=bond1[:6]
2558
2565
  bond3='sh'+bond2
2559
2566
 
2560
- if '.sz' in bond1:
2567
+ elif '.sz' in bond1:
2561
2568
  bond2=bond1[:6]
2562
2569
  bond3='sz'+bond2
2563
-
2570
+ else:
2571
+ bond3=bond1
2572
+
2564
2573
  import akshare as ak
2565
2574
  import pandas as pd
2566
2575
 
@@ -262,6 +262,7 @@ def backtest_VaR(tickerlist,sharelist,today,future_days=1, \
262
262
  result="高估"
263
263
 
264
264
  #打印结果
265
+ """
265
266
  print("\n======= VaR模型:回溯测试 =======")
266
267
  #print("投资组合 :",ticker_name(tickerlist))
267
268
  print("投资组合 :",end='')
@@ -285,6 +286,36 @@ def backtest_VaR(tickerlist,sharelist,today,future_days=1, \
285
286
  print("损失超过VaR的实际天数 :",threshhold_actual,'天')
286
287
  print("实际的置信度水平 : ",round(alpha_actual*100,2),"%",sep='')
287
288
  print("模型验证的回溯测试结果 :",result)
289
+ """
290
+
291
+ titletxt="VaR模型:回溯测试"
292
+ import datetime as dt; todaydt=dt.date.today()
293
+ footnote="数据来源:新浪/stooq,"+str(todaydt)
294
+ ticker_name_list=list2str(ticker_name(tickerlist,'bond'))
295
+ shares=sharelist
296
+ if len(sharelist)==1: shares=sharelist[0]
297
+
298
+ data_dict={'持有资产:':ticker_name_list, \
299
+ '资产配置:':shares, \
300
+ '持有日期:':today, \
301
+ '预计持有天数:':str(future_days)+'天', \
302
+ '置信度:':str(alpha*100)+'%', \
303
+ "使用的历史样本数据:":str(pastyears)+"年", \
304
+ "使用的VaR模型:":type, \
305
+
306
+ "*** 在险价值 ***":'', \
307
+ "VaR金额:":format(round(VaR,2),','), \
308
+ "VaR比率:":str(round(ratio*100,2))+"%", \
309
+
310
+ "*** 回溯测试 ***":'', \
311
+ "期望的置信度水平:":str(alpha*100)+"%", \
312
+ "损失超过VaR的预期天数:":str(threshhold_expected)+'天', \
313
+ "损失超过VaR的实际天数:":str(threshhold_actual)+'天', \
314
+ "实际的置信度水平:":str(round(alpha_actual*100,2))+"%", \
315
+ "模型验证的回溯测试结果:":result}
316
+
317
+ print2CSS(data_dict,titletxt=titletxt,footnote=footnote)
318
+
288
319
 
289
320
  return
290
321
 
@@ -347,6 +378,7 @@ def backtest_VaR_portfolio(portfolio,today,future_days=1, \
347
378
  result="高估"
348
379
 
349
380
  #打印结果
381
+ """
350
382
  print("\n======= VaR模型:回溯测试 =======")
351
383
  print("投资组合 :",tickerlist)
352
384
  print("成分股票配置 :",sharelist)
@@ -367,6 +399,33 @@ def backtest_VaR_portfolio(portfolio,today,future_days=1, \
367
399
  print("损失超过VaR的实际天数 :",threshhold_actual,'天')
368
400
  print("实际的置信度水平 : ",round(alpha_actual*100,2),"%",sep='')
369
401
  print("模型验证的回溯测试结果 :",result)
402
+ """
403
+
404
+ titletxt="VaR模型:回溯测试"
405
+ import datetime as dt; todaydt=dt.date.today()
406
+ footnote="数据来源:新浪/stooq,"+str(todaydt)
407
+
408
+ data_dict={'投资组合:':portfolio_name(portfolio), \
409
+ '持有日期:':today, \
410
+ "当前头寸:":format(round(position,2),','), \
411
+ '预计持有天数:':str(future_days)+'天', \
412
+ '置信度水平:':str(alpha*100)+'%', \
413
+ "使用的历史样本数据:":str(pastyears)+"年", \
414
+ "使用的VaR模型:":type, \
415
+
416
+ "*** 在险价值 ***":'', \
417
+ "VaR金额:":format(round(VaR,2),','), \
418
+ "VaR比率:":str(round(ratio*100,2))+"%", \
419
+
420
+ "*** 回溯测试 ***":'', \
421
+ "期望的置信度水平:":str(alpha*100)+"%", \
422
+ "损失超过VaR的预期天数:":str(threshhold_expected)+'天', \
423
+ "损失超过VaR的实际天数:":str(threshhold_actual)+'天', \
424
+ "实际的置信度水平:":str(round(alpha_actual*100,2))+"%", \
425
+ "模型验证的回溯测试结果:":result}
426
+
427
+ print2CSS(data_dict,titletxt=titletxt,footnote=footnote)
428
+
370
429
 
371
430
  return
372
431
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: siat
3
- Version: 3.10.75
3
+ Version: 3.10.125
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