3

I have python code which only read real live data such currencies:

 df1 = yf.download(tickers = 'audusd' ,period ='1d', interval = '1h')  
 df2 = yf.download(tickers = 'usdjpy' ,period ='1d', interval = '1h')

but for gold (xauusd) and Natural Gas(xbrusd) and others does not work:

df2 = yf.download(tickers = 'xauusd' ,period ='1d', interval = '1h')  does not work
df3 = yf.download(tickers = 'xbrusd' ,period ='1d', interval = '1h') 

does not work

How I can read metal or energy or other from forex using yfinance library ?

Dani Mesejo
  • 61,499
  • 6
  • 49
  • 76
kuwil
  • 39
  • 2

1 Answers1

1

Use pip to install pandas-datareader:

pip install pandas-datareader

If I'm not mistaken, the correct tickers are GC=F for gold and NG=F for natural gas.

from pandas_datareader import data as pdr
import yfinance as yf
yf.pdr_override()

df1 = pdr.get_data_yahoo('AUDUSD=X', period='1d', interval='1h')
df2 = pdr.get_data_yahoo('JPY=X', period='1d', interval='1h')
df3 = pdr.get_data_yahoo('GC=F', period='5d', interval='1h')
df4 = pdr.get_data_yahoo('NG=F', period='5d', interval='1h')

This does work when period='5d', but doesn't work when period='1d'.

Here's a quick start guide on using yfinance.

Luka Banfi
  • 111
  • 8