Extracting Intraday Price Quotes From TAQ Database in WRDS Using SAS
Extracting Intraday Price Quotes From TAQ Database in WRDS Using SAS
Extracting Intraday Price Quotes From TAQ Database in WRDS Using SAS
TAQdatabaseinWRDSusingSAS
(30minutesinterval)
OscarTorresReyna/ToddHines
[email protected]/[email protected]
http://dss.princeton.edu/training/
Note
Thecodepresentedhereisbasedonasample
SAScodeavailableatWRDS
(http://wrds.wharton.upenn.edu/)
YoucancopyandpastethecodeinSASand
modifyittoyourneeds.
Makesureyoucopyitintheorderitis
presentedhere.
OTR/TH
1)LoginintoWRDSfromSAS
%letwrds =wrds.wharton.upenn.edu4016;
optionscomamid=TCPremote=WRDS;
signon username=_prompt_;
libname local'H:\';*Thisiswherethedatawillbesaved;
rsubmit;
libname taq'/wrds/taq/sasdata';*Thisiswherethedatasets
arelocated;
OTR/TH
2)Inputarea
*%lettaq_ds=taq.cq_20090102;*datasetyouareinterested(ifonly
onedataset);
%letstart_time ='9:00:00't;*startingtime;
*%letdate1='02JAN2009'd;*dayyouareinterested(ifonlyone);
*%letinterval_seconds =15*60;*intervalis15*60seconds,15min;
%letinterval_seconds =30*60;*intervalis15*60seconds,30min;
OTR/TH
3)Extractselecteddata/date/time
*ExtractdataforJanuaryJulyof2009and2stocksbetween9:00amto4:30pm,retrieveSYMBOLDATETIMEandPRICE;
dataall2009;
settaq.cq_20090102taq.cq_20090105taq.cq_20090106taq.cq_20090107taq.cq_20090108taq.cq_20090109taq.cq_20090112taq.cq_20090113
taq.cq_20090114taq.cq_20090115taq.cq_20090116taq.cq_20090120taq.cq_20090121taq.cq_20090122taq.cq_20090123taq.cq_20090126
taq.cq_20090127taq.cq_20090128taq.cq_20090129taq.cq_20090130taq.cq_20090202taq.cq_20090203taq.cq_20090204taq.cq_20090205
taq.cq_20090206taq.cq_20090209taq.cq_20090210taq.cq_20090211taq.cq_20090212taq.cq_20090213taq.cq_20090217taq.cq_20090218
taq.cq_20090219taq.cq_20090220taq.cq_20090223taq.cq_20090224taq.cq_20090225taq.cq_20090226taq.cq_20090227taq.cq_20090302
taq.cq_20090303taq.cq_20090304taq.cq_20090305taq.cq_20090306taq.cq_20090309taq.cq_20090310taq.cq_20090311taq.cq_20090312
taq.cq_20090313taq.cq_20090316taq.cq_20090317taq.cq_20090318taq.cq_20090319taq.cq_20090320taq.cq_20090323taq.cq_20090324
taq.cq_20090325taq.cq_20090326taq.cq_20090327taq.cq_20090330taq.cq_20090331taq.cq_20090401taq.cq_20090402taq.cq_20090403
taq.cq_20090406taq.cq_20090407taq.cq_20090408taq.cq_20090409taq.cq_20090413taq.cq_20090414taq.cq_20090415taq.cq_20090416
taq.cq_20090417taq.cq_20090420taq.cq_20090421taq.cq_20090422taq.cq_20090423taq.cq_20090424taq.cq_20090427taq.cq_20090428
taq.cq_20090429taq.cq_20090430taq.cq_20090501taq.cq_20090504taq.cq_20090505taq.cq_20090506taq.cq_20090507taq.cq_20090508
taq.cq_20090511taq.cq_20090512taq.cq_20090513taq.cq_20090514taq.cq_20090515taq.cq_20090518taq.cq_20090519taq.cq_20090520
taq.cq_20090521taq.cq_20090522taq.cq_20090526taq.cq_20090527taq.cq_20090528taq.cq_20090529taq.cq_20090601taq.cq_20090602
taq.cq_20090603taq.cq_20090604taq.cq_20090605taq.cq_20090608taq.cq_20090609taq.cq_20090610taq.cq_20090611taq.cq_20090612
taq.cq_20090615taq.cq_20090616taq.cq_20090617taq.cq_20090618taq.cq_20090619taq.cq_20090622taq.cq_20090623taq.cq_20090624
taq.cq_20090625taq.cq_20090626taq.cq_20090629taq.cq_20090630taq.cq_20090701taq.cq_20090702taq.cq_20090706taq.cq_20090707
taq.cq_20090708taq.cq_20090709taq.cq_20090710taq.cq_20090713taq.cq_20090714taq.cq_20090715taq.cq_20090716taq.cq_20090717
taq.cq_20090720taq.cq_20090721taq.cq_20090722taq.cq_20090723taq.cq_20090724taq.cq_20090727taq.cq_20090728taq.cq_20090729
taq.cq_20090730taq.cq_20090731;
wheresymbolin('GE','C')andtimebetween'9:00:00'tand'16:30:00't;
run;
proc sort;bysymboldatetime;run;
Title'Printseverallinesoftheoriginaldataforchecking';
OTR/TH
4)Screendatatofindthetradebeforeasettimeinterval
dataxtemp2;
setall2009;
bysymboldatetime;
formatitime rtime time12.;
iffirst.symbol=1orfirst.date=1thendo;
*Initializetimeandpricewhennewsymbolordatestarts;
rtime=time;
iprice=bid;
oprice=ofr;
itime=&start_time;
end;
iftime>=itime thendo;*Intervalreached;
output;*rtime andiprice holdthelastobservationvalues;
itime =itime +&interval_seconds;
dowhile(time>=itime);*needtofillinalltimeintervals;
output;
itime =itime +&interval_seconds;
end;
end;
rtime=time;
iprice=bid;
oprice=ofr;
retainitime rtime iprice oprice;*Carrytimeandpricevaluesforward;
*keepsymboldateitime iprice rtime;
run;
OTR/TH
5)Checkthedata,saveasSASdataandexportto*.csv
Title"Finaloutput XXmininterval";*ReplacetheXXbyinterval;
proc printdata=xtemp2(obs=100);
var symboldateitime iprice oprice rtime;
run;
proc downloaddata=xtemp2OUT=local.all30;*Thisdownloadthedatasetin
SASformat.CHANGETHENAMEIFYOUCHANGETHEINTERVAL;
run;
proc exportDATA=local.all30
OUTFILE="h:\all30.csv"
DBMS=csv REPLACE;*ThisexportstheSASdatasetto*.csv toreadin
Excel.REMEMBERTOCHANGETHENAMEIFYOUCHANGETHEINTERVAL;
run;
OTR/TH