使用 python 下载股票和期权数据

Rag*_*udi 3 python finance google-finance stock yahoo-finance

我需要下载股票的历史“股票数据”和当前的“期权价格数据”。有人可以指出我正确的包裹吗?我尝试了 yahoo-finance 软件包,但它不起作用。有人可以发布一个代码片段来下载它吗?我看过几篇下载股票数据的帖子,但没有看到下载期权数据的帖子。因此,任何下载两者的帮助将不胜感激。

以下是雅虎财经的历史数据和期权数据的链接,仅供大家参考。

https://finance.yahoo.com/quote/MSFT/history?p=MSFT https://finance.yahoo.com/quote/MSFT/options?p=MSFT

小智 5

您可以使用 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")
Run Code Online (Sandbox Code Playgroud)

对于历史股价数据,您可以这样做:

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")
Run Code Online (Sandbox Code Playgroud)