1

目标:

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

问题

我在谷歌金融上使用该符号,但我不断收到相同的错误“无法读取网址”。我很确定我输入了错误的符号,但我已经尝试了所有我知道的选项,但我不知道还能做什么。我可以在 pandas_datareader 中使用什么符号来提取 S&P 500 的历史数据?任何帮助将不胜感激。

结果

结果与错误

代码

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()
4

0 回答 0