How To Download Options Data From Yahoo Finance & CBOE

My inbox gets bombarded with options traders selling their options trading courses and software. I thought this time I should write a post on how you can download options data from Yahoo Finance. Options trading has become very popular in the last few years. Options are a bit complicated to trade. So don’t try to trade them if you have never traded them before. First get some training and only then think about trading them. Options are derivative contracts. The concept is simple and beautiful. Instead of buying the stock, you buy the right to buy or sell that stock at a certain price before expiry. Now you pay a premium to buy options on a certain stock. You are at liberty to not exercise your right to buying or selling a stock provided by the options contract. So you are not obligated to buy or sell the stock when you buy an options contract.Apple stock AAPL is very popular amongst the traders. Watch this 25 minute video on how to predict AAPL.

Call option gives you the right but not the obligation to buy a stock at a certain price known as the strike price before expiry. A call option is like going long on a stock. If stock price rises above the strike price, you can earn a substantial profit by exercising you call options contract. If the stock price stays below the strike price, you can let the call options contract expire without exercising it. Watch this 50 minute documentary on Black Wednesday. In the same manner a put option gives you the right to sell a stock but not the obligation before the expiry at a certain price known as strike price.If stock price falls below the strike price, you can exercise the options contract and earn profit. If the stock price stays above the strike price, you can let your put option expire without exercising it. There are many traders who write options on the stock they own and sell them in the market. This earns them a premium which is an additional income. There is a stock buying strategy that lets you buy your favorite stock at a lower price by writing options contracts on them. You can watch this presentation by Doc Severson on how to create a monthly income with trading options..

The price of option contract known as premium depends on the current price of the underlying stock as well as the strike price of the contract, the time to expiry, the volatility of the underlying stock and the interest rate in the market. There is an element of inbuilt leverage in an options contract. Options are used to limit risk as well as benefit from the inbuilt leverage. Most options contract are offered on a monthly basis with duration ranging from a few days to a few months and can be upto 20 years. An options contract gives you the right to buy or sell 100 shares of the underlying stocks. Download this ebook how I made $2 million in the stock market.

Downloading Google Stock GOOG Options Data From Yahoo Finance

Let’s try to find all the options contract on Google stock GOOG. Below is the python code that will read Yahoo Finance for all the options put/call contracts listed on Yahoo Finance.We will be using pandas. Pandas is a powerful python library that you should master as you will be using it often.

#import pandas module
import pandas as pd
from pandas_datareader import data as web
#download all options contacts on Google stock
goog_options = web.Options('GOOG', 'yahoo')
goog_options = goog_options.get_all_data().reset_index()

Now let’s explore how many contracts have been downloaded. Did you read the post on how a guy trading from home crashed S&P 500? You should read this post in which explain how did the Flash Crash of May 2010 happened.

goog_options.shape

aos = goog_options.sort(['Expiry', 'Strike'])[['Expiry', 'Strike', 'Type', 'IV', 'Bid',
'Ask', 'Underlying_Price']]

#find the expiry dates
aos['Expiry'].unique()
aos.loc[1025]

First python command ask for the size of the dataframe. We have 1059 rows with 19 columns. So we have 1059 options contract that are being written on GOOG. In the second command we sort out the required data from the 19 columns. The last command asks for the expiry and the options contract listed at 1025th row. This is what we get. Before that did you take a look at our Probability & Statistics Course for Traders? This is a crash course on probability and statistics for traders. Most traders don’t know probability and statistics. In this course we teach you step by step how you can use probability and statistics in your trading on a daily basis.

>> aos.loc[1025]
Expiry              2017-06-16 00:00:00
Strike                             1100
Type                               call
IV                             0.242317
Bid                                0.05
Ask                                0.65
Underlying_Price                 829.08
Name: 1025, dtype: object>> >

From the above lines we can see the options contract listed at 1025 expires on 16th June 2017. Watch this 50 minute documentary on Wall Street Quants. The strike price is $1100 per share. It is a call option. The underlying price is $829 per share right now. So we are a long way to go. There are still 4 months left before expiration. Miracle can take place and GOOG can go above $1100 per share before the expiry. If GOOG price doesn’t go above $1100 per share we should let this call options contract to expire unexercised. Precisely because of the very low chance of GOOG price going above $1100 per share this options contract is priced at $0.05 per share. Since each contract controls 100 shares of GOOG, you will pay $5 for this call options contract. This was the premium to buy the call options contract. Now if you want to exercise this options contract, you will have to buy GOOG at $1100 per share. Of course you are not going to do that since GOOG is trading at $829 per share right now so you will let it expire without exercising it. Did you read the post on how to plot candlestick plots of stock OHLC price using python?

Plotting The Implied Volatility Of GOOG Call Options

IV is implied volatility. Implied volatility is different than the historical volatility. Historical volatility is just the standard deviation of a past stock returns. Usually the standard deviation is calculated on the window of 1 year. Implied volatility is more important when we trade options. We need implied volatility if we want to calculate the option price. We don’t go into the detail now. But in a future post we are going to discuss implied volatility more. First let’s shortlist all the call options contract that have expiry of 2017-06-16.

#explore the implied volatility
aos.tail()
calls1 = aos[(aos.Expiry=='2017-06-16') & (aos.Type=='call')]
calls1[:5]
calls1.shape

When we run the above python we get the following output:

>> calls1 = aos[(aos.Expiry==’2017-06-16′) & (aos.Type==’call’)]
Expiry  Strike  Type        IV    Bid    Ask  Underlying_Price
2  2017-06-16     350  call  0.769900  479.6  481.5            829.08
9  2017-06-16     370  call  0.000010    0.0    0.0            829.08
14 2017-06-16     380  call  0.709353  449.7  451.6            829.08
20 2017-06-16     390  call  0.000010    0.0    0.0            829.08
25 2017-06-16     400  call  0.000010  388.3  392.0            829.08>>>
calls1[:5]
(103, 7)
>>> calls1.shape
Expiry  Strike  Type        IV    Bid    Ask  Underlying_Price
1054 2019-01-18    1180   put  0.184861  355.1  360.0            829.08
1055 2019-01-18    1200  call  0.199257    7.0   11.0            829.08
1056 2019-01-18    1200   put  0.229195  384.3  389.0            829.08
1057 2019-01-18    1220  call  0.197678    6.5    9.4            829.08
1058 2019-01-18    1220   put  0.278068  417.0  421.5            829.08>>>

There are 103 options contract with expiry 2017-06-16. Now we plot the implied volatility of the options contract with this expiry.

#plot implied volatility
ax = aos[(aos.Expiry=='2017-06-16') & (aos.Type=='call')] \
.set_index('Strike')[['IV']].plot(figsize=(12,8))
ax.axvline(calls1.Underlying_Price.iloc[0], color='g');

Below is the plot of GOOG Call Options Implied Volatility.

GOOG Call Options Implied Volatility

Above is the plot of the implied volatility. You can see as the strike price approaches the underlying price implied volatility falls.

Saving The Options Data

Options data keeps on changing. If you want to use the above options data, it would be a good idea to save it into csv file that you can read again. The options data that you have downloaded can be saved using the following python commands.

#save the options data into a csv file
goog_options.to_csv('goog_options.csv')
#you can read this csv file again
goog_options = pd.read_csv('goog_options.csv', parse_dates=['Expiry'])

Downloading Options Data From Chicago Board Options Exchange CBOE

Now Chicago Board Options Exchange trades options and futures. Publicly listed options are traded on CBOE. You can also download options data from CBOE. FIrst go to this url:

http://www.cboe.com/delayedquote/quote-table-download

Open this url in your browser. Type the stock ticker symbol in the search box. In my case I have typed GOOG. A dialog box opens that asks you where you want to save quotedata.dat. Now use the following python code to read this file that you have saved on your hard drive. In my case I have saved the quotedata.dat file in my E hard drive.

import numpy as np
x=pd.read_csv('E:/MarketData/QuoteData.dat',skiprows=2,header='infer')
y=np.array(x)
n=len(y)
y[0:2]
y[n-3:n-1]

This is the output.

>> y[0:2]
array([[’17 Mar 650.00 (GOOG1703C650)’, 0.0, 0.0, …, 0, 5, nan],
[’17 Mar 650.00 (GOOG1703C650-3)’, 0.0, 0.0, …, 0, 5, nan]], dtype=object)>>>
y[n-3:n-1]
array([[’19 Jan 1240.00 (GOOG1918A1240-S)’, 0.0, 0.0, …, 0, 0, nan],
[’19 Jan 1240.00 (GOOG1918A1240-X)’, 0.0, 0.0, …, 0, 0, nan]], dtype=object)>>>

You can see from the above output we have GOOG data. Watch this documentary on how a genius algorithm builder challenges the gurus on Wall Street.

Leave A Response