* ________________________________________________________________________________________________________________________ firstLook.sas Joel Hasbrouck September 2011 This program runs on rnd.stern.nyu. It builds a dataset for one ticker symbol, computes daily closing prices, plots them, and computes descriptive statistics. _______________________________________________________________________________________________________________________ ; options source nodate nocenter nonumber ps=44 ls=110 orientation=landscape; libname taq '/homedir/fin/fac/jhasbrou/public_html/ftp/phd2011Fall'; libname this '.'; proc print data=taq.ctqall (obs=10); run; *_______________________________________________________________________________________________________________________ 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.; 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); run; *_______________________________________________________________________________________________________________________ Get daily closing prices and total daily volume ________________________________________________________________________________________________________________________; data dailyData; * Put the values in a new dataset; dailyVol = 0; do until (last.date); set this.myTicker; by date; dailyVol = sum(dailyVol,size); * The sum(.) function treats missing values as zero (which is what we want here). if price^=. then closingPrice=price; end; * If there are no transactions, set the closing price to the midpoint of the last bid and ask.; if closingPrice=. then closingPrice = (BBid+BOfr)/2.; output; run; proc print data=dailyData (obs=10); run; *_______________________________________________________________________________________________________________________ Plot closing prices - basic ________________________________________________________________________________________________________________________; proc plot data=dailyData; plot closingPrice*date; run; *_______________________________________________________________________________________________________________________ Plot closing 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='firstLook.rtf' style=analysis; goptions device=sasemf htext=1.8 ftext=duplex hsize=8in vsize=6in; symbol1 v=dot; proc gplot data=dailyData; plot closingPrice*date; by symbol; run; quit; *_______________________________________________________________________________________________________________________ Basic time series statistics ________________________________________________________________________________________________________________________; ods exclude iacfgraph pacfgraph; * Suppresses inverse- and partial-autocorrelation graphs; proc arima data=dailyData; identify var=closingPrice stationarity=(dickey=3); identify var=closingPrice(1); * analysis of first differences; run; ods rtf close; endsas; ods rtf file='ctqLook.rtf' style=analysis; proc print data=wrds.ctqall (obs=250) noobs; by symbol permno date; run; proc print data=wrds.ctqall (where=(symbol='AMWD' and date='01sep2010'd and time>='9:34:00't and time<'9:35:00't) obs=250) noobs; by symbol permno date; run; proc freq data=wrds.ctqAll; tables symbol date; run; ods rtf close;