Building an indicator from short volume data price of a asset or an ETF are of course the best indicator there are, but UNF Ortunately there is only if much information contained in it. Some people seem to think so the more indicators (RSI, MACD, moving average crossover etc), the better, and if all of t Hem is based at the same underlying price series, they would all contain a subset of the same limited information containe D in the price.
We need more information
additionalTo what's the contained the price and make a more informed guess about what's going to happen in the the near future. An excellent example of combining all sorts of info to a clever analysis can is found on the short Side of Long blog. Producing this kind of analysis requires a great amount of work, for which I simply don ' t has the time as I only trade PA Rt-time.
So I built my own ' Market dashboard ' this automatically collects information for me and presents it in an easily digestibl E form. In this post I ' m going to show how to build a indicator based on short volume data. This post would illustrate the process of data gathering and processing.
Step 1:find data source.
BATS Exchange provides daily volume data for free on their site.
Step 2:get Data manually & inspect
Short volume data of the BATS exchange was contained in a text file, is zipped. Each day has its own zip file. After downloading and unzipping the TXT file, this is what's inside (first several lines):
date| symbol| Short volume| Total volume| Market center20111230| a|26209|71422| z20111230| aa|298405|487461| z20111230| aacc|300|3120| z20111230| aan|3600|10100| z20111230| aaon|1875|6156| Z
....
In total a file contains around 6000 symbols.
This data is needs quite some work before it can be presented in a meaningful manner.
Step 3:automatically Get Data
What I really want isn't just the data for one day, but a ratio of short volume to total volume for the past several year S, and I don ' t really feel like downloading the zip files and copy-pasting them in Excel manually.
Luckily, full automation are only a couple of code lines away:
First we need to dynamically create a URL from which a file would be downloaded:
?
12345678910 |
from string
import Template
def createUrl(date):
s
= Template(
‘http://www.batstrading.com/market_data/shortsales/$year/$month/$fName-dl?mkt=bzx‘
)
fName
= ‘BATSshvol%s.txt.zip‘ % date.strftime(
‘%Y%m%d‘
)
url
= s.substitute(fName
=
fName, year
=
date.year, month
=
‘%02d‘ % date.month)
return url,fName
|
Output:
Http://www.batstrading.com/market_data/shortsales/2013/08/BATSshvol20130813.txt.zip-dl?mkt=bzx
Now we can download multiple files at once:
?
12345678910 |
import urllib
for i,date
in enumerate
(dates):
source, fName
=
createUrl(date)
# create url and file name
dest
= os.path.join(dataDir,fName)
if not os.path.exists(dest):
# don‘t download files that are present
print ‘Downloading [%i/%i]‘ %
(i,
len
(dates)), source
urllib.urlretrieve(source, dest)
else
:
print ‘x‘
,
|
Output:
Downloading [0/657] http://www.batstrading.com/market_data/shortsales/2011/01/BATSshvol20110103.txt.zip-dl?mkt= bzxdownloading [1/657] http://www.batstrading.com/market_data/shortsales/2011/01/BATSshvol20110104.txt.zip-dl? mkt=bzxdownloading [2/657] http://www.batstrading.com/market_data/shortsales/2011/01/ batsshvol20110105.txt.zip-dl?mkt=bzxdownloading [3/657] http://www.batstrading.com/market_data/shortsales/2011/ 01/batsshvol20110106.txt.zip-dl?mkt=bzx
Step 4. Parse downloaded files
We can use the zip and pandas libraries to parse a single file:
?
12345678910111213 |
import datetime as dt
import zipfile
import StringIO
def readZip(fName):
zipped
= zipfile.ZipFile(fName)
# open zip file
lines
= zipped.read(zipped.namelist()[
0
])
# unzip and read first file
buf
= StringIO.StringIO(lines)
# create buffer
df
= pd.read_csv(buf,sep
=
‘|‘
,index_col
=
1
,parse_dates
=
False
,dtype
=
{
‘Date‘
:
object
,
‘Short Volume‘
:np.float32,
‘Total Volume‘
:np.float32})
# parse to table
s
= df[
‘Short Volume‘
]
/
df[
‘Total Volume‘
]
# calculate ratio
s.name
= dt.datetime.strptime(df[
‘Date‘
][
-
1
],
‘%Y%m%d‘
)
return s
|
It returns a ratio of short volume/total Volume for all symbols in the zip file:
Symbola 0.531976AA 0.682770AAIT 0.000000AAME 0.000000AAN 0.506451AAON 0.633841AAP 0.413083AAPL 0.642275AAT 0.263158AAU 0.494845AAV 0.407976AAWW 0.259511AAXJ 0.334937AB 0.857143ABAX 0.812500...ZLC 0.192725ZLCS 0.018182ZLTQ 0.540341ZMH 0.413315ZN 0.266667ZNGA 0.636890ZNH 0.125000ZOLT 0.472636ZOOM 0.000000ZQK 0.583743ZROZ 0.024390ZSL 0.482461ZTR 0.584526ZTS 0.300384ZUMZ 0.385345name:2013-08-13 00:00:00, length:5859, Dtype:float32
Step 5:make a chart:
Now the only thing left are to parse all downloaded files and combine them to a single table and plot the result:
The figure above I has plotted the
average short volume ratio for the past II years. I also could has used a subset of symbols if I wanted to take a look at a specific sector or stock. Quick look at the data gives me an impression, volume ratios usually correspond with market bottoms and low Ratios seem to is good entry points for a long position.
Starting from here, this short volume ratio can is used as a basis for strategy development.
Build indicators from short position data