【问题标题】:Python: using Google Finance to download index dataPython:使用谷歌财经下载索引数据
【发布时间】:2017-05-23 13:51:32
【问题描述】:

我已成功从 Google 财经下载股票数据,如下所示:

import pandas as pd
from pandas_datareader import data as web   
import datetime
start = datetime.datetime(2016,1,1)
end   = datetime.date.today()
apple = web.DataReader('aapl', 'google', start, end)

我认为我可以对索引数据使用相同的框架。但这不起作用:

spx = web.DataReader('INDEXSP', 'google', start, end)

RemoteDataError: Unable to read URL: http://www.google.com/finance/historical

Google 不支持此索引吗?

或者我需要不同的协议吗?

【问题讨论】:

  • 我也在为此苦苦挣扎。最终,我只是去寻找 csv 格式的数据下载,然后使用 pd.read_csv 将其导入 python

标签: python yahoo-finance quantitative-finance google-finance google-finance-api


【解决方案1】:

索引数据可用:

假设您调用了一个<instrument>,Google API 还没有准备好映射到它的历史记录,try to find the proper <instrument> name manually first.

S&P 500 INDEX ( INDEXCBOE:SPX )
v/s
标准普尔 500 (INDEXSP:.INX)
...
DAX 绩效指数 (INDEXDB:DAX)


在 Google 财经方面工作和提供数据:

【讨论】:

  • 那也行不通。 web.DataReader('INDEXCBOE:SPX', 'google', start, end) 仍然返回相同的错误。
  • 在这种情况下,问题不在于 Google Finance 后端处理,而在于 .DataReader() 实现,因为 Google 提供数据,QED 在点击中上面的链接。如果当前的.DataReader() 实现对<instrument> 名称进行了一些修改,请尝试上面的第二个建议,使用"aapl" -> "(NASDAQ:AAPL)" 类比,其中.DataReader() 将股票代码转换为完全限定的工具名称。 测试一个命名为".INX"<instrument>,它应该被正确地翻译成INDEXSP:.INX。如果不是,.DataReader() 实现将失败。
  • 明确一点,INDEXCBOE:SPX 和 INDEXSP:.INX 都不起作用。
  • 好的,问题仍然存在于 .DataReader() 实现中。 Q.E.D.感谢您分享您的经验。
  • 不太确定这个@user3666197。只是确认数据已显示并不意味着它可以作为 csv 使用。路径应该是finance.google.com/finance/…,但该链接已损坏。您可以确认它适用于 etf (SPY):finance.google.com/finance/historical?q=SPY&startdate=2017/…
【解决方案2】:

对于 DAX,您可以使用从 google 下载的“NASDAQ:DAX”和 datareader。但是,这只 ETF 仅从 2014-10-23 开始。

【讨论】:

    【解决方案3】:

    这是 Google 方面的一个问题。将the S&P 的历史价格页面与Google 的历史价格页面进行比较,您会发现后者具有“下载到电子表格”的链接,而前者没有。 pandas-datareader 只是关闭了这个 csv 链接。

    因此,对于您的评论,我不会认为这是 pandas-datareader 中的一个损坏的实现,只是在 Google Finance 不提供该 .csv 的情况下不起作用。

    【讨论】:

      猜你喜欢
      • 2014-08-14
      • 1970-01-01
      • 2019-09-12
      • 2017-12-28
      • 2011-09-14
      • 2012-06-26
      • 1970-01-01
      • 2015-07-20
      • 2021-10-29
      相关资源
      最近更新 更多