【问题标题】:pandas data reader google finance for australian stock exchangepandas data reader 谷歌金融澳大利亚证券交易所
【发布时间】:2016-05-29 09:09:35
【问题描述】:

无法使用 pandas 和专门针对澳大利亚证券交易所的股票代码的新数据阅读器模块从 Google Finance 获取报价。

每只股票的相关谷歌财经页面将它们列为: 联邦银行 asx:cba billabong 国际 asx:bbg 等

然而,pandas datareader 不排除格式为 asx:stock_code 的代码,例如 asx:cba

import pandas
from pandas_datareader import data
import datetime
start = datetime.datetime(2016, 5, 27)
end = datetime.datetime(2016, 5, 27)
f = web.DataReader('bbg:asx', 'google', start, end)

pandas datareader module on github pandas datareader 功能现在与 pandas 库本身分离 pandas datareader read the docs

必须使用什么语法才能让 pandas datareader 的 google 财务模块返回 ASX 上澳大利亚股票价格的 pandas 数据框?

【问题讨论】:

    标签: python pandas


    【解决方案1】:

    Google 财经,作为雅虎财经,对通过其网站提供的数据设置了一些限制,可通过GET 请求获得。您可以看到ASX:BBG(和其他ASX 股票)在historical prices 网站上缺少'export to spreadsheet' 选项(例如,与NASDAQ:GOOGL 相比)。

    您还可以使用以下方法检查代码语法 ASX:BBG 是否正确:

    import pandas as pd
    url = 'https://www.google.com/finance/historical'
    params = {'q': 'ASX:BBG'}
    r = requests.get(url=url, params=params)
    
    pd.read_html(r.content)[2]
    

    产生前 30 个分页结果:

                   0     1     2     3      4       5
    0           Date  Open  High   Low  Close  Volume
    1   May 27, 2016  1.44  1.46  1.40   1.46       0
    2   May 26, 2016  1.36  1.48  1.36   1.46       0
    3   May 25, 2016  1.38  1.40  1.36   1.38       0
    4   May 24, 2016  1.38  1.39  1.35   1.38       0
    5   May 23, 2016  1.33  1.42  1.32   1.42       0
    6   May 20, 2016  1.33  1.35  1.32   1.33       0
    7   May 19, 2016  1.39  1.40  1.33   1.34       0
    8   May 18, 2016  1.38  1.40  1.37   1.39       0
    9   May 17, 2016  1.36  1.38  1.36   1.38       0
    10  May 16, 2016  1.38  1.38  1.32   1.36       0
    11  May 13, 2016  1.36  1.40  1.35   1.38       0
    12  May 12, 2016  1.33  1.38  1.33   1.36       0
    13  May 11, 2016  1.32  1.39  1.32   1.35       0
    14  May 10, 2016  1.26  1.33  1.26   1.32       0
    15   May 9, 2016  1.30  1.32  1.27   1.27       0
    16   May 6, 2016  1.30  1.32  1.28   1.32       0
    17   May 5, 2016  1.31  1.31  1.28   1.30       0
    18   May 4, 2016  1.30  1.32  1.26   1.30       0
    19   May 3, 2016  1.32  1.33  1.24   1.32       0
    20   May 2, 2016  1.36  1.36  1.29   1.33       0
    21  Apr 29, 2016  1.32  1.37  1.30   1.36       0
    22  Apr 28, 2016  1.35  1.36  1.28   1.30       0
    23  Apr 27, 2016  1.38  1.40  1.34   1.36       0
    24  Apr 26, 2016  1.40  1.41  1.37   1.38       0
    25  Apr 22, 2016  1.42  1.43  1.41   1.42       0
    26  Apr 21, 2016  1.44  1.46  1.42   1.42       0
    27  Apr 20, 2016  1.48  1.48  1.42   1.46       0
    28  Apr 19, 2016  1.48  1.52  1.44   1.46       0
    29  Apr 18, 2016  1.50  1.52  1.48   1.48       0
    30  Apr 15, 2016  1.50  1.54  1.49   1.50       0
    

    因此,您可以像这样修改params

    from datetime import date
    params = {'q': 'ASX:BBG', 'startdate':date(2016,4,1), 'enddate':date(2016,5,1)}
    

    遍历不同的时间段:

                   0     1     2     3      4       5
    0           Date  Open  High   Low  Close  Volume
    1   Apr 29, 2016  1.32  1.37  1.30   1.36       0
    2   Apr 28, 2016  1.35  1.36  1.28   1.30       0
    3   Apr 27, 2016  1.38  1.40  1.34   1.36       0
    4   Apr 26, 2016  1.40  1.41  1.37   1.38       0
    5   Apr 22, 2016  1.42  1.43  1.41   1.42       0
    6   Apr 21, 2016  1.44  1.46  1.42   1.42       0
    7   Apr 20, 2016  1.48  1.48  1.42   1.46       0
    8   Apr 19, 2016  1.48  1.52  1.44   1.46       0
    9   Apr 18, 2016  1.50  1.52  1.48   1.48       0
    10  Apr 15, 2016  1.50  1.54  1.49   1.50       0
    11  Apr 14, 2016  1.50  1.54  1.48   1.52       0
    12  Apr 13, 2016  1.47  1.52  1.47   1.48       0
    13  Apr 12, 2016  1.49  1.54  1.46   1.48       0
    14  Apr 11, 2016  1.50  1.54  1.46   1.54       0
    15   Apr 8, 2016  1.51  1.52  1.48   1.50       0
    16   Apr 7, 2016  1.52  1.56  1.52   1.54       0
    17   Apr 6, 2016  1.59  1.60  1.51   1.52       0
    18   Apr 5, 2016  1.66  1.66  1.58   1.60       0
    19   Apr 4, 2016  1.78  1.80  1.66   1.68       0
    20   Apr 1, 2016  1.81  1.82  1.76   1.77       0
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-12-05
      • 2017-09-19
      • 2021-09-03
      • 2012-05-22
      • 2010-11-21
      • 1970-01-01
      • 2015-06-04
      • 1970-01-01
      相关资源
      最近更新 更多