siat 3.9.11__py3-none-any.whl → 3.9.20__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/other_indexes.py +195 -0
- siat/security_price2.py +16 -3
- {siat-3.9.11.dist-info → siat-3.9.20.dist-info}/METADATA +3 -1
- {siat-3.9.11.dist-info → siat-3.9.20.dist-info}/RECORD +7 -7
- {siat-3.9.11.dist-info → siat-3.9.20.dist-info}/LICENSE +0 -0
- {siat-3.9.11.dist-info → siat-3.9.20.dist-info}/WHEEL +0 -0
- {siat-3.9.11.dist-info → siat-3.9.20.dist-info}/top_level.txt +0 -0
siat/other_indexes.py
CHANGED
@@ -182,6 +182,201 @@ if __name__=='__main__':
|
|
182
182
|
index_code='VNINDEX'
|
183
183
|
start='2025-2-1'; end='2025-3-31'
|
184
184
|
get_other_index(index_code,start,end)
|
185
|
+
#==============================================================================
|
186
|
+
if __name__=='__main__':
|
187
|
+
ticker='AAPL'
|
188
|
+
ticker='Apple'
|
189
|
+
start='2025-4-1'; end='2025-4-30'
|
190
|
+
|
191
|
+
get_prices_av(ticker,start,end)
|
192
|
+
|
193
|
+
def get_prices_av(ticker,start,end):
|
194
|
+
"""
|
195
|
+
功能:从Alpha Vantage获取美股股价历史行情,使用Alpha Vantage
|
196
|
+
参数:
|
197
|
+
ticker:AV股票代码(假设与雅虎财经的股票代码相同),如不同可通过search_av获得准确代码
|
198
|
+
start:起始日期
|
199
|
+
end:结束日期
|
200
|
+
"""
|
201
|
+
# 免费注册:wangdehong@bfsu.edu.cn,每日25次。
|
202
|
+
api_key='VTRR3TA7L9O2DIX6'
|
203
|
+
|
204
|
+
from alpha_vantage.timeseries import TimeSeries
|
205
|
+
ts = TimeSeries(key=api_key, output_format="pandas")
|
206
|
+
try:
|
207
|
+
dft, _ = ts.get_daily(symbol=ticker, outputsize="full")
|
208
|
+
except:
|
209
|
+
pass
|
210
|
+
return None
|
211
|
+
|
212
|
+
dft.sort_index(ascending=True,inplace=True)
|
213
|
+
dft.rename(columns={'1. open':'Open','2. high':'High','3. low':'Low', \
|
214
|
+
'4. close':'Close','5. volume':'Volume'},inplace=True)
|
215
|
+
dft['Adj Close']=dft['Close']
|
216
|
+
dft['source']='Alpha Vantage'
|
217
|
+
dft['ticker']=ticker
|
218
|
+
dft['Name']=ticker
|
219
|
+
|
220
|
+
import pandas as pd
|
221
|
+
startpd=pd.to_datetime(start); endpd=pd.to_datetime(end)
|
222
|
+
df=dft[(dft.index >= startpd) & (dft.index <= endpd)]
|
223
|
+
|
224
|
+
return df
|
225
|
+
|
226
|
+
|
227
|
+
#==============================================================================
|
228
|
+
if __name__=='__main__':
|
229
|
+
ticker='AAPL'
|
230
|
+
ticker='Apple'
|
231
|
+
start='2025-4-1'; end='2025-4-30'
|
232
|
+
|
233
|
+
get_prices_av_pdr(ticker,start,end)
|
234
|
+
|
235
|
+
def get_prices_av_pdr(ticker,start,end):
|
236
|
+
"""
|
237
|
+
功能:从Alpha Vantage获取美股股价历史行情,使用pandas_datareader
|
238
|
+
参数:
|
239
|
+
ticker:AV股票代码(可能与雅虎财经的股票代码不同),可以通过search_av获得准确代码
|
240
|
+
start:起始日期
|
241
|
+
end:结束日期
|
242
|
+
"""
|
243
|
+
# 免费注册:wangdehong@bfsu.edu.cn,限每日25次。
|
244
|
+
api_key='VTRR3TA7L9O2DIX6'
|
245
|
+
|
246
|
+
import pandas_datareader.data as pdr
|
247
|
+
try:
|
248
|
+
dft = pdr.DataReader(ticker, "av-daily", api_key=api_key,start=start,end=end)
|
249
|
+
dft['ticker']=ticker
|
250
|
+
dft['Name']=ticker
|
251
|
+
except: # 拯救一次,查找字符串匹配的股票代码
|
252
|
+
firstcode,firstname,_=search_av(ticker,api_key)
|
253
|
+
if firstcode is None:
|
254
|
+
pass
|
255
|
+
return None
|
256
|
+
print(f" Notice: matching keyword {ticker} to stock code {firstcode}({firstname})")
|
257
|
+
try:
|
258
|
+
dft = pdr.DataReader(firstcode, "av-daily", api_key=api_key,start=start,end=end)
|
259
|
+
dft['ticker']=firstcode
|
260
|
+
dft['Name']=firstname
|
261
|
+
except:
|
262
|
+
pass
|
263
|
+
return None
|
264
|
+
|
265
|
+
if dft is None:
|
266
|
+
pass
|
267
|
+
return None
|
268
|
+
if len(dft) == 0:
|
269
|
+
pass
|
270
|
+
return None
|
271
|
+
|
272
|
+
dft.rename(columns={'open':'Open','high':'High','low':'Low','close':'Close', \
|
273
|
+
'volume':'Volume'},inplace=True)
|
274
|
+
dft['Adj Close']=dft['Close']
|
275
|
+
dft['source']='Alpha Vantage'
|
276
|
+
|
277
|
+
import pandas as pd
|
278
|
+
dft['Date']=dft['date']=dft.index
|
279
|
+
dft['date']=dft['date'].apply(lambda x: pd.to_datetime(x))
|
280
|
+
dft.set_index('date',inplace=True)
|
281
|
+
|
282
|
+
#startpd=pd.to_datetime(start); endpd=pd.to_datetime(end)
|
283
|
+
#df=dft[(dft.index >= startpd) & (dft.index <= endpd)]
|
284
|
+
df=dft
|
285
|
+
|
286
|
+
return df
|
287
|
+
|
288
|
+
|
289
|
+
#==============================================================================
|
290
|
+
if __name__=='__main__':
|
291
|
+
api_key='VTRR3TA7L9O2DIX6'
|
292
|
+
keyword='AAPL'
|
293
|
+
keyword='Apple'
|
294
|
+
|
295
|
+
search_av("microsoft")
|
296
|
+
search_av("Apple")
|
297
|
+
|
298
|
+
def search_av(keyword,api_key='VTRR3TA7L9O2DIX6'):
|
299
|
+
"""
|
300
|
+
过程:给定上市公司关键名称或不带后缀的股票代码,找出Alpha Vantage的股票代码。
|
301
|
+
"""
|
302
|
+
import requests
|
303
|
+
url = f"https://www.alphavantage.co/query?function=SYMBOL_SEARCH&keywords={keyword}&apikey={api_key}"
|
304
|
+
response = requests.get(url)
|
305
|
+
if response.status_code != 200:
|
306
|
+
pass
|
307
|
+
return None,None,None
|
308
|
+
|
309
|
+
data = response.json()
|
310
|
+
if "bestMatches" in data:
|
311
|
+
firstcode=data["bestMatches"][0]['1. symbol']
|
312
|
+
firstname=data["bestMatches"][0]['2. name']
|
313
|
+
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")
|
318
|
+
#未找到可匹配的股票代码
|
319
|
+
return None,None,None
|
320
|
+
|
321
|
+
return firstcode,firstname,data
|
322
|
+
|
323
|
+
#==============================================================================
|
324
|
+
if __name__=='__main__':
|
325
|
+
ticker='AAPL'
|
326
|
+
start='2025-4-1'; end='2025-4-30'
|
327
|
+
|
328
|
+
get_price_tiingo(ticker,start,end)
|
329
|
+
|
330
|
+
def get_price_tiingo(ticker,start,end):
|
331
|
+
"""
|
332
|
+
功能:获取美股历史行情信息,基于TIINGO
|
333
|
+
"""
|
334
|
+
DEBUG=False
|
335
|
+
|
336
|
+
# 每日限1000次调用,基于wdehong2000@163.com
|
337
|
+
api_token='0892bdb0533f8114535f354db596e6c244f5618d'
|
338
|
+
|
339
|
+
from tiingo import TiingoClient
|
340
|
+
|
341
|
+
# 通过配置字典
|
342
|
+
config = {
|
343
|
+
'api_key': api_token, # 替换为实际密钥
|
344
|
+
'session': True # 启用HTTP会话复用,提升性能
|
345
|
+
}
|
346
|
+
client = TiingoClient(config)
|
347
|
+
|
348
|
+
# 获取历史行情(默认返回DataFrame)
|
349
|
+
try:
|
350
|
+
dft = client.get_dataframe(
|
351
|
+
ticker,
|
352
|
+
startDate=start,
|
353
|
+
endDate=end,
|
354
|
+
frequency='daily'
|
355
|
+
)
|
356
|
+
except Exception as e:
|
357
|
+
if DEBUG:
|
358
|
+
print(f" #Error(get_price_tiingo): {e}")
|
359
|
+
else:
|
360
|
+
print(f" #Error(get_price_tiingo): {ticker} not found or exceeded max requests per day")
|
361
|
+
return None
|
362
|
+
|
363
|
+
# 去掉时区
|
364
|
+
dft.index = dft.index.tz_localize(None)
|
365
|
+
|
366
|
+
# 整理数据项
|
367
|
+
dft.rename(columns={'open':'Open','high':'High','low':'Low','close':'Close', \
|
368
|
+
'volume':'Volume'},inplace=True)
|
369
|
+
|
370
|
+
dft.rename(columns={'adjOpen':'Adj Open','adjHigh':'Adj High','adjLow':'Adj Low', \
|
371
|
+
'adjClose':'Adj Close', \
|
372
|
+
'adjVolume':'Adj Volume'},inplace=True)
|
373
|
+
|
374
|
+
dft['source']='Tiingo'
|
375
|
+
dft['ticker']=ticker; dft['name']=ticker
|
376
|
+
|
377
|
+
return dft
|
378
|
+
|
379
|
+
|
185
380
|
#==============================================================================
|
186
381
|
#==============================================================================
|
187
382
|
#==============================================================================
|
siat/security_price2.py
CHANGED
@@ -192,11 +192,24 @@ def get_price_1ticker(ticker,fromdate,todate, \
|
|
192
192
|
if source in ['auto','sina','em'] and found not in ['Found','Empty']:
|
193
193
|
dft=get_other_index_ak(ticker1,fromdate,todate)
|
194
194
|
found=df_have_data(dft)
|
195
|
-
|
195
|
+
|
196
|
+
#数据源情形7:Tiingo,每日限1000次调用
|
197
|
+
if source in ['auto','ti'] and found not in ['Found','Empty']:
|
198
|
+
dft=get_price_tiingo(ticker1,fromdate,todate)
|
199
|
+
found=df_have_data(dft)
|
200
|
+
|
201
|
+
#数据源情形8:alpha_vantage,每日限25次调用
|
202
|
+
if source in ['auto','av'] and found not in ['Found','Empty']:
|
203
|
+
dft=get_prices_av(ticker1,fromdate,todate)
|
204
|
+
found=df_have_data(dft)
|
205
|
+
|
206
|
+
#数据源情形9:Alpha Vantage, pandas_datareader, 可进行模糊匹配,但匹配准确度不确定!
|
207
|
+
if source in ['auto','av'] and found not in ['Found','Empty']:
|
208
|
+
dft=get_prices_av_pdr(ticker1,fromdate,todate)
|
209
|
+
found=df_have_data(dft)
|
210
|
+
|
196
211
|
"""
|
197
|
-
Tiingo:获取股票,共同基金和信息和交易所交易基金的信息,可以免费注册获得API_KEY
|
198
212
|
IEX:获得投资交易信息,需要API_KEY
|
199
|
-
Alpha Vantage:美股信息,需要API_KEY
|
200
213
|
Econdb:提供超过90家官方统计机构提供的经济数据,免费
|
201
214
|
Enigma:交易数据,需要API
|
202
215
|
Quandl:股价和基金交易数据,需要API_KEY
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.2
|
2
2
|
Name: siat
|
3
|
-
Version: 3.9.
|
3
|
+
Version: 3.9.20
|
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
|
@@ -40,6 +40,8 @@ Requires-Dist: nbconvert
|
|
40
40
|
Requires-Dist: ipywidgets==8.1.6
|
41
41
|
Requires-Dist: playwright
|
42
42
|
Requires-Dist: yahooquery==2.3.7
|
43
|
+
Requires-Dist: alpha_vantage
|
44
|
+
Requires-Dist: tiingo[pandas]
|
43
45
|
Dynamic: author
|
44
46
|
Dynamic: author-email
|
45
47
|
Dynamic: description
|
@@ -89,7 +89,7 @@ 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=
|
92
|
+
siat/other_indexes.py,sha256=i-yj2wU7mErlSCoNSOSQjY3_HNcI_8gJBs7H0PhiE5U,13353
|
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
|
@@ -102,7 +102,7 @@ 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=
|
105
|
+
siat/security_price2.py,sha256=35AV6zcL-u26uM1MGtyO5bj9uY6CCrdk3MTff5Q-0rc,27465
|
106
106
|
siat/security_prices.py,sha256=HoCZ7YPrQYZHgKC-LyXFeeBCTfRc3EMMEiEg52SVv2w,109073
|
107
107
|
siat/security_prices_test.py,sha256=OEphoJ87NPKoNow1QA8EU_5MUYrJF-qKoWKNapVfZNI,10779
|
108
108
|
siat/security_trend.py,sha256=o0vpWdrJkmODCP94X-Bvn-w7efHhj9HpUYBHtLl55D0,17240
|
@@ -145,8 +145,8 @@ 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.
|
149
|
-
siat-3.9.
|
150
|
-
siat-3.9.
|
151
|
-
siat-3.9.
|
152
|
-
siat-3.9.
|
148
|
+
siat-3.9.20.dist-info/LICENSE,sha256=NTEMMROY9_4U1szoKC3N2BLHcDd_o5uTgqdVH8tbApw,1071
|
149
|
+
siat-3.9.20.dist-info/METADATA,sha256=wXBJpcdrfc32c2wyhu8u4dtuP00jFsatoIMwUw3vVJQ,8396
|
150
|
+
siat-3.9.20.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
|
151
|
+
siat-3.9.20.dist-info/top_level.txt,sha256=r1cVyL7AIKqeAmEJjNR8FMT20OmEzufDstC2gv3NvEY,5
|
152
|
+
siat-3.9.20.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|