I know how to get individual stocks. How might I get data for an entire index, like the DJI? https://www.google.com/finance?q=INDEXDJX%3A.DJI&ei=zsVZU4iADYKI6AGoXA
我知道如何获得个股。我如何获得整个索引的数据,比如DJI?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)
1 个解决方案
#1
6
Google Finance and Yahoo Finance handle their symbols for indices differently. Google would denote the Dow as ".DJI" whereas in Yahoo it would be "^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.
出于某种原因,当我运行这些代码时,熊猫们很难从雅虎找到道琼斯指数的数据,但它可以在标准普尔和纳斯达克找到它。
# 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. 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:
另一种可能是使用Quandl。他们有大量的数据集(金融、经济、人口等)可能对市场分析有用。虽然它仍然只获得了接近的价格,并且需要知道他们有时神秘的“代码”,这里有一个例子:
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.
希望这个有帮助。
#1
6
Google Finance and Yahoo Finance handle their symbols for indices differently. Google would denote the Dow as ".DJI" whereas in Yahoo it would be "^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.
出于某种原因,当我运行这些代码时,熊猫们很难从雅虎找到道琼斯指数的数据,但它可以在标准普尔和纳斯达克找到它。
# 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. 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:
另一种可能是使用Quandl。他们有大量的数据集(金融、经济、人口等)可能对市场分析有用。虽然它仍然只获得了接近的价格,并且需要知道他们有时神秘的“代码”,这里有一个例子:
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.
希望这个有帮助。