Knowledge Base | How to Load Option Chains from Yahoo Finance to CSV

Contents

Option Chains at Yahoo Finance

Yahoo Finance publishes US stock option chains.

You may open http://finance.yahoo.com/, search a ticker like YHOO, and click the 'Options' tab.

You may use URLs like https://finance.yahoo.com/quote/YHOO/options to open pages with option chains directly.

Yahoo Finance has no links to download option chains to CSV.

Undocumented URLs to Download Option Chains from Yahoo Finance

Yahoo Finance uses a web service to load option chains into web pages.

The web service returns JSON and has URLs like these:

https://query1.finance.yahoo.com/v7/finance/options/YHOO

https://query1.finance.yahoo.com/v7/finance/options/YHOO?date=1510876800

Specify the expiration date as a Unix timestamp.

You may use specialized download and parser utilities like gwebcmd to download and convert JSON data to CSV.

For example, to get option chains use the command:

gwebcmd webtocsv ^
    "https://query1.finance.yahoo.com/v7/finance/options/YHOO" ^
    yhoo.csv /delay=200 /echoOutputFileName /pages=20 /rootPath=*.*.*.calls,*.*.*.puts

gwebcmd in the webtocsv mode loads web data (JSON, XML, HTML, CSV) and converts the data to CSV.

Specify the /rootPath=*.*.*.calls,*.*.*.puts parser parameter that points to the JSON roots of call and put option chains.

gwebcmd loads option chains for all expiration dates automatically. Just specify the /page=20 option.

Loading Option Chains from Yahoo Finance with Batch Files

Create a text file like 'task.txt' and place tickers one by line like:

TICKERS.TXT
AAPL
FB
GOOGL
YHOO

Create a batch file like 'load.cmd' with the following commands:

LOAD.CMD
@echo off

@for /F %%i in (tickers.txt) do (
    gwebcmd webtocsv ^
        "https://query1.finance.yahoo.com/v7/finance/options/%%i" ^
        %%i.JSON %%i.CSV /delay=200 /echoOutputFileName /pages=20 /rootPath=*.*.*.calls,*.*.*.puts
)

Run it. You will see the result:

C:>load.cmd
AAPL.CSV - 1210 rows
FB.CSV - 960 rows
GOOGL.CSV - 1814 rows
YHOO.CSV - 384 rows

Pay attention to the /delay parameter. Use the delay to avoid banning your IP due to frequent multiple automatic requests.

Downloading Option Chains from Yahoo Finance using Market.csv

Market.csv is a specialized tool for loading data from Yahoo Finance, Google Finance, and MSN Money.

You place the required tickers to a file like tickers.txt.

TICKERS.TXT
AAPL
FB
GOOGL
YHOO

Then you execute commands to download data using the required data providers:

C:\MarketData
market.csv.exe download YahooOptions

The tool downloads data, archives the data to zip files and converts the data to CSV.

You may get results in the YahooOptions.csv output file.

Moreover, you may download option chains from MSN Money in the same way.

Also, Market.csv includes ready-to-use SQL codes and format files to import CSV data into a Microsoft SQL Server database.

Downloads

Products for Option Traders
WEB.CSV aka gwebcmd
The app loads data from the web (HTML, XML, JSON, and CSV) into CSV
Version: 4.6 | 08/22/2017 | 1.4MB | Home | What's New | Editions
Market.csv
The app loads data from Yahoo Finance, Google Finance, and MSN Money to CSV and databases
Version: 2.5 | 08/22/2017 | 0.9MB | Home | What's New | Editions

Disclaimer

Yahoo Finance is a logo and registered trademark of Yahoo! Inc.