通过python中的yahoo和pandas_datareader获取来自不同市场的市场数据
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了通过python中的yahoo和pandas_datareader获取来自不同市场的市场数据相关的知识,希望对你有一定的参考价值。
因此,市场之间的冗余标签名称有点问题。例如,使用以下代码获取数据时:
from pandas_datareader import data as pdr
from datetime import datetime
data = pdr.get_data_yahoo(['AC'], start=datetime(2020,1,6), end=datetime(2020,2,6))
我要返回的数据是NYSE:AC
(美国国会大厦集团公司)还是TSE:AC
(加拿大航空)?
答案
据我了解,不带点和extension name
的默认值来自美国市场。股票代码的扩展名表示除美国以外的市场。这里有一些例子。
AC.TO : Toronto
AC.PA : Paris
AC.MX : Mexico
AC.VI : Vienna
FPI1.BE : Berlin
F7TB.MU : Munich
以下可以得到longName
的ticker
。
from datetime import datetime
import pandas_datareader.data as web
tickers = ['AC', 'AC.TO']
for ticker in tickers:
print('
---------------------------------------------------------------
')
data = web.get_data_yahoo([ticker], start=datetime(2020, 1, 6), end=datetime(2020, 2, 6))
df = web.get_quote_yahoo([ticker])
print(df[['longName', 'exchange', 'fullExchangeName', 'currency', 'quoteType', ]].T)
print()
print(data)
以下是上面代码的输出:
---------------------------------------------------------------
AC
longName Associated Capital Group, Inc.
exchange NYQ
fullExchangeName NYSE
currency USD
quoteType EQUITY
Attributes High Low Open Close Volume Adj Close
Symbols AC AC AC AC AC AC
Date
2020-01-06 39.790001 38.490002 38.490002 39.790001 3300 39.790001
2020-01-07 39.669998 38.590000 39.540001 39.160000 6200 39.160000
2020-01-08 39.790001 38.560001 38.889999 39.790001 6400 39.790001
2020-01-09 39.830002 39.750000 39.830002 39.750000 1800 39.750000
2020-01-10 39.520000 39.099998 39.520000 39.500000 5100 39.500000
2020-01-13 42.759998 39.250000 39.250000 42.759998 23000 42.759998
2020-01-14 47.779999 43.029999 43.160000 47.770000 13000 47.770000
2020-01-15 48.501999 47.049999 48.299999 48.419998 21400 48.419998
2020-01-16 52.820000 48.134998 48.160000 50.410000 10200 50.410000
2020-01-17 52.595001 50.160000 51.200001 51.080002 21400 51.080002
2020-01-21 65.459999 50.549999 50.709999 63.580002 42700 63.580002
2020-01-22 64.900002 56.000000 64.900002 57.220001 30700 57.220001
2020-01-23 57.480000 46.959999 57.480000 47.340000 26100 47.340000
2020-01-24 47.779999 42.299999 47.340000 42.349998 30000 42.349998
2020-01-27 48.540001 42.500000 42.500000 43.759998 28100 43.759998
2020-01-28 45.000000 43.040001 43.349998 43.880001 11700 43.880001
2020-01-29 43.689999 41.099998 43.689999 41.459999 15200 41.459999
2020-01-30 43.700001 41.730000 42.110001 42.790001 21900 42.790001
2020-01-31 42.730000 41.189999 42.299999 41.770000 20300 41.770000
2020-02-03 43.410000 42.020000 42.320000 42.279999 10900 42.279999
2020-02-04 43.299999 41.799999 42.490002 41.799999 16300 41.799999
2020-02-05 44.299999 41.730000 42.160000 43.889999 15200 43.889999
2020-02-06 45.430000 43.590000 43.937000 43.720001 19700 43.720001
2020-02-07 44.158001 41.290001 43.700001 41.290001 12600 41.290001
---------------------------------------------------------------
AC.TO
longName Air Canada
exchange TOR
fullExchangeName Toronto
currency CAD
quoteType EQUITY
Attributes High Low Open Close Volume Adj Close
Symbols AC.TO AC.TO AC.TO AC.TO AC.TO AC.TO
Date
2020-01-06 47.820000 47.110001 47.610001 47.299999 1134902 47.299999
2020-01-07 48.270000 47.200001 47.299999 48.240002 863739 48.240002
2020-01-08 49.279999 47.750000 47.750000 49.040001 1193122 49.040001
2020-01-09 50.389999 49.070000 49.119999 49.599998 1388006 49.599998
2020-01-10 51.014999 49.200001 49.590000 50.900002 1443019 50.900002
2020-01-13 52.180000 50.470001 50.849998 52.090000 1388026 52.090000
2020-01-14 52.709999 51.490002 52.029999 52.009998 1352906 52.009998
2020-01-15 52.459999 51.340000 51.930000 51.540001 1108539 51.540001
2020-01-16 52.220001 51.560001 51.700001 51.790001 930670 51.790001
2020-01-17 51.520000 50.160000 50.480000 51.080002 1767395 51.080002
2020-01-20 51.410000 50.660000 50.820000 51.150002 310712 51.150002
2020-01-21 50.610001 47.680000 50.500000 48.840000 3095071 48.840000
2020-01-22 49.680000 48.639999 49.299999 48.680000 1282190 48.680000
2020-01-23 49.000000 47.009998 48.459999 48.419998 2001993 48.419998
2020-01-24 48.580002 45.770000 48.450001 47.180000 2416449 47.180000
2020-01-27 45.529999 43.400002 43.410000 44.740002 2709248 44.740002
2020-01-28 45.770000 44.689999 45.119999 45.099998 2257306 45.099998
2020-01-29 45.959999 44.709999 45.279999 45.599998 1916354 45.599998
2020-01-30 45.200001 44.180000 45.099998 44.930000 1586113 44.930000
2020-01-31 45.139999 44.154999 44.630001 44.330002 1529131 44.330002
2020-02-03 45.180000 44.119999 44.369999 44.779999 1499613 44.779999
2020-02-04 47.250000 45.520000 45.590000 46.509998 1812547 46.509998
2020-02-05 48.060001 46.400002 47.250000 46.700001 1971011 46.700001
2020-02-06 47.130001 46.330002 47.000000 46.349998 1373740 46.349998
2020-02-07 46.250000 45.040001 46.250000 45.459999 1316269 45.459999
以上是关于通过python中的yahoo和pandas_datareader获取来自不同市场的市场数据的主要内容,如果未能解决你的问题,请参考以下文章
使用 Python 抓取 Yahoo Finance 的资产负债表
Python、Pandas 数据读取器和 Yahoo 错误 RemoteDataError:无法读取 URL
在 Yahoo! 上通过“data-reactid”查找元素金融[关闭]