Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Download stock and option data using python [closed]

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

like image 283
Raghava kattamudi Avatar asked Aug 26 '26 00:08

Raghava kattamudi


1 Answers

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")
like image 100
atreadw Avatar answered Aug 27 '26 15:08

atreadw



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!