Reputation: 11
By default, this code obtains all the closing days data or several Tickers:
tickers = ['SPY', 'QQQ', 'GLD ', 'EEM', 'IEMG', 'VTI', 'HYG', 'SJNK', 'USO']
ind_data = pd.DataFrame()
for t in tickers:
ind_data[t] = wb.DataReader(t,data_source='yahoo', start='2015-1-1')['Adj Close']
ind_data.to_excel('C:/Users/micka/Desktop/ETF.xlsx')
How do you add a parameter to Datareader in order to obtain weekly/monthly historical data instead? I tried using freq and interval but it doesn't work.
Upvotes: 1
Views: 2662
Reputation: 6375
What if you try to replace this in your code for weakly data:
# Don't forget to import pandas_datareader exactly in this way
import pandas_datareader
# Then replace this in for loop
pandas_datareader.yahoo.daily.YahooDailyReader(t, interval='w' , start='2015-1-1').read()['Adj Close']
And this for monthly data:
# Don't forget to import pandas_datareader exactly in this way
import pandas_datareader
# Then replace this in for loop
pandas_datareader.yahoo.daily.YahooDailyReader(t, interval='m' , start='2015-1-1').read()['Adj Close']
Check official doc for further options. After executing this code for the weakly period:
import pandas_datareader
tickers = ['SPY', 'QQQ', 'GLD ', 'EEM', 'IEMG', 'VTI', 'HYG', 'SJNK', 'USO']
ind_data = pd.DataFrame()
for t in tickers:
ind_data[t] = pandas_datareader.yahoo.daily.YahooDailyReader(t, interval='w' , start='2015-1-1').read()['Adj Close']
ind_data
Upvotes: 1