在今年 5 月 Verizon 收购 yahoo 并终止免费 API 服务后,我在使用 Yahoo Finance 很长时间后不得不切换到 Google Finance。我回去重新研究了这个问题,有人创建了一个新的 Yahoo Finance API 调用,它与新的 yahoo API 一起工作。 https://stackoverflow.com/a/44092983/8316350
python 源码和安装程序可以在这里找到:https://github.com/c0redumb/yahoo_quote_download
参数是(ticker、start_date 和 end_date),其中日期为 yyyymmdd 格式并返回 unicode 字符串列表。以下测试将下载几周的数据,然后仅提取调整后的收盘价以返回名为 adj_close 的列表:
from yahoo_quote_download import yqd
import string
quote = yqd.load_yahoo_quote('AAPL', '20170515', '20170530')
print(quote[0]) # print the column headers
print(quote[1]) # print a couple rows of data
print(quote[2]) # just to make sure it looks right
quote.pop() # get rid of blank string at end of data
quote = [row.encode("utf-8") for row in quote] # convert to byte data
quote = [string.split(row, ',') for row in quote] # split the string to create a list of lists
adj_close = [row[5] for row in quote] # grab only the 'adj close' data and put into a new list
print(adj_close)
返回:
Date,Open,High,Low,Close,Adj Close,Volume
2017-05-15,156.009995,156.649994,155.050003,155.699997,155.090958,26009700
2017-05-16,155.940002,156.059998,154.720001,155.470001,154.861862,20048500
['Adj Close', '155.090958', '154.861862', '149.662277', '151.943314', '152.461288', '153.387650', '153.198395', '152.740189', '153.268112', '153.009140', '153.068893']