How can get ' USDJPY'(currency rates) with pandas and yahoo finance?

浪尽此生 提交于 2019-12-18 16:48:43

问题


I am learning and using the pandas and python.

Today, I am trying to make a fx rate table, but I got a trouble with getting the pricess of 'USDJPY'.

When I get a prices of 'EUR/USD', i code like this.

eur = web.DataReader('EURUSD=X','yahoo')['Adj Close']

it works.

But when I wrote

jpy = web.DataReader('USDJPY=X','yahoo')['Adj Close']

the error message comes like this:

--------------------------------------------------------------------------- IOError Traceback (most recent call last) in () ----> 1 jpy = web.DataReader('USDJPY=X','yahoo')['Adj Close']

C:\Anaconda\lib\site-packages\pandas\io\data.pyc in DataReader(name, data_source, start, end, retry_count, pause) 70 return get_data_yahoo(symbols=name, start=start, end=end, 71 adjust_price=False, chunksize=25, ---> 72 retry_count=retry_count, pause=pause) 73 elif data_source == "google": 74 return get_data_google(symbols=name, start=start, end=end,

C:\Anaconda\lib\site-packages\pandas\io\data.pyc in get_data_yahoo(symbols, start, end, retry_count, pause, adjust_price, ret_index, chunksize, name) 388 """ 389 return _get_data_from(symbols, start, end, retry_count, pause, --> 390 adjust_price, ret_index, chunksize, 'yahoo', name) 391 392

C:\Anaconda\lib\site-packages\pandas\io\data.pyc in _get_data_from(symbols, start, end, retry_count, pause, adjust_price, ret_index, chunksize, source, name) 334 # If a single symbol, (e.g., 'GOOG') 335 if isinstance(symbols, (basestring, int)): --> 336 hist_data = src_fn(symbols, start, end, retry_count, pause) 337 # Or multiple symbols, (e.g., ['GOOG', 'AAPL', 'MSFT']) 338 elif isinstance(symbols, DataFrame):

C:\Anaconda\lib\site-packages\pandas\io\data.pyc in _get_hist_yahoo(sym, start, end, retry_count, pause) 188 '&g=d' + 189 '&ignore=.csv') --> 190 return _retry_read_url(url, retry_count, pause, 'Yahoo!') 191 192

C:\Anaconda\lib\site-packages\pandas\io\data.pyc in _retry_read_url(url, retry_count, pause, name) 167 168 raise IOError("after %d tries, %s did not " --> 169 "return a 200 for url %r" % (retry_count, name, url)) 170 171

IOError: after 3 tries, Yahoo! did not return a 200 for url 'http://ichart.yahoo.com/table.csv?s=USDJPY=X&a=0&b=1&c=2010&d=1&e=1&f=2014&g=d&ignore=.csv'

Other currencies like 'GBPUSD' also have same problem.

Can you solve this problem?

Do you have any idea of getting 'USDJPY' from yahoo or google???


回答1:


Yahoo Finance doesn't provide historical data on exchange rates (i.e. there's no "Historical Prices" link in the top left of the page like there would be for stocks, indices, etc...)

You can use FRED (Federal Reserve of St. Louis data) to get these exchange rates...

import pandas.io.data as web

jpy = web.DataReader('DEXJPUS', 'fred')

or the more direct way...

jpy = web.get_data_fred('DEXJPUS')

A list of all of the exchange rate that FRED has daily data for can be found here: http://research.stlouisfed.org/fred2/categories/94




回答2:


Yahoo Finance doesn't provide historical data on exchange rates

Yes it does but not on cross rates. All vs the USD List of Yahoo USD Exchange Rates

a = web.DataReader("JPY=X", 'yahoo')



回答3:


Get the historical exchange rates from OANDA http://pandas-datareader.readthedocs.io/en/latest/remote_data.html

In [1]: from pandas_datareader.oanda import get_oanda_currency_historical_rates
In [2]: start, end = "2016-01-01", "2016-06-01"
In [3]: quote_currency = "USD"
In [4]: base_currency = ["EUR", "GBP", "JPY"]
In [5]: df_rates = get_oanda_currency_historical_rates(
            start, end,
            quote_currency=quote_currency,
            base_currency=base_currency
        )
In [6]: print(df_rates)

Update: Oanda started charging for this lately https://www.oanda.com/fx-for-business/exchange-rates-api



来源:https://stackoverflow.com/questions/21483959/how-can-get-usdjpycurrency-rates-with-pandas-and-yahoo-finance

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!