简体   繁体   English

使用pandas web.DataReader从整个索引(例如DJIA)获取数据

[英]Grabbing data from entire index (e.g., DJIA) using pandas web.DataReader

I know how to get individual stocks. 我知道如何获得单个股票。 How might I get data for an entire index, like the DJI? 我如何获取整个数据(例如DJI)的数据? https://www.google.com/finance?q=INDEXDJX%3A.DJI&ei=zsVZU4iADYKI6AGoXA https://www.google.com/finance?q=INDEXDJX%3A.DJI&ei=zsVZU4iADYKI6AGoXA

I'd like to analyze the stock market as a whole from as far back as possible 我想从尽可能远的角度分析整个股市

start, end = dt.datetime(1950, 1, 1), dt.datetime(2013, 12, 31)

data = web.DataReader('.DJI', 'yahoo', start, end)

Google Finance and Yahoo Finance handle their symbols for indices differently. Google Finance和Yahoo Finance处理索引符号的方式不同。 Google would denote the Dow as ".DJI" whereas in Yahoo it would be "^DJI". Google将Dow表示为“ .DJI”,而在Yahoo中则将其表示为“ ^ DJI”。

For some reason when I run the code Pandas is having trouble finding data for the Dow from Yahoo, but it can find it for the S&P and the Nasdaq. 出于某种原因,当我运行代码时,Pandas难以从Yahoo中找到有关道琼斯指数的数据,但可以为标准普尔和纳斯达克找到它。

# this works
web.DataReader('^GSPC','yahoo')  # S&P 500
web.DataReader('^IXIC','yahoo')  # NASDAQ

# this doesn't
web.DataReader('^DJI','yahoo')   # Dow

If you specifically want Dow data, Pandas also lets you use FRED data, so you can get alternatively take that route, though it won't include all the price data, just the close prices. 如果您特别想要道琼斯指数数据,熊猫也可以让您使用FRED数据,因此您可以选择采用该路线,尽管它不包括所有价格数据,仅包括收盘价。

web.DataReader('DJIA','fred')

Another possibility would be to use Quandl . 另一种可能性是使用Quandl They have tons of datasets (financial, economic, demographic, etc.) that might be useful for market analysis. 他们拥有大量的数据集(财务,经济,人口统计等),可能对市场分析有用。 While it still only gets the close prices and requires knowing their sometimes cryptic "codes", here is a sample: 尽管它仍然只能获得收盘价,并且需要知道它们有时是神秘的“代码”,但这里有一个示例:

import Quandl
dow_code = 'BCB/UDJIAD1'
Quandl.get(dow_code)

You may need to create a Quandl account (it's free) to get the authorization token that allows external mining into their database, but this is another possible workaround for you :) 您可能需要创建一个Quandl帐户(免费)以获取允许外部挖掘其数据库的授权令牌,但这是您的另一种可能的解决方法:)

Hope this helps. 希望这可以帮助。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用 web.DataReader、yahoo finance 加载数据时出错 - Error when loading data using web.DataReader, yahoo finance 未获取数据 Web.DataReader Panda - No data fetched Web.DataReader Panda 熊猫根据给定(任意)的datetimeindex重新采样(例如使用最近的值) - Pandas resample on given (arbitrary) datetimeindex (using e.g. nearest) 从 Python 网络应用程序:将数据插入电子表格(例如 LibreOffice / Excel),计算并另存为 pdf - From Python web app: insert data into spreadsheet (e.g. LibreOffice / Excel), calculate and save as pdf 允许用户选择以确定web.DataReader中的库存选择 - Allow user selection to determine the stock selection in web.DataReader 如何在与 web.DataReader 相关的 Python 中修复此错误 - How to fix this error in Python related to web.DataReader 如何从环境中接收数据,例如bash - How to receive data from the environment e.g. bash 从 tensorflow 数据集中提取数据(例如到 numpy) - Extract data from tensorflow dataset (e.g. to numpy) pandas 对象(索引、ndarray 等)和数据类型(例如 bool、int、float)之间的区别? - Difference between pandas objects (index, ndarray, etc) and datatypes (e.g. bool, int, float)? 是否有 Pandas 解决方案(例如:使用 numba 或 Cython)来使用索引、MultiIndexed DataFrame 进行“转换”/“应用”? - Is there a Pandas solution—e.g.: with numba, or Cython—to `transform`/`apply` with an index, a MultiIndexed DataFrame?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM