我正在学习并使用pandas和python。
今天,我正在尝试制作一个fx费率表, 但是我在获得'USDJPY'的价格方面遇到了麻烦。
当我得到'EUR / USD'的价格时,我的代码是这样的。
eur = web.DataReader('EURUSD=X','yahoo')['Adj Close']
它有效。
但是当我写作
时jpy = web.DataReader('USDJPY=X','yahoo')['Adj Close']
错误信息如下:
----------------------------------------------- ---------------------------- IOError Traceback(最近一次调用 最后)in() ----> 1 jpy = web.DataReader('USDJPY = X','yahoo')['Adj Close']
C:\ Anaconda \ lib \ site-packages \ pandas \ io \ data.pyc在DataReader中(名称, data_source,start,end,retry_count,pause) 70返回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返回get_data_google(symbols = name,start = start,end = end,
C:\ Anaconda \ lib \ site-packages \ pandas \ io \ data.pyc in get_data_yahoo(符号,开始,结束,重试_计数,暂停,调整_价格, 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#如果是单个符号,(例如'GOOG') 335 if isinstance(symbols,(basestring,int)): - > 336 hist_data = src_fn(符号,开始,结束,重试_计数,暂停) 337#或多个符号,(例如,['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提高IOError(“%d尝试后,%s没有” - > 169“为网址%r返回200”%(retry_count,name,url)) 170 171
IOError:经过3次尝试,雅虎!没有为网址返回200 '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'
其他货币如'GBPUSD'也有同样的问题。
你能解决这个问题吗?
你有什么想法从雅虎或谷歌获得'USDJPY'
答案 0 :(得分:10)
雅虎财经不提供汇率历史数据(即页面左上方没有“历史价格”链接,就像股票,指数等一样......)
您可以使用FRED(美国联邦储备局圣路易斯数据)获取这些汇率......
import pandas.io.data as web
jpy = web.DataReader('DEXJPUS', 'fred')
或更直接的方式......
jpy = web.get_data_fred('DEXJPUS')
可在此处找到FRED每日数据的所有汇率列表:http://research.stlouisfed.org/fred2/categories/94
答案 1 :(得分:9)
雅虎财经不提供汇率历史数据
是的,但不是交叉汇率。所有对美元 List of Yahoo USD Exchange Rates
a = web.DataReader("JPY=X", 'yahoo')
答案 2 :(得分:1)
从OANDA获取历史汇率 http://pandas-datareader.readthedocs.io/en/latest/remote_data.html
<Scene
key="gray"
component={GrayScreen}
title="Gray"
animation={(Platform.OS === 'ios') ? '' : 'fade'}
hideBackImage={!(Platform.OS === 'ios')}
/>
更新:Oanda最近开始收费 https://www.oanda.com/fx-for-business/exchange-rates-api
答案 3 :(得分:1)
免费且简单的方法是雅虎:
# get fx rates
# https://finance.yahoo.com/currencies
# example EUR/USD = EURUSD%3DX?p=EURUSD%3DX
import pandas as pd
import pandas_datareader as dr
# change date range here
start_date = '2021-02-26'
end_date = '2021-03-01'
# retrieve market data of current ticker symbol
print('This is the table with HLOC, Volume, Adj Close prices')
eurusd = dr.data.DataReader('EURUSD%3DX', data_source='yahoo', start=start_date, end=end_date)
print(eurusd)
# just get latest adjusted close for further use
print('This is the Adj Close prices only')
print(eurusd['Adj Close'])
它也适用于其他十字架,与上述陈述相反:
# EURCHF%3DX
eurchf = dr.data.DataReader('EURCHF%3DX', data_source='yahoo', start=start_date, end=end_date)
print(eurchf)
答案 4 :(得分:0)
#!pip install yfinance
#!pip install mplfinance
from datetime import datetime
import yfinance as yf
import mplfinance as mpf
#import pandas as pd
#import pandas_datareader as dr
# change date range here
start_date = '2021-02-26'
end_date = '2021-03-01'
#This Does NOT WORK#
# retrieve market data of current ticker symbol
print('This is the table with HLOC, Volume, Adj Close prices')
eurusd = dr.data.DataReader('EURUSD%3DX', data_source='yahoo',
start=start_date, end=end_date)
print(eurusd)
#This Does#
data = yf.download('USDCAD=X', start=start_date, end=end_date)
#If someone can figure out how to get the S5,S30, M1, M3 etc. Please share