如何从雅虎财经获取每周/每月的历史数据?

发布于 2025-01-11 02:28:37 字数 378 浏览 0 评论 0原文

默认情况下,此代码获取所有收盘日数据或多个股票代码:

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

如何向 Datareader 添加参数以获取每周/每月历史数据?我尝试使用频率和间隔,但它不起作用。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

孤千羽 2025-01-18 02:28:38

如果您尝试在代码中替换弱数据会怎样:

# 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']

对于每月数据:

# 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']

检查 官方文档了解更多选项。在弱周期执行此代码后:

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

我得到了这个:
输入图片此处描述

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

I got this:
enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文