2

I need to download historical "stock data" and current "option price data" for a ticker. Can someone please point me to right package. I tried yahoo-finance package, but it is not working. Can someone please post a code snippet to download the same. I have seen several posts to download the stock data, but none to download the option data. So, any help to download both would be greatly appreciated.

Here are the links for historical data and options data from yahoo finance, just for your reference.

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

desertnaut
  • 57,590
  • 26
  • 140
  • 166

3 Answers3

5

You can get current options data and historical stock price data with the yahoo_fin package (see here: http://theautomatic.net/yahoo_fin-documentation/). It comes with two modules, stock_info and options.

To get current options data, you can do:

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")

For historical stock price data, you can do:

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")
atreadw
  • 289
  • 2
  • 6
4

I resolved this issue using the robin_stocks python library, which has phenomenal documentation.

The call robin_stocks.options.get_chains('TSLA') will return a dictionary with general options data for a particular ticker. The key 'expiration_dates' has a list of dates for the expiration of options as its value.

Note: You do need a Robinhood account to access this.

Mauro
  • 307
  • 4
  • 8
0

Yahoo Finance has changed many of their API endpoints. The pandas_datareader package has deprecated support for Yahoo due to that. Right now, something like this may be helpful: http://www.blackarbs.com/blog/how-to-build-a-sequential-option-scraper-with-python-and-requests/7/8/2017 It's a mix of Beautiful Soup and other packages to scrape the data off the web. If you want to use an older version of Pandas, you can apply this fix -- but consider that a temporary solution only: https://pypi.org/project/fix-yahoo-finance/ Dirk

user1653205
  • 145
  • 1
  • 8