Yfinance - 无法获取最近的股票数据

Yfinance - Cannot get recent stock data

抱歉,如果这很明显,但我正在使用 yfinance 创建一个股票分析程序,但这个月我什么也得不到,这是月初(截至现在的 8 月 3 日),但我的程序无法在 7 月 31 日之后获取数据

这是我录制的 5 天节目 window:

from pandas_datareader import data as pdr
import yfinance as yf
import datetime
from dateutil.relativedelta import *
import calendar
yf.pdr_override()

today =datetime.date.today()
yesterday = today-datetime.timedelta(5)

a= pdr.get_data_yahoo('AAPL', start=yesterday,end=today)
print(a)

输出为

                  Open        High         Low       Close   Adj Close    Volume
Date

    2020-07-31  411.540009  425.660004  403.299988  425.040009  425.040009  93584200
  • 指定正确的日期范围
  • 由于今天是星期一,所以今天的数据可能还没有。
from datetime import date, timedelta
import yfinance as yf
from pandas_datareader import data as pdr

start = date(2020, 7, 1)
end = date(2020, 7, 31)

a = yf.download('AAPL', start=start, end=end)

# also works, but you don't need both yf and pdr
a = pdr.data.get_data_yahoo('AAPL', start=start, end=end)

# display(a.head())
                  Open        High         Low       Close   Adj Close    Volume
Date                                                                            
2020-07-01  365.119995  367.359985  363.910004  364.109985  364.109985  27684300
2020-07-02  367.850006  370.470001  363.640015  364.109985  364.109985  28510400
2020-07-06  370.000000  375.779999  369.869995  373.850006  373.850006  29663900
2020-07-07  375.410004  378.619995  372.230011  372.690002  372.690002  28106100
2020-07-08  376.720001  381.500000  376.359985  381.369995  381.369995  29273000

根据您的日期范围

today = date.today()
yesterday = today - timedelta(5)

a = pdr.get_data_yahoo('AAPL', start=yesterday, end=today)

                  High         Low        Open       Close    Volume   Adj Close
Date                                                                            
2020-07-29  380.920013  374.850006  375.000000  380.160004  22582300  380.160004
2020-07-30  385.190002  375.070007  376.750000  384.760010  39532500  384.760010
2020-07-31  425.660004  403.299988  411.540009  425.040009  93584200  425.040009
2020-08-03  446.545685  431.579987  432.799988  435.750000  76237006  435.750000