* ________________________________________________________________________________________________________________________ analyzeTrades.sas Joel Hasbrouck September 2011 This program runs on rnd.stern.nyu. It builds a dataset of transactions for one ticker symbol, plots the trade prices, and computes descriptive statistics. _______________________________________________________________________________________________________________________ ; options source nodate nocenter nonumber ps=max ls=110 orientation=landscape; libname taq '/homedir/fin/fac/jhasbrou/public_html/ftp/phd2011Fall'; libname this '.'; *_______________________________________________________________________________________________________________________ Subset a ticker symbol and print out a few records. ________________________________________________________________________________________________________________________; data this.myTicker; set taq.ctqall; * Next statement restricts the output to the symbol we want with nonmissing values for the bbid and bofr Outliers (with extremely high offers) and records after the 'normal' market close are removed. 'condFlag' flags trades with special condition codes.; where symbol='ESSX' and bbid^=. and bofr^=. and bofr/bbid<5 and time<='16:10't and condflag^=1; run; proc print data=this.myTicker (obs=10); title "this.myTicker"; run; *_______________________________________________________________________________________________________________________ Pull off the records with trades. ________________________________________________________________________________________________________________________; data trades; * Put the values in a new dataset; set this.myTicker; where price^=.; retain tradeSeqno 0; tradeSeqno = tradeSeqno+1; run; proc print data=trades (obs=50); title "trades"; run; *_______________________________________________________________________________________________________________________ Frequency counts for exchanges and condition codes ________________________________________________________________________________________________________________________; proc freq data=trades; tables ex cond; by symbol; run; *_______________________________________________________________________________________________________________________ Distribution of sizes ________________________________________________________________________________________________________________________; proc univariate data=trades; var size; id date time ex cond; by symbol; run; *_______________________________________________________________________________________________________________________ Plot trade prices - fancy This procedure routes graphic output to an rtf file. The rtf file can be read in Microsoft Word and other programs. ________________________________________________________________________________________________________________________; ods rtf file='analyzeTrades.rtf' style=analysis; options nolabel; goptions device=sasemf htext=1.8 ftext=duplex hsize=8in vsize=6in; symbol1 v=dot h=.3; proc gplot data=trades; plot price*tradeSeqno=1; by symbol; title 'Trades by sequence number'; run; quit; symbol1; symbol1 i=hiloc v=dot h=.1 color=black; proc gplot data=trades; plot price*date=1; by symbol; title 'High/low/close by date'; run; quit; ods rtf close; endsas;