Put Call Ratio
Author: stefan17
Creation Date: 11/26/2003 7:44 AM
profile picture

stefan17

#1
Where can I download or buy data of put call ratio?
profile picture

Cone

#2
The first place I'd look is www.cboe.com. It's worth a shot ;)
profile picture

wolf359

#3
StockCharts has about 2yrs of data available under the symbol $CPC. I don't think you need to subscribe just to get that. Try this link.

http://stockcharts.com/webcgi/wb.exe?Data.web+$CPC

profile picture

pmayhew

#4
I use the list found on the cboe under 'market data' > put/call ratio...click on archive link...

Then I copy the list to excel...convert it ot metastock...

Bit I am still hoping to check this on a daily basis; that could get tedious so I am still looking for a better way to get this data?

Pat
profile picture

spongebob

#5
Try Pinnacle Data at www.pinnacledata.com

The package that you'd be looking at would be:

X1 - DAILY S&P 100 DATA, OEX HISTORY
---------------------------------------------------------
1 OEX Open 7/15/83 OEX-Open
2 OEX High 7/15/83 OEX-High
3 OEX Low 7/15/83 OEX-Low
4 OEX Close 7/15/83 OEX-Close
5 OEX Call Volume 2/22/84 OEX-CalV
6 OEX Call Open Interest 2/22/84 OEX-CalI
7 OEX Put Volume 2/22/84 OEX-PutV
8 OEX Put Open Interest 2/22/84 OEX-PutI
9 OEX Put/Call Ratio 2/22/84 OEX-PC
10 OEX Call/Put Ratio 2/22/84 OEX-CP
11 OEX Hines Ratio 2/22/84 OEX-Hins
12 VIX Open 1/2/86 VIX-Open
13 VIX High 1/2/86 VIX-High
14 VIX Low 1/2/86 VIX-Low
15 VIX Close 1/2/86 VIX-Clse
16 Tot Call Volume 7/17/95 TOT-CalV
17 Tot Call Open Interest 7/17/95 TOT-CalI
18 Tot Put Volume 7/17/95 TOT-PutV
19 Tot Put Open Interest 7/17/95 TOT-PutI
20 VXN Open 1/23/01 VXN-Open
21 VXN High 1/23/01 VXN-High
22 VXN Low 1/23/01 VXN-Low
23 VXN Close 1/23/01 VXN-Clse
24 Tot Equity Call Volume 1/8/97 EQY-CalV
25 Tot Equity Put Volume 1/8/97 EQY-PutV
26 Tot Index Call Volume 1/8/97 IND-CalV
27 Tot Index Put Volume 1/8/97 IND-PutV

There are plenty more, lots of good clean sentiment (like Investors Intelligence Bullish %, etc) data and COT data, plus a great futures feed. But they don't have stocks. For that I use Quotes Plus.

I have no affiliation with either Pinnacle or Quotes Plus, just a very satisfied customer.

Cheers.
profile picture

Eugene

#6
profile picture

twiga

#7
pmayhew,
you write
Bit I am still hoping to check this on a daily basis; that could get tedious so
I am still looking for a better way to get this data?


I could not agree more with you that all such manual operations are
very unproductive. Especially since there are many such macro variables that
require a different special handling each and that have to be downloaded
from the internet.

I cannot program the automatic download in Wealth-Script (only fundtimer
has the ability) but I can try to analyze the problem and to prototype it in R.
I am already downloading thus the NYSE Turnover and SP500 Cash dividends and
Earnings and there are many other useful series that Yahoo does not provide.
It is unthinkable and barbaric to try and obtain them
daily (or even monthly) by manual operations.

Maybe you can give a Wealth-Script version a try and publish it. If fundtimer
feels good that day he may debug it or re-write your program to actually work
correctly.

ANALYSIS
Generally speaking one has to:
PRELIMINARY:
Make a directory named "MacroIndexes" or something so that you can make
a Wealth-Lab datasource out of files in this directory.

Decide on date format, data formats and file extension, naming convention for
the file,number of columns, frequency (daily, monthly, quarterly?), number
of rows for general information about the file (such as the URL and
the description) and row number were the data that the WL datasource will read
will start.

If you have more than one frequency (daily and monthly for example, create more
such directories, one per frequency.

I would suggest ISO date format ("YYYY-MM-DD"), ".csv" file extension, 1 column of
data and one for the date, leave free rows for information about the series
and that WL will skip and start writing data for WL in a later row.
A mnemonic symbol name for the file, eg "PCRAT_D.csv" for Index Put/Call Ratio
Daily, except of course if a standard symbol name exists, it should be used
instead.

This output directory is were you will place the PUT/CALL ratios, maybe the
volumes and any other macro series of the same frequency.

Create a WL datasource for this directory (use a prototype data file created
with notepad)

Then:
STEPS

STEP 1: Assign the output directory name (which should already exist) to a variable
STEP 2: Assign the output file name (complete path)
STEP 3: Download the file from the url into a temporary directory (there
are lots of free download utilities which you can use by shelling to DOS
from within Wealth-Script, or use COM with Internet Explorer)
STEP 4: Skip step 4 in this case since the PUT/CALL ratio comes in a .csv file. But
if it did not, you have to parse the HTML or the text
(http://www.nirsoft.net/utils/htmlastext.html)
has a nice free utility to convert HTML to text). It is sometimes simpler to parse
the text.
STEP 5: Read the temporary file into a variable
STEP 6: Extract the dates and the columns of interest
STEP 7: format the data for output, example put the dates in ISO format
STEP 8: Prepare five lines of comments and headers (or blanks if there
is nothing to describe the series )
STEP 9: Starting at row 6, write the file(s) to the output directory (The
Wealth-Lab data source directory previously created)
STEP10: Check if WL datasource can read the data


Prototype in R script

#-------------------------------------------------------------------------------
#PURPOSE: Download index Put Call Ratio and volume
#!IG 2008-01-01 1:02:05 PM
#INPUT DATA SOURCE:
# http://www.cboe.com/publish/ScheduledTask/MktData/datahouse/indexPC.csv

#Create the output directory name
outDir <- "G:\\DATA\\MacroData_D\\"

#Create the output file name (complete path)
outFiles <- paste(outDir, c("PCXVOL_D.csv", "PCRX_D.csv"), sep="" ) ; print(outFiles)
#!"G:\\DATA\\MacroData_D\\PCXVOL_D.csv" "G:\\DATA\\MacroData_D\\PCRX_D.csv"

#Download the file from the url into a temporary directory
tempFile <-"G:\\temp\\temp.csv"
inUrl = "http://www.cboe.com/publish/ScheduledTask/MktData/datahouse/indexPC.csv"
download.file(url=inUrl, destfile= tempFile, mode="w")

#Read the file
r <-read.csv(file=tempFile,skip=1, header=TRUE); print(head(r,3))
#! Trade_date Call Put Total P.C.Ratio
#!1 10/17/2003 134785 270102 404887 2.00
#!2 10/20/2003 110019 120439 230458 1.09
#!3 10/21/2003 125388 159054 284442 1.27
#!

#Extract the dates and the columns of interest
rdate <-r[,1]; print(head(rdate)) #! the first column is the Trade date
rvolume <-r[,4]; print(head(rvolume));
rPCR <-r[,5]; print(head(rPCR))

#format the data for output, example put the dates in ISO format
temp <- as.Date(rdate, format = "%m/%d/%Y"); print(head(temp))
rdate <-as.character(temp); print(head(rdate))

#Prepare five lines of comments and headers
headerVolume<- data.frame(Date=c(rep(" ",4),"Date"),indexVol=c(rep(" ",4),"indexVol" ))
headerVolume[1,] <-c("Source", inUrl)
headerVolume[2,1] <-"DateDownloaded"
headerVolume[2,2] <- as.character(as.Date(Sys.time()))
print(headerVolume)

headerPutCall <-data.frame(Date=c(rep(" ",4),"Date"),indexPC=c(rep(" ",4), "indexPC" ))
headerPutCall[1,] <-c("Source", inUrl)
headerPutCall[2,1] <-"DateDownloaded"
headerPutCall[2,2] <- as.character(as.Date(Sys.time()))
print(headerPutCall)

#Starting at row 6, write the file(s) to the output directory
#1. Prepare PC Volume series by combining date and data columns
v <-data.frame(Date=rdate, indexVol = rvolume); #! combine date and vol columns
print(head(v));

hv <-rbind(headerVolume, v); #! Stack 6 header lines on top of data
print(head(hv))

#2. Prepare Index PC Ratio series by combining date and data columns
idx <- data.frame(Date=rdate, indexPC = rPCR ); #! combine dates and PC ratio columns
print(head(v),10);

hidx <- rbind(headerPutCall, idx) #! Stack 6 header lines on top of data
print(head(hidx,10))

#Write the two files
write.table(x=hv, file=outFiles[1], sep=",", quote=FALSE, row.names=FALSE, col.names=FALSE)

write.table(x=hidx, file=outFiles[2], sep=",", quote=FALSE, row.names=FALSE, col.names=FALSE)

#read them back in and print top rows to check if correctly written
rvol <-read.csv(file= outFiles[1], header=FALSE) ;print(head(rvol,15))
ridx <-read.csv(file= outFiles[2], header=FALSE) ;print(head(ridx,15))


#Finally check if your WL datasource can read them :
#WL Datasource properties:
#!Version=3
#!Fields=Date,Close,
#!Extension=CSV
#!DateFormat=yyyy-mm-dd
#!TimeFormat=hh.nn
#!IgnoreLines=5
#!DecimalSep=Period
#!FieldSep=Comma
#!VolumeMult=1
#!ImpliedDecimals=0
#!Interval=1
#!Scale=0

#WL DATA (copied from Chart)
#! PCRX_D Open High Low Close Volume
#!2003-10-17 2 2 2 2 0
#!2003-10-20 1.0900000333786 1.0900000333786 1.0900000333786 1.0900000333786 0
#!2003-10-21 1.26999998092651 1.26999998092651 1.26999998092651 1.26999998092651 0
#!2003-10-22 1.88999998569489 1.88999998569489 1.88999998569489 1.88999998569489 0
#!2003-10-23 1.60000002384186 1.60000002384186 1.60000002384186 1.60000002384186 0
#!2003-10-24 1.49000000953674 1.49000000953674 1.49000000953674 1.49000000953674 0
#!2003-10-27 1.37000000476837 1.37000000476837 1.37000000476837 1.37000000476837 0
#!2003-10-28 1.05999994277954 1.05999994277954 1.05999994277954 1.05999994277954 0
#!
#!...
#!




profile picture

Eugene

#8
I'm pretty impressed with the power of .NET.

Just for fun, I've experimented with downloading the Put/Call Ratio data on-the-fly in a WL5 trading strategy. The C# code was short enough to fit the screen, from getting the raw data series to trading rules.
profile picture

twiga

#9
Why don't you post it so we can have a taste of how c#
looks like.

I've never seen any.



profile picture

Eugene

#10
twiga,

Why don't you post it so we can have a taste of how c# looks like.

Please wait until WLP5 is out.
profile picture

daronow

#11
>> Please wait until WLP5 is out.

The problem with that is that some of us may not live long enough to see the WL 5 release date since it keeps getting pushed back :(
profile picture

Cone

#12
There has never been an official date mentioned for releasing Version 5.0, so it has cannot have been pushed back!

The only semi-official date that I mentioned was "before the end of January 2008".
profile picture

daronow

#13
I don't want to start a flame war, so to clarify I'll note I am referring to the announcement here:

http://wl4.wealth-lab.com/cgi-bin/WealthLab.DLL/getpage?page=WL5PressRelease20071108.htm

"Wealth-Lab Pro 5.0 will be available in mid-December 2007 and backtesting on Fidelity.com will become available by the beginning of 2008."

Technically we could quibble over the meaning of "available" (maybe they didn't mean a full public release but a limited beta?) and we could even debate the meaning of the word "is" (and for reference I did *NOT* have a relationship with Ms. Lewinsky, nor did I inhale).

Finally, don't get me wrong, I'm just itching to get my hands on it and do some serious compiled backtesting :)
profile picture

Cone

#14
You're right, sorry. It won't be long now - let's call it mid January now ;)
profile picture

daronow

#15
Can you give any details about the rollout, for example will it be done via a download inside AT Pro, or via a direct link? How about licensing, will it use the standard hardware key licensing from WL4 (potentially creating a bottleneck at Fidelity's key generation department), or some other method (obviously I don't expect to be told technical details, I'm just worried about waiting on hold for 3 days to get my key).
profile picture

Cone

#16
Just a guess, but I imagine that an AT Pro Alert will notify when WL Pro Version 5.0 is available for download and will provide a link.

Keys are no longer required, but there's a 30-day trial period, and after that you must be authenticated to continue using the software. Authentication occurs automatically by logging in to Fidelity. ("Developer 5.0" will also use an authentication scheme.)
profile picture

Eugene

#17
twiga,

As promised, here is that C# code that gets Put/Call ratio, parses the raw data, stores it in the global memory for a multi-symbol backtest plus some vanilla trading rules.








using System;
using System.Globalization;
using System.Net;
using System.IO;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using WealthLab;
using WealthLab.Indicators;

namespace WealthLab.Strategies
{
public class PutCallRatio : WealthScript
{

protected override void Execute()
{
/* Location of the Put/Call Ratio, year 2003 to present */
Bars pcratio = new Bars( "PCRATIO", BarScale.Daily, 0 );

IFormatProvider format = new CultureInfo("en-US");
string URI = @"http://www.cboe.com/publish/ScheduledTask/MktData/datahouse/indexPC.csv";

if ( GetGlobal("onDemand") == null )
{
/* Download the file and split into lines */
WebClient client = new WebClient();

string text = client.DownloadString(URI);
string[] lines = text.Split(new string[] { "\n" }, StringSplitOptions.RemoveEmptyEntries);

/* Parse the Put/Call Ratio data file starting from line 2 */
for ( int i = 3; i < lines.Length; i++ )

{
try
{
string[] t = lines[i].Split(',');
DateTime d = DateTime.ParseExact( t[0], new string[] { "M/d/yyyy" }, format, DateTimeStyles.None );
double ratio = Convert.ToDouble( t[4], format );
pcratio.Add( d,ratio,ratio,ratio,ratio,1 );
}
catch
{
PrintDebug( lines[i] );
}
}
SetGlobal( "onDemand", pcratio );
}

pcratio = Synchronize( (Bars)GetGlobal("onDemand") );
ChartPane PCRatioPane = CreatePane( 30, true, true );
PlotSeries( PCRatioPane, pcratio.Close, Color.Blue, WealthLab.LineStyle.Solid, 2 );

DataSeries bbL = BBandLower.Series( pcratio.Close, 20, 2 ); bbL.Description = "Put/Call Ratio: Lower BB";
DataSeries bbU = BBandUpper.Series( pcratio.Close, 20, 2 ); bbU.Description = "Put/Call Ratio: Upper BB";
PlotSeriesDualFillBand( PCRatioPane, bbU, bbL, Color.Empty, Color.Empty, Color.Brown, WealthLab.LineStyle.Solid, 1 );

for(int bar = 50; bar < Bars.Count; bar++)
{
if (IsLastPositionActive)
{
Position p = LastPosition;
if ( p.PositionType == PositionType.Long )
SellAtStop( bar+1, p, p.EntryPrice * 0.9, "Stop Loss" ); else
CoverAtStop( bar+1, p, p.EntryPrice * 1.1, "Stop Loss" );
ExitAtAutoTrailingStop( bar+1, p, 5, 25, "AutoStop" );
}
else
{
if( CrossUnder( bar, pcratio.Close, bbL ) )
BuyAtMarket( bar+1 );
if( CrossOver( bar, pcratio.Close, bbU ) )
ShortAtMarket( bar+1 );
}
}
}
}
}







1/24/2007

Header format change (the data now starts from the 3rd string)

Handle errors in data (an empty line in the data somehow stays unaffected by StringSplitOptions.RemoveEmptyEntries --? )
profile picture

reds

#18
Hi Eugene,

It is quite an accomplishment to download data, parse it, and then run on trading system on it in such a concise format.

I have no experience with C#. Would the same thing be possible in WLD 4.0 and if so how verbose would the code be?

Thanks,

Mike
profile picture

Eugene

#19
In this WL5 code, the .NET classes are doing all the dirty work. That's why preprocessing requires less lines of code than cosmetic functions and a no-frills trading system. In WL4 it would be more verbose and less readable.

To write a code like this in WL4, you'll need:

1. A function to extract the raw data using IE COM object e.g. FT's GetPage function.
2. A fair amount of string operations to split, parse and convert (GetToken, Copy, StrToFloat etc).
3. FT's SetGlobalSeries/GetGlobalSeries functions to operate with the data series in global memory.
...
profile picture

twiga

#20
Eugene,

impressive!

But, does one have to type in all this for every program


using System;
using System.Globalization;
using System.Net;
using System.IO;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using WealthLab;
using WealthLab.Indicators;

namespace WealthLab.Strategies
{



or is it included automatically in every script and just
comes out in the listing for debugging purposes?

profile picture

Eugene

#21
Thanks (and kudos to Aleksey).

But, does one have to type in all this for every program

Yes and no. This code required System.Globalization and System.IO so I included these namespaces.

or is it included automatically in every script and just comes out in the listing for debugging purposes?

It is included automatically, like WLD3/4 presented you a code template every time a CS window was opened. WL5's template contains these directives:

using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using WealthLab;
using WealthLab.Indicators;


But if you're not using Cosmetic functions in a strategy, you may drop the System.Drawing line for example. It's not for debugging purposes, you're in control over which namespaces you include because a strategy needs them.
This website uses cookies to improve your experience. We'll assume you're ok with that, but you can opt-out if you wish (Read more).