Webscrapping Options Data with Python and YFinance

Tony Lian
3 min readJun 28, 2020

Options data is often very hard to get, especially in a way that you can pull into a workable format for your own analysis. One of the best sources out there that is still open is Yahoo Finance and the yfinance python package.

Installation:

pip install yfinance

I won’t go through the basics of the package here as the documentation already does that. https://pypi.org/project/yfinance/

What I do want to focus on is how to cleanly pull the entire options chain. The example given would only get a singular expiration. In the code below, we loop through each expiration to return the entire options surface across all expiration dates.

The function will return a Pandas DataFrame that looks like the one below.

Analysis on the Data

From here, we have some workable data to actually perform some market analysis. For instance, we could easily plot the volatility smiles for each expiration. I’m partial to the Bokeh package due to the customizability and cleanness.

We can also plot the volume and open interest on each strike. In the world of options market-making, calls and puts are the same once they are delta hedged. The details on this are for another post so you’ll just have to take my word on this. The key idea here is that under Black Scholes, calls and puts have the same greeks except for delta. Anyways, on to the plots.

Observations we can draw from our analysis

  • We can see that the majority of the volume on the day is concentrated in the front terms.
  • Most market participants are trading for Gamma instead of for Vega.
  • We also see that there’s an enormous amount of open interest in July 17 on the 55, 57.5, and 60 strikes.

Further Application

I have been using this script to automatically pull data at the end of the each trading day to create my own historical dataset. Stayed tuned for more analysis!

Disclaimer: This content is for information purposes only. It is not intended to be investment advice. Seek a duly licensed professional for investment advice.

--

--