I wanted to learn more about options trading: what type of costs and profits are possible, how the contracts work, and what type of expectation values they have. I wrote a bit of code to scrape some options chains information and gained some experience using Beautiful Soup and Selenium.

Using Beautiful Soup and Selenium was interesting. Beautiful Soup got me to look through and parse HTML code and Selenium was an interesting addition to using Requests for some of the wargames stuff. I ended up using Selenium over Requests so that it could process the JavaScript. Something I had to figure out with Selenium though was that the code in an iframe wasn’t available until I “switched focus” to that part of the page.

I did some math on options chains for some bigger equities such as GLW, COST, CSCO, and so far it looks like (at least for call options for these stocks) the contract requires pretty high confidence in order to be profitable.

Below is the README markdown file for the code, which is here.

Background

This package scrapes YF for options contract information using Selenium and Beautiful Soup. It will download a list of available expiration dates for a given equity, then download options information such as strike price, bids and asks, implied volatility, etc. that are available on the site. Note that the information sometimes seems to be outdated or incorrect in comparison to information from privately available data (e.g. from a brokerage).

Usage

An object is created for each equity which stores the options contracts information:

from code import options
XYZoptions = options("XYZ")

The object has three important variables.

The information that is available is listed in the fieldnames variable:

self.fieldnames = ['symbol',
                   'type',
                   'expiration date',
                   'strike',
                   'contract name',
                   'last price',
                   'bid',
                   'ask',
                   'change',
                   'change%',
                   'volume',
                   'open interest',
                   'implied volatility'
                   ]

The object has a few important methods.

Therefore, typical usage will consist of:

from code import options
XYZoptions = options("XYZ")
XYZoptions.getdates()
XYZoptions.getoptionschain()
XYZoptions.writedata()

Requirements

This code requires Selenium and Beautiful Soup ChromeDriver is by Selenium, and should be downloaded. The code assumes it is located at “C:\Program Files (x86)\Google\Chrome\Application\”.

Todo: