Skip to content Skip to sidebar Skip to footer

How Can Get ' Usdjpy'(currency Rates) With Pandas And Yahoo Finance?

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

Solution 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.dataas web

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

UPDATE: hase moved the pandas-datareader

from pandas_datareader importdata
jpy = data.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

Solution 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')

Solution 3:

The free and easy way is Yahoo:

# get fx rates# https://finance.yahoo.com/currencies# example EUR/USD = EURUSD%3DX?p=EURUSD%3DXimport 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 symbolprint('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 useprint('This is the Adj Close prices only')
print(eurusd['Adj Close'])

and it also works with other crosses, contrary to the above statements:

# EURCHF%3DX
eurchf = dr.data.DataReader('EURCHF%3DX', data_source='yahoo', start=start_date, end=end_date)
print(eurchf)

Solution 4:

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

Solution 5:

#!pip install yfinance#!pip install mplfinancefrom 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 symbolprint('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

Post a Comment for "How Can Get ' Usdjpy'(currency Rates) With Pandas And Yahoo Finance?"