[英]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.