1

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

这是我录制 5 天窗口的程序:

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
4

1 回答 1

0
  • 指定正确的日期范围
  • 由于今天是星期一,因此可能还没有今天的数据。
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
于 2020-08-04T00:48:05.427 回答