- 指定正确的日期范围
- 由于今天是星期一,因此可能还没有今天的数据。
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