Yahoo Pandas datareader 日期差异

Yahoo Pandas datareader date difference

我正在尝试使用 Yahoo API 作为来源导入股票数据。我已经尝试了很多次,但我总是得到同样的错误,开始和结束日期与我通过的不同。例如,我将开始和结束日期作为 '2015-1-1' & '2017-1-1' 传递,但我得到的股票数据开始和结束于 “2014-12-31”和“2016-12-30”。我不知道我做错了什么。我什至尝试使用 google 但出现错误“data_sorce='google' 未实现。” 在使用 Yahoo 时,是否有其他免费数据源可供我使用或更正日期? Jupyter notebook

您可以导入为 yfinance and just enter a start and end when importing the data. Yahoo decommissioned their historical data API check out the Ran Aroussi the developer's of fix-yahoo-finance which is now yfinance blog where he details everything nicely https://aroussi.com/post/python-yahoo-finance

到 install/upgrade yfinance 使用 pip,运行:

$ pip install yfinance

而不是这种方法

facebook = web.DateReader("FB", "yahoo", start, end)

可以改为这样的格式

通过将数据导入为 pdr

覆盖 pandas_datareader 的方法
import yfinance as yf
yf.pdr_override() # <== the override :-)

# download dataframe using pandas_datareader
facebook = pdr.get_data_yahoo("FB", start="2015-1-1", end="2017-1-1")

或者您可以直接使用 yfinance

import yfinance as yf
facebook = yf.download("FB", start="2015-1-1", end="2017-1-1")