* * Example 5.2 page 223 * open data ch05_ibm_ads.dat data(format=free,org=columns) 1 59775 a d s open data ch05_ibm_adsx.dat data(format=free,org=columns) 1 59775 vlag tlag bidask alag dlag slag * nonlin b0 b1 g0 g1 tu0 tu1 td0 td1 * frml decomp = (pix=b0+b1*alag),(ppx=1.0/(1+exp(-pix))),$ (dix=g0+g1*dlag),(pdx=1.0/(1+exp(-dix))),$ (luix=tu0+tu1*slag),(lux=1.0/(1+exp(-luix))),$ (ldix=td0+td1*slag),(ldx=1.0/(1+exp(-ldix))),$ %if(a==0,log(1-ppx),$ %if(d==1,log(ppx)+log(pdx) +log(lux)+(s-1)*log(1-lux),$ log(ppx)+log(1-pdx)+log(ldx)+(s-1)*log(1-ldx))) * maximize decomp * * Compute probabilities of price changes * disp "P(A=1|A was 0)=" #.### 1.0/(1+exp(-b0)) disp "P(A=1|A was 1)=" #.### 1.0/(1+exp(-b0-b1)) * * Compute probabilities of direction of price change, given that a price change * is occurring. * disp "P(D=1|A was 0)=" #.### 1.0/(1+exp(-g0)) disp "P(D=1|D was 1)=" #.### 1.0/(1+exp(-g0-g1)) disp "P(D=1|D was -1)=" #.### 1.0/(1+exp(-g0+g1)) * * Compute probabilities of the size of price increases * compute pg=1.0/(1+exp(-tu0-tu1*1)) disp "Probability(S=1|S was 1,D is 1)" #.### pg compute pg=1.0/(1+exp(-tu0-tu1*2)) disp "Probability(S=1|S was 2,D is 1)" #.### pg compute pg=1.0/(1+exp(-tu0-tu1*3))