我需要下载股票代码的历史“股票数据”和当前的“期权价格数据”。谁能给我指一指正确的包裹。我试过yahoo-finance软件包,但它不起作用。有没有人可以发布一个代码片段来下载同样的代码。我看过几篇下载股票数据的帖子,但都没有下载期权数据的帖子。因此,任何帮助下载两者的人都将不胜感激。
以下是来自雅虎财经的历史数据和期权数据的链接,仅供参考。
https://finance.yahoo.com/quote/MSFT/history?p=MSFT https://finance.yahoo.com/quote/MSFT/options?p=MSFT
发布于 2019-04-13 10:15:33
您可以使用yahoo_fin包(参见此处:http://theautomatic.net/yahoo_fin-documentation/)获取当前期权数据和历史股票价格数据。它有两个模块,stock_info和options。
要获取当前选项数据,您可以执行以下操作:
from yahoo_fin import options
# gets the data for nearest upcoming expiration date
options.get_option_chain("nflx")
# specific expiration date
options.get_options_chain("nflx", "04/26/2019")
# get call options only
options.get_calls("nflx", "04/26/2019")
# get put options only
options.get_puts("nflx", "04/26/2019")对于历史股价数据,您可以执行以下操作:
from yahoo_fin import stock_info as si
# pulls historical OHLC data into a pandas data frame
si.get_data("nflx")
# or some other ticker
si.get_data("insert ticker here")发布于 2020-09-04 07:55:49
我使用robin_stocks python库解决了这个问题,该库具有出色的文档。
调用robin_stocks.options.get_chains('TSLA')将返回一个字典,其中包含特定报价器的常规选项数据。键'expiration_dates‘的值是期权到期日期列表。
注意:您确实需要一个Robinhood帐户才能访问此帐户。
发布于 2019-02-12 00:10:32
雅虎财经已经改变了他们的许多API端点。正因为如此,pandas_datareader包已经不再支持雅虎。现在,像这样的东西可能会有帮助:http://www.blackarbs.com/blog/how-to-build-a-sequential-option-scraper-with-python-and-requests/7/8/2017这是一个美丽的汤和其他包的组合,可以从网络上抓取数据。如果你想使用旧版本的https://pypi.org/project/fix-yahoo-finance/,你可以应用这个补丁--但这只是一个临时的解决方案:
https://stackoverflow.com/questions/53842898
复制相似问题