python - 使用 python 下载股票和期权数据
问题描述
我需要下载股票代码的历史“股票数据”和当前“期权价格数据”。有人可以指点我正确的包裹吗?我尝试了 yahoo-finance 软件包,但它不起作用。有人可以发布代码片段以下载相同的内容。我看过几篇下载股票数据的帖子,但没有看到下载期权数据的帖子。因此,对于下载两者的任何帮助将不胜感激。
以下是来自雅虎财经的历史数据和期权数据的链接,仅供参考。
https://finance.yahoo.com/quote/MSFT/history?p=MSFT https://finance.yahoo.com/quote/MSFT/options?p=MSFT
解决方案
您可以使用 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")
推荐阅读
- r - 根据特定模式刮取多个段落
- python - 如何从 Jupyter 笔记本中删除意外的 CSS?
- python - 医学影像数据 - 如何将 .raw/mhd 转换为 Nifti/nii
- node.js - 如何从 ionic 公开静态 html 页面
- express - 无法从 express/npm 模块中找到静态资产
- node.js - 建立数据库连接后如何获取所有文档
- android - Android Studio:膨胀类 android.support.design.widget.FloatingActionButton 时出错
- python-3.x - Google Cloud Speech to Text 中的 enable_speaker_diarization 标记出错
- python - Scrapy 将动态项目导出到 csv
- c++ - 这个 OpenFST 函数中的 `Read` 来自哪里?