* * Transactions data from pp 212-214 * open data ch05_ibm.txt data(format=free,org=columns) 1 60328 datetime volume bid ask price set date = fix(datetime/100000) set time = datetime-100000*date set delta = (price-price{1}) * * Times are in seconds since midnight, so 9:30 is 9.50x3600=34200. Five minute * blocks are 300 seconds. The fix function will round down from 9:30 until just * short of 9:35 * set block = 1+fix((time-34200)/300) * * Restrict analysis to pairs within a single day, and trading before 16:00. * (16:00 starts block 79). * set smpl = date==date{1}.and.block<=78 * compute [vect] grid = ||-.375,-.250,-.125,0.000,0.125,0.250,1000|| dec vect cdelta(%rows(grid)) pdelta(%rows(grid)) do i=1,%rows(grid) sstats(smpl=smpl,mean) / delta<=grid(i)>>cdelta(i) compute pdelta(i)=%if(i==1,cdelta(i),cdelta(i)-cdelta(i-1)) end do i * report(action=define) report(atrow=1,atcol=1,span) "Table 5.1 Frequencies of Price Change in Multiples of Tick Size" report(atrow=2,atcol=1) "Number(tick)" "<=-3" "-2" "-1" "0" "1" "2" ">=3" report(atrow=3,atcol=1,fill=rows,picture="##.##") "Percentage" pdelta*100 report(action=format,picture="##.##") report(action=show) * * Count the number of different values for date. The sstats comes in one short of * the total number of days because it only counts the number of changes. * sstats / date<>date{1}>>daycount compute daycount=daycount+1 * * Initialize the series of counts * compute periods=fix(daycount)*78 set trades 1 periods = 0.0 * * Run through the data, incrementing the proper slot of "trades" based upon the * date and block number. * compute dateseq=0,lastdate=-9999.0 do trade=1,60328 if block>78 next if date(trade)<>lastdate compute dateseq=dateseq+1 compute slot=(dateseq-1)*78+fix(block(trade)),trades(slot)=trades(slot)+1 compute lastdate=date(trade) end do trade * spgraph(vfields=2,footer="Figure 5.1 IBM transactions data") graph(hlabel="(a) Number of Transactions") # trades * corr(number=250,noprint,corrs=acf) trades graph(hlabel="(b) Sample ACF",style=bargraph,min=0.0,max=1.0) # acf spgraph(done) * * Average transactions across days to get the average number per * five minute interval * panel(block=78,time=1.0,compress) trades / atrades graph(footer="Figure 5.2 Time plot of average transactions",min=0.0) # atrades * * Compute two-way classification of trades * set sign = %sign(delta) compute table=%zeros(3,3) do t=1,60328 if smpl(t).and.smpl(t-1) compute table(2-fix(sign(t-1)),2-fix(sign(t)))=table(2-fix(sign(t-1)),2-fix(sign(t)))+1 end do t * report(action=define) report(atrow=1,atcol=2) '"+"' '"0"' '"-"' "Margin" report(atrow=2,atcol=1,fillby=cols) '"+"' '"0"' '"-"' "Margin" report(atrow=2,atcol=2) table report(atrow=2,atcol=5,fillby=cols) table*%fill(3,1,1.0) report(atrow=5,atcol=2,fillby=rows) %fill(1,3,1.0)*table report(action=format,picture="#####") report(action=show) * * Compute ACF of sign changes * corr(number=5) sign