无法在Google财经上使用pandas_datareader阅读S& P500

时间:2017-05-29 06:34:46

标签: python python-3.x google-finance pandas-datareader

目标:

我尝试使用pandas_datareader从Google财经中读取S& P500的历史数据。

问题

我在谷歌财务上使用了这个符号,但我一直收到相同的错误"无法读取网址"。我很确定我输入了错误的符号但我已经尝试了所有我知道的选项而且我不知道还能做什么。我可以使用什么符号与pandas_datareader一起提取S& P 500的历史数据?任何帮助将不胜感激。

结果

Results & Errors

代码

import urllib, sys, pandas, pandas_datareader
from yahoo_finance import Share
from bs4 import BeautifulSoup
from pandas_datareader import data
import fix_yahoo_finance
from datetime import datetime

def Main():
    datetime_start = datetime(2010, 1, 1)
    datetime_finish = datetime(2013, 1, 27)

    f_google = data.DataReader('F', 'google', datetime_start, datetime_finish)
    print('Ford on google, symbol "F", on 04 January 2010: %s' %f_google.loc['2010-01-04'])

    sp_500_yahoo = Share('^GSPC')
    print('Yahoo S&P 500: %s' %sp_500_yahoo.get_price())

    list_symbols = ['INDEXSP:.INX', 'INDEXSP', '.INX', 'INDEXSP:', '^GSPC', 'SPX']

    for string_symbol in list_symbols:
        try:
            sp500_google = data.DataReader(string_symbol, 'google', start = datetime_start, end = datetime_finish)
            print('\nS&P 500 on google, symbol %s, on 04 January 2010: %s' %(string_symbol, sp500_google.loc['2010-01-04']))
            except Exception as e:
                string_error = str(e.args)
                print('\nError for S&P 500 symbol %s on google: %s' %(string_symbol, string_error))
        else:
           pass
        finally:
           pass

     # system info
     print('\npython version: %s' %sys.version)
     print('pandas version: %s' %pandas.__version__)
     print('pandas_datareader version: %s' %pandas_datareader.__version__)
     print('fix_yahoo_finance version: %s' %fix_yahoo_finance.__version__)

if __name__ == '__main__':
     Main()

0 个答案:

没有答案