new; #include dstamp.set; ts=hsec; format /le 10,4; output file=Mark-Wu.OUT reset; output on; dstamp; load dat[85,32]=noise-q.dat; dat=dat[13:85,.]; @--from 1976.I--1994.I--@ " ECMQ.PGM-- (1) ESTIMATE THE SHORT-RUN PARAMETERS IN THE ECM BY OLS WITH THE COINTEGRATION VECTOR TREATED AS KNOWN. (2) COMPUTES IMPLIED MOMENTS OF INTEREST WITH ASSOCIATED THE ASYMPTOTIC STANDARD ERRORS "; @==========================================================@ @:::::::::USER DEFINED VARIABLES:::::::::::::::::::::::::::@ @==========================================================@ k=1; @ 1--POUND. 2--DM. 3--YEN @ restart: lag=1; pmax=13; @--max order of Q-stat--@ _hess=1; @-- Hessian Matrix, 1 if conventional, 2 if BHHH --@ @==========================================================@ t0=lag+2; t1=rows(dat); nobs=t1-t0+1; alpha=1|-1; @ COINTEGRATION VECTOR @ clear a,v,ava,c0,nn; @-----------------------------------------------------------@ " Lags used (VECM)..........";;lag; " First observation.........";;t0; " Last observation..........";;t1; " Currency..................";;k;; " 1--POUND. 2--DM. 3--YEN "; " Method to Compute Hessian.";;_hess;; " 1--conventional, 2--BHHH"; @========================================================@ @:::::::::SET UP THE DATA :::::::::::::::::::::::::::::::@ @========================================================@ dx=zeros(t1,2); fwd=100*ln(dat[.,26+k+3]); spt=100*ln(dat[.,26+k]); x=fwd~spt; z=sumc((alpha'.*x)'); @ FORWARD PREMIUM @ dx[2:t1,.]=x[2:t1,.]-x[1:t1-1,.]; @ LOG DIFFERENCES @ @=================================================================@ @ THIS SETS UP D (D0) AS THE DATA OR DESIGN MATRIX SO WE CAN @ @ ESTIMATE THE VECM @ @=================================================================@ if lag==0; D0=z[t0-1:t1-1]; elseif lag==1; D0=dx[t0-1:t1-1,.]~z[t0-1:t1-1]; elseif lag>=2; Da=dx[t0-1:t1-1,1]; Db=dx[t0-1:t1-1,2]; i=2; do while i<=lag; Da=Da~dx[t0-i:t1-i,1]; Db=Db~dx[t0-i:t1-i,2]; i=i+1; endo; D0=Da~Db~z[t0-1:t1-1,.]; endif; @---------------------------------------------------------------@ @ [I] ESTIMATE THE ECM BY OLS @ @---------------------------------------------------------------@ n=rows(D0); D=ones(n,1)~D0; @ ADD A CONSTANT @ b1=inv(D'D)*D'dx[t0:t1,1]; res1=dx[t0:t1,1]-D*b1; @ FORWARD RATE @ b2=inv(D'D)*D'dx[t0:t1,2]; res2=dx[t0:t1,2]-D*b2; @ SPOT RATE @ R0=res1~res2; sigma=R0'*R0/n; @ ERROR COVARIANCE MATRIX @ @---Define the Y(t) matrix in companion form. It is a kXT matrix. ----@ if lag==1; y=dx[t0:t1,1]~dx[t0:t1,2]~z[t0:t1]; endif; if lag==2; y= dx[t0:t1,1]~dx[t0-1:t1-1,1] ~dx[t0:t1,2]~dx[t0-1:t1-1,2] ~z[t0:t1]; endif; if lag==3; y= dx[t0:t1,1]~dx[t0-1:t1-1,1]~dx[t0-2:t1-2,1] ~dx[t0:t1,2]~dx[t0-1:t1-1,2]~dx[t0-2:t1-2,2] ~z[t0:t1]; endif; if lag==4; y= dx[t0:t1,1]~dx[t0-1:t1-1,1]~dx[t0-2:t1-2,1]~dx[t0-3:t1-3,1] ~dx[t0:t1,2]~dx[t0-1:t1-1,2]~dx[t0-2:t1-2,2]~dx[t0-3:t1-3,2] ~z[t0:t1]; endif; y=y'; @output on;@ AIC = ln(det(sigma)) + 2*(rows(b1)+rows(b2))/n; SBC = ln(det(sigma)) + (rows(b1)+rows(b2))*ln(n)/n; " Akaike Information Criterion AIC ";;AIC; " Schwartz Bayesian Criterion SBC ";;SBC; /* " Box-Ljung Q(p) stat for Epsilons"; "Equation Q p DF Pval"; "------------------------------------------------"; p=1; do while p<=pmax; Q1=Qstat(res1,p); Q2=Qstat(res2,p); Q =Qstat(res1~res2,p); "Fwd ";;Q1~p~(p-rows(b1));; if p-rows(b1)>0;cdfchic(Q1,p-rows(b1)); else; " N/A"; endif; "Spot ";;Q2~p~(p-rows(b2));; if p-rows(b2)>0;cdfchic(Q2,p-rows(b2)); else; " N/A"; endif; "S & F";;Q~p~(4*p-2*rows(b1));; if 4*p-2*rows(b1)>0; cdfchic(Q,4*p-2*rows(b1)); else; " N/A"; endif; p=p+1; endo; */ output off; @----------------------------------------------------------------@ @ [II] COMPUTE COVARIANCE MATRIX OF THETA @ @----------------------------------------------------------------@ theta1=b1|b2; theta2=sigma[1,1]|sigma[1,2]|sigma[2,2]; theta=theta1|theta2; @ COMPUTE COVARIANCE MATRIX OF THETA @ clear bhhh; @ FOR both the `BETA' and "Sigma" @ if _hess==1; vcv=hessp(&llik3,theta); vcvtheta=inv( -vcv ); endif; if _hess==2; nn=t0; do while nn <= t1; dt=gradp(&llik2,theta); bhhh=dt'*dt + bhhh; "nn=";; nn; nn=nn+1; endo; vcvtheta=inv(bhhh); endif; @ ========================================================= @ @ SET UP COMPANION FORM @ @ ========================================================= @ if lag==1; @ VECM(1) @ g0=b1[1]|b2[1]; A1=b1[2:rows(b1)-1]'|b2[2:rows(b2)-1]'; gam=b1[rows(b1)]|b2[rows(b2)]; a0=g0|(alpha'*g0); A=(A1~gam)|((alpha'*A1)~(1+alpha'*gam)) ; V11=sigma; V12=sigma*alpha; V21=alpha'*sigma; V22=alpha'*sigma*alpha; V=(V11~V12)|(V21~V22); @ COVARIANCE MATRIX OF u @ endif; @--------------------------------@ if lag==2; @ VECM(2) @ g0=b1[1]|b2[1]; a0=g0[1]|0|g0[2]|0|(alpha'*g0); gam=b1[rows(b1)]|b2[rows(b2)]; H=(b1[2]~b1[4])|(b2[2]~b2[4]); B=(b1[3]~b1[5])|(b2[3]~b2[5]); A=zeros(5,5); A[1,.]=b1[2:rows(b1)]'; A[2,1]=1; A[3,.]=b2[2:rows(b2)]'; A[4,3]=1; A[5,.]=(alpha'*(H[.,1]~B[.,1]~H[.,2]~B[.,2]))~(1+alpha'*gam); V=zeros(5,5); V[1,1]=sigma[1,1]; V[1,3]=sigma[1,2]; V[1,5]=sigma[1,.]*alpha; V[3,1]=sigma[1,2]; V[3,3]=sigma[2,2]; V[3,5]=sigma[2,.]*alpha; V[5,1]=V[1,5]; V[5,3]=V[3,5]; V[5,5]=alpha'*sigma*alpha; endif; @--------------------------------@ if lag==3; @ VECM(3) @ g0=b1[1]|b2[1]; a0=g0[1]|0|0|g0[2]|0|0|(alpha'*g0); gam=b1[rows(b1)]|b2[rows(b2)]; A=zeros(7,7); A[1,.]=b1[2:rows(b1)]'; A[2,1]=1; A[3,2]=1; A[4,.]=b2[2:rows(b2)]'; A[5,4]=1; A[6,5]=1; A[7,.]=( alpha'*(b1[2:rows(b1)-1]'|b2[2:rows(b2)-1]') )~(1+alpha'*gam); V=zeros(7,7); V[1,1]=sigma[1,1]; V[1,4]=sigma[1,2]; V[1,7]=sigma[1,.]*alpha; V[4,1]=sigma[1,2]; V[4,4]=sigma[2,2]; V[4,7]=sigma[2,.]*alpha; V[7,1]=V[1,7]; V[7,4]=V[4,7]; V[7,7]=alpha'*sigma*alpha; endif; @--------------------------------@ if lag==4; @ VECM(4) @ g0=b1[1]|b2[1]; a0=g0[1]|0|0|0|g0[2]|0|0|0|(alpha'*g0); gam=b1[rows(b1)]|b2[rows(b2)]; A=zeros(9,9); A[1,.]=b1[2:rows(b1)]'; A[2,1]=1; A[3,2]=1; A[4,3]=1; A[5,.]=b2[2:rows(b2)]'; A[6,5]=1; A[7,6]=1; A[8,7]=1; A[9,.]=( alpha'*(b1[2:rows(b1)-1]'|b2[2:rows(b2)-1]') )~(1+alpha'*gam); V=zeros(9,9); V[1,1]=sigma[1,1]; V[1,5]=sigma[1,2]; V[1,9]=sigma[1,.]*alpha; V[5,1]=sigma[1,2]; V[5,5]=sigma[2,2]; V[5,9]=sigma[2,.]*alpha; V[9,1]=V[1,9]; V[9,5]=V[5,9]; V[9,9]=alpha'*sigma*alpha; endif; @=================================================================@ @::::::::::::End of setup portion:::::::::::::::::::::::::::::::::@ @-----------------------------------------------------------------@ @============================================================@ @ [III] COMPUTE IMPLIED MOMENTS AND ASYMPTOTIC STANDARD ERRORS @ @------------------------------------------------------------@ output on; mom1=M1(theta); @ MOMENT 1 = COV[s(t+1)-s(t),z(t)]/Var(z(t)) @ db=gradp(&M1,theta); @ GRADIENT @ semom1=sqrt(db*vcvtheta*db'); @ ASYMPTOTIC STANDARD ERROR @ mom2=M2(theta); @ MOMENT 2 = COV[s(t+1)-s(t),z(t)] @ db=gradp(&M2,theta); @ GRADIENT @ semom2=sqrt(db*vcvtheta*db'); @ ASYMPTOTIC STANDARD ERROR @ mom3=M3(theta); @ MOMENT 3 = RHO[z(t+1),z(t)] @ db=gradp(&M3,theta); @ GRADIENT @ semom3=sqrt(db*vcvtheta*db'); @ ASYMPTOTIC STANDARD ERROR @ mom4=M4(theta); @ MOMENT 4 = VAR[E(s(t+1)-s(t))|I(t)] @ db=gradp(&M4,theta); @ GRADIENT @ semom4=sqrt(db*vcvtheta*db'); @ ASYMPTOTIC STANDARD ERROR @ mom5=M5(theta); @ MOMENT 5 = VAR[r(t)] @ db=gradp(&M5,theta); @ GRADIENT @ semom5=sqrt(db*vcvtheta*db'); @ ASYMPTOTIC STANDARD ERROR @ mom6=M6(theta); @ MOMENT 6 = VAR[r(t)]-VAR[z(t)] @ db=gradp(&M6,theta); @ GRADIENT @ semom6=sqrt(db*vcvtheta*db'); @ ASYMPTOTIC STANDARD ERROR @ mom7=M7(theta); @ MOMENT 7 = RHO[r(t+1),r(t)] @ db=gradp(&M7,theta); @ GRADIENT @ semom7=sqrt(db*vcvtheta*db'); @ ASYMPTOTIC STANDARD ERROR @ mom8=M8(theta); @ MOMENT 8 = VAR[r(t)]-VAR[E(s(t+1)-s(t))|I(t)] @ db=gradp(&M8,theta); @ GRADIENT @ semom8=sqrt(db*vcvtheta*db'); @ ASYMPTOTIC STANDARD ERROR @ mom9=M9(theta); @ MOMENT 9 = VAR[z(t)] @ db=gradp(&M9,theta); @ GRADIENT @ semom9=sqrt(db*vcvtheta*db'); @ ASYMPTOTIC STANDARD ERROR @ mom10=M10(theta); @ MOMENT 10 = COV[s(t+1)-s(t), r(t)] @ db=gradp(&M10,theta); @ GRADIENT @ semom10=sqrt(db*vcvtheta*db'); @ ASYMPTOTIC STANDARD ERROR @ "COV[s(t+1)-s(t), z(t)]/Var[z(t)]: ";;mom1;; " t-ratio = ";; mom1/semom1; "COV[s(t+1)-s(t), z(t)]: ";;mom2;; " t-ratio = ";; mom2/semom2; "RHO[z(t+1),z(t)]: ";;mom3;; " t-ratio = ";; mom3/semom3; "VAR[E(s(t+1)-s(t))|I(t)] : ";;mom4;; " t-ratio = ";; mom4/semom4; "VAR[r(t)]: ";;mom5;; " t-ratio = ";; mom5/semom5; "VAR[r(t)]-Var[z(t)]: ";;mom6;; " t-ratio = ";; mom6/semom6; "RHO[r(t+1),r(t)]: ";;mom7;; " t-ratio = ";; mom7/semom7; "VAR[r(t)]-VAR[E(s(t+1)-s(t))|I(t)]";;mom8;; " t-ratio = ";; mom8/semom8; "VAR[z(t)] ";;mom9;; " t-ratio = ";; mom9/semom9; "COV[s(t+1)-s(t), r(t)] ";;mom10;;" t-ratio = ";;mom10/semom10; @--------plotting expected excess return and expected depreciation--------@ exdep=zeros(cols(y),1); seexdep=zeros(cols(y),1); rp=zeros(cols(y),1); serp=zeros(cols(y),1); nn=1; do while nn<=cols(y); exdep[nn]=exdepp(theta); @ expected depreciation for 1 obs @ db=gradp(&exdepp,theta); @ GRADIENT @ seexdep[nn]=sqrt(db*vcvtheta*db'); @ ASYMPTOTIC STANDARD ERROR @ rp[nn]=rpp(theta); @ expected excess return for 1 obs @ db=gradp(&rpp,theta); @ GRADIENT @ serp[nn]=sqrt(db*vcvtheta*db'); @ ASYMPTOTIC STANDARD ERROR @ nn=nn+1; endo; exdep=4*exdep; seexdep=4*seexdep; rp=4*rp; serp=4*serp; @-annualizing-@ caltme=seqa((1976.25),0.25,rows(rp)); @-------------------------------------------------------@ library pgraph; graphset; @ _protate=1;@ _pcolor = {15}; _ptitlht = 0.3; _pline = {1 6 1975 0 1995 0 1 15 1}; _plctrl = {0,2,0,2}; @ _pstype = {1,10,1,1,9,1}; /* Controls symbols with graph points */@ _pstype = {1,9,1,10}; /* Controls symbols with graph points */ _pltype = {3,6,3,6}; /* line type for the main curves */ fonts("simplex complex microb simgrma"); @ LOAD FONTS @ _plwidth = {3,4,3,4}; /* Width of lines */ _psymsiz=5; _pdate=""; _paxht = 0.3; _pnumht = 0.3; ylabel("\202Percent per annum"); xtics(1975,1995,1,1); @-------------------------------------------------------@ if k==1; begwind; window(3,1,0); v1=(exdep-1.96*seexdep)~exdep~(exdep+1.96*seexdep); title("\202(a)"); ytics(-45,45,10,10); v2=(rp-1.96*serp)~rp~(rp+1.96*serp); xy(caltme,v2~exdep); "First plot"; caltme~v2~exdep; endif; if k==1; k=2; goto restart; endif; if k==2; nextwind; v1=(exdep-1.96*seexdep)~exdep~(exdep+1.96*seexdep); title("\202(b)"); ytics(-30,30,10,10); v2=(rp-1.96*serp)~rp~(rp+1.96*serp); xy(caltme,v2~exdep); "Second Plot"; caltme~v2~exdep; endif; if k==2; k=3; goto restart; endif; if k==3; nextwind; v1=(exdep-1.96*seexdep)~exdep~(exdep+1.96*seexdep); title("\202(c)"); ytics(-40,40,10,10); v2=(rp-1.96*serp)~rp~(rp+1.96*serp); xy(caltme,v2~exdep); "Third plot"; caltme~v2~exdep; endif; endwind; @================================================================@ @ PROCEDURES SECTION @ @================================================================@ @----------------------------------------------------------------@ @ EVALUATE THE LOG LIKELIHOOD AT THE OLS ESTIMATES IN ORDER TO @ @ COMPUTE THE COVARIANCE MATRIX OF THETA @ @----------------------------------------------------------------@ proc llik1(theta1); @ FOR THE BETA PART @ local u; u=zeros(t1,2); u[t0:t1,1]=dx[t0:t1,1]-D*theta1[1:rows(b1)]; u[t0:t1,2]=dx[t0:t1,2]-D*theta1[rows(b1)+1:2*rows(b1)]; retp(-u[nn,.]*inv(sigma)*u[nn,.]'*0.5); @ QUADRATIC FORM IN NORMAL EXPONENT @ endp; proc llik2(theta); @ FOR both beta and SIGMA PARTs, 1 obs, for BHHH @ local u1,u2,u3,u,omega,t,func,tend, theta1, theta2; clear func; omega=zeros(2,2); u=zeros(t1,2); theta1=theta[1:rows(theta)-3]; theta2=theta[rows(theta)-2:rows(theta)]; u[t0:t1,1]=dx[t0:t1,1]-D*theta1[1:rows(b1)]; u[t0:t1,2]=dx[t0:t1,2]-D*theta1[rows(b1)+1:2*rows(b1)]; omega[1,1]=theta2[1]; omega[1,2]=theta2[2]; omega[2,1]=omega[1,2]; omega[2,2]=theta2[3]; tend=rows(u); func = -( u[nn,.]*inv(omega)*u[nn,.]' + ln(det(omega)) )*0.5; retp(func); endp; proc llik3(theta); @ both beta and SIGMA PARTs, n obs, for conventional @ local u1,u2,u3,u,omega,t,func,tend, theta1, theta2; clear func; omega=zeros(2,2); u=zeros(t1,2); theta1=theta[1:rows(theta)-3]; theta2=theta[rows(theta)-2:rows(theta)]; u[t0:t1,1]=dx[t0:t1,1]-D*theta1[1:rows(b1)]; u[t0:t1,2]=dx[t0:t1,2]-D*theta1[rows(b1)+1:2*rows(b1)]; omega[1,1]=theta2[1]; omega[1,2]=theta2[2]; omega[2,1]=omega[1,2]; omega[2,2]=theta2[3]; tend=rows(u); t=1; do while t<=tend; func=func+u[t,.]*inv(omega)*u[t,.]'; t=t+1; endo; func=func+(tend)*ln(det(omega)); func= ( tend*ln(2*pi) + func ) *0.5; func=-func; retp(func); endp; @:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::@ @::::::Proc to compute Autocovariance Matrices that can be @ @ indexed according to the lag @ @-----------------------------------------------------------------@ proc cov0(A,V); @ This proc computes C0 once and for all @ local i,C0,AVA; C0=V; AVA=V; i=1; do while i<=200; AVA=A*(AVA)*(A'); C0=C0+AVA; i=i+1; endo; retp(C0); endp; proc C(j,A,V); @ j-th AUTOCOVARIANCE MATRIX OF Y @ local Cj,AVA,i; cj=cov0(A,V); if j>0; i=1; do while i<=j; cj=a*cj; i=i+1; endo; endif; retp(cj); endp; @----------------------------------------------------------------------@ @ :::REVERSE ASSIGNMENT TO GET IMPLIED MOMENT AS A FUNCTION OF THETA:: @ @----------------------------------------------------------------------@ proc (2) = reverse(theta1,theta2); local sto,stonum,g0,gam,j,b1,b2,b3,sigma,a0,e1,e2,e3,A,V,V11,V12,V21,V22, H,B,X1; sigma=zeros(2,2); if lag==1; b1=theta1[1:rows(theta1)/2]; b2=theta1[(rows(theta1)/2)+1:rows(theta1)]; sigma[1,1]=theta2[1]; sigma[1,2]=theta2[2]; sigma[2,1]=sigma[1,2]; sigma[2,2]=theta2[3]; g0=b1[1]|b2[1]; A1=b1[2:rows(b1)-1]'|b2[2:rows(b2)-1]'; gam=b1[rows(b1)]|b2[rows(b2)]; a0=g0|(alpha'*g0); A=(A1~gam)|((alpha'*A1)~(1+alpha'*gam)) ; V11=sigma; V12=sigma*alpha; V21=alpha'*sigma; V22=alpha'*sigma*alpha; V=(V11~V12)|(V21~V22); @ COVARIANCE MATRIX OF u @ endif; if lag==2; b1=theta1[1:rows(theta1)/2]; b2=theta1[(rows(theta1)/2)+1:rows(theta1)]; sigma[1,1]=theta2[1]; sigma[1,2]=theta2[2]; sigma[2,1]=sigma[1,2]; sigma[2,2]=theta2[3]; g0=b1[1]|b2[1]; a0=g0[1]|0|g0[2]|0|(alpha'*g0); gam=b1[rows(b1)]|b2[rows(b2)]; H=(b1[2]~b1[4])|(b2[2]~b2[4]); B=(b1[3]~b1[5])|(b2[3]~b2[5]); A=zeros(5,5); A[1,.]=b1[2:rows(b1)]'; A[2,1]=1; A[3,.]=b2[2:rows(b2)]'; A[4,3]=1; A[5,.]=(alpha'*(H[.,1]~B[.,1]~H[.,2]~B[.,2]))~(1+alpha'*gam); V=zeros(5,5); V[1,1]=sigma[1,1]; V[1,3]=sigma[1,2]; V[1,5]=sigma[1,.]*alpha; V[3,1]=sigma[1,2]; V[3,3]=sigma[2,2]; V[3,5]=sigma[2,.]*alpha; V[5,1]=V[1,5]; V[5,3]=V[3,5]; V[5,5]=alpha'*sigma*alpha; endif; if lag==3; b1=theta1[1:rows(theta1)/2]; b2=theta1[(rows(theta1)/2)+1:rows(theta1)]; sigma[1,1]=theta2[1]; sigma[1,2]=theta2[2]; sigma[2,1]=sigma[1,2]; sigma[2,2]=theta2[3]; g0=b1[1]|b2[1]; a0=g0[1]|0|0|g0[2]|0|0|(alpha'*g0); gam=b1[rows(b1)]|b2[rows(b2)]; A=zeros(7,7); A[1,.]=b1[2:rows(b1)]'; A[2,1]=1; A[3,2]=1; A[4,.]=b2[2:rows(b2)]'; A[5,4]=1; A[6,5]=1; A[7,.]=( alpha'*(b1[2:rows(b1)-1]'|b2[2:rows(b2)-1]') )~(1+alpha'*gam); V=zeros(7,7); V[1,1]=sigma[1,1]; V[1,4]=sigma[1,2]; V[1,7]=sigma[1,.]*alpha; V[4,1]=sigma[1,2]; V[4,4]=sigma[2,2]; V[4,7]=sigma[2,.]*alpha; V[7,1]=V[1,7]; V[7,4]=V[4,7]; V[7,7]=alpha'*sigma*alpha; endif; if lag==4; b1=theta1[1:rows(theta1)/2]; b2=theta1[(rows(theta1)/2)+1:rows(theta1)]; sigma[1,1]=theta2[1]; sigma[1,2]=theta2[2]; sigma[2,1]=sigma[1,2]; sigma[2,2]=theta2[3]; g0=b1[1]|b2[1]; a0=g0[1]|0|0|0|g0[2]|0|0|0|(alpha'*g0); gam=b1[rows(b1)]|b2[rows(b2)]; A=zeros(9,9); A[1,.]=b1[2:rows(b1)]'; A[2,1]=1; A[3,2]=1; A[4,3]=1; A[5,.]=b2[2:rows(b2)]'; A[6,5]=1; A[7,6]=1; A[8,7]=1; A[9,.]=( alpha'*(b1[2:rows(b1)-1]'|b2[2:rows(b2)-1]') )~(1+alpha'*gam); V=zeros(9,9); V[1,1]=sigma[1,1]; V[1,5]=sigma[1,2]; V[1,9]=sigma[1,.]*alpha; V[5,1]=sigma[1,2]; V[5,5]=sigma[2,2]; V[5,9]=sigma[2,.]*alpha; V[9,1]=V[1,9]; V[9,5]=V[5,9]; V[9,9]=alpha'*sigma*alpha; endif; retp(A,V); endp; @----------------------------------------------------------------@ @:::::::::: PROC TO COMPUTE MOMENT 1 AS A FUNCTION OF THETA::::::@ @----------------------------------------------------------------@ proc M1(theta); local sto,stonum,g0,gam,j,b1,b2,b3,sigma,a0,e1,e2,e3,A,V,V11,V12,V21,V22, H,B,X1,theta1,theta2,C0,C1; sigma=zeros(2,2); theta1=theta[1:rows(theta)-3]; theta2=theta[rows(theta)-2:rows(theta)]; {A,V}=reverse(theta1,theta2); C0=C(0,A,V); C1=C(1,A,V); if lag==1; e1=1~0~0; e2=0~1~0; e3=0~0~1; endif; @ VECM(1) @ if lag==2; e1=1~0~0~0~0; e2=0~0~1~0~0; e3=0~0~0~0~1; endif; @ VECM(2) @ if lag==3; e1=1~0~0~0~0~0~0; e2=0~0~0~1~0~0~0; e3=0~0~0~0~0~0~1; endif; @ VECM(3) @ if lag==4; e1=1~0~0~0~0~0~0~0~0; e2=0~0~0~0~1~0~0~0~0; e3=0~0~0~0~0~0~0~0~1; endif; @ VECM(4) @ stonum=e2*C1*e3'; @ Cov[s(t+1)-s(t), z(t)] @ sto=e3*C0*e3'; @ Var[z(t)] @ x1=stonum/sto; retp(x1); endp; proc M2(theta); local sto,stonum,g0,gam,j,b1,b2,b3,sigma,a0,e1,e2,e3,A,V,V11,V12,V21,V22, H,B,X1,theta1,theta2,C0,C1; sigma=zeros(2,2); theta1=theta[1:rows(theta)-3]; theta2=theta[rows(theta)-2:rows(theta)]; {A,V}=reverse(theta1,theta2); C0=C(0,A,V); C1=C(1,A,V); if lag==1; e1=1~0~0; e2=0~1~0; e3=0~0~1; endif; if lag==2; e1=1~0~0~0~0; e2=0~0~1~0~0; e3=0~0~0~0~1; endif; if lag==3; e1=1~0~0~0~0~0~0; e2=0~0~0~1~0~0~0; e3=0~0~0~0~0~0~1; endif; @ VECM(3) @ if lag==4; e1=1~0~0~0~0~0~0~0~0; e2=0~0~0~0~1~0~0~0~0; e3=0~0~0~0~0~0~0~0~1; endif; @ VECM(4) @ stonum=e2*C1*e3'; @ Cov[s(t+1)-s(t), z(t)] @ x1=stonum; retp(x1); endp; proc M3(theta); local sto,stonum,g0,gam,j,b1,b2,b3,sigma,a0,e1,e2,e3,A,V,V11,V12,V21,V22, H,B,X1,theta1,theta2,C0,C1; sigma=zeros(2,2); theta1=theta[1:rows(theta)-3]; theta2=theta[rows(theta)-2:rows(theta)]; {A,V}=reverse(theta1,theta2); C0=C(0,A,V); C1=C(1,A,V); if lag==1; e1=1~0~0; e2=0~1~0; e3=0~0~1; endif; if lag==2; e1=1~0~0~0~0; e2=0~0~1~0~0; e3=0~0~0~0~1; endif; if lag==3; e1=1~0~0~0~0~0~0; e2=0~0~0~1~0~0~0; e3=0~0~0~0~0~0~1; endif; @ VECM(3) @ if lag==4; e1=1~0~0~0~0~0~0~0~0; e2=0~0~0~0~1~0~0~0~0; e3=0~0~0~0~0~0~0~0~1; endif; @ VECM(4) @ stonum=e3*C1*e3'; @ Cov[z(t+1),z(t)] @ sto=e3*C0*e3'; @ Var[z(t)] @ x1=stonum/sto; retp(x1); endp; proc M4(theta); local sto,stonum,g0,gam,j,b1,b2,b3,sigma,a0,e1,e2,e3,A,V,V11,V12,V21,V22, H,B,X1,theta1,theta2,C0,C1; sigma=zeros(2,2); theta1=theta[1:rows(theta)-3]; theta2=theta[rows(theta)-2:rows(theta)]; {A,V}=reverse(theta1,theta2); C0=C(0,A,V); C1=C(1,A,V); if lag==1; e1=1~0~0; e2=0~1~0; e3=0~0~1; endif; if lag==2; e1=1~0~0~0~0; e2=0~0~1~0~0; e3=0~0~0~0~1; endif; if lag==3; e1=1~0~0~0~0~0~0; e2=0~0~0~1~0~0~0; e3=0~0~0~0~0~0~1; endif; @ VECM(3) @ if lag==4; e1=1~0~0~0~0~0~0~0~0; e2=0~0~0~0~1~0~0~0~0; e3=0~0~0~0~0~0~0~0~1; endif; @ VECM(4) @ retp(e2*A*C0*A'*e2'); endp; proc M5(theta); local sto,stonum,g0,gam,j,b1,b2,b3,sigma,a0,e1,e2,e3,A,V,V11,V12,V21,V22, H,B,X1,theta1,theta2,C0,C1, a0,g0; sigma=zeros(2,2); theta1=theta[1:rows(theta)-3]; theta2=theta[rows(theta)-2:rows(theta)]; {A,V}=reverse(theta1,theta2); C0=C(0,A,V); C1=C(1,A,V); if lag==1; e1=1~0~0; e2=0~1~0; e3=0~0~1; endif; if lag==2; e1=1~0~0~0~0; e2=0~0~1~0~0; e3=0~0~0~0~1; endif; if lag==3; e1=1~0~0~0~0~0~0; e2=0~0~0~1~0~0~0; e3=0~0~0~0~0~0~1; endif; @ VECM(3) @ if lag==4; e1=1~0~0~0~0~0~0~0~0; e2=0~0~0~0~1~0~0~0~0; e3=0~0~0~0~0~0~0~0~1; endif; @ VECM(4) @ sto=(e3-e2*A)*C0*(e3'-A'*e2'); retp(sto); endp; proc M6(theta); local sto,stonum,g0,gam,j,b1,b2,b3,sigma,a0,e1,e2,e3,A,V,V11,V12,V21,V22, H,B,X1,theta1,theta2,C0,C1, a0,g0; sigma=zeros(2,2); theta1=theta[1:rows(theta)-3]; theta2=theta[rows(theta)-2:rows(theta)]; {A,V}=reverse(theta1,theta2); C0=C(0,A,V); C1=C(1,A,V); if lag==1; e1=1~0~0; e2=0~1~0; e3=0~0~1; endif; if lag==2; e1=1~0~0~0~0; e2=0~0~1~0~0; e3=0~0~0~0~1; endif; if lag==3; e1=1~0~0~0~0~0~0; e2=0~0~0~1~0~0~0; e3=0~0~0~0~0~0~1; endif; @ VECM(3) @ if lag==4; e1=1~0~0~0~0~0~0~0~0; e2=0~0~0~0~1~0~0~0~0; e3=0~0~0~0~0~0~0~0~1; endif; @ VECM(4) @ sto=(e3-e2*A)*C0*(e3'-A'*e2'); retp(sto-e3*c0*e3'); endp; proc M7(theta); local sto,stonum,g0,gam,j,b1,b2,b3,sigma,a0,e1,e2,e3,A,V,V11,V12,V21,V22, H,B,X1,theta1,theta2,C0,C1, a0,g0; sigma=zeros(2,2); theta1=theta[1:rows(theta)-3]; theta2=theta[rows(theta)-2:rows(theta)]; {A,V}=reverse(theta1,theta2); C0=C(0,A,V); C1=C(1,A,V); if lag==1; e1=1~0~0; e2=0~1~0; e3=0~0~1; endif; if lag==2; e1=1~0~0~0~0; e2=0~0~1~0~0; e3=0~0~0~0~1; endif; if lag==3; e1=1~0~0~0~0~0~0; e2=0~0~0~1~0~0~0; e3=0~0~0~0~0~0~1; endif; @ VECM(3) @ if lag==4; e1=1~0~0~0~0~0~0~0~0; e2=0~0~0~0~1~0~0~0~0; e3=0~0~0~0~0~0~0~0~1; endif; @ VECM(4) @ stonum=(e3-e2*A)*C1*(e3'-A'*e2'); sto=(e3-e2*A)*C0*(e3'-A'*e2'); X1=stonum/sto; retp(X1); endp; proc M8(theta); @-- Var[r(t)] - VAR[E(s(t+1)-s(t))|I(t)] --@ local sto,stonum,g0,gam,j,b1,b2,b3,sigma,a0,e1,e2,e3,A,V,V11,V12,V21,V22, H,B,X1,theta1,theta2,C0,C1, a0,g0; sigma=zeros(2,2); theta1=theta[1:rows(theta)-3]; theta2=theta[rows(theta)-2:rows(theta)]; {A,V}=reverse(theta1,theta2); C0=C(0,A,V); C1=C(1,A,V); if lag==1; e1=1~0~0; e2=0~1~0; e3=0~0~1; endif; if lag==2; e1=1~0~0~0~0; e2=0~0~1~0~0; e3=0~0~0~0~1; endif; if lag==3; e1=1~0~0~0~0~0~0; e2=0~0~0~1~0~0~0; e3=0~0~0~0~0~0~1; endif; @ VECM(3) @ if lag==4; e1=1~0~0~0~0~0~0~0~0; e2=0~0~0~0~1~0~0~0~0; e3=0~0~0~0~0~0~0~0~1; endif; @ VECM(4) @ sto=(e3-e2*A)*C0*(e3'-A'*e2'); retp(sto-e2*A*C0*A'*e2'); endp; proc M9(theta); @---- VAR(z(t)) ----@ local sto,stonum,g0,gam,j,b1,b2,b3,sigma,a0,e1,e2,e3,A,V,V11,V12,V21,V22, H,B,X1,theta1,theta2,C0,C1, a0,g0; sigma=zeros(2,2); theta1=theta[1:rows(theta)-3]; theta2=theta[rows(theta)-2:rows(theta)]; {A,V}=reverse(theta1,theta2); C0=C(0,A,V); C1=C(1,A,V); if lag==1; e1=1~0~0; e2=0~1~0; e3=0~0~1; endif; if lag==2; e1=1~0~0~0~0; e2=0~0~1~0~0; e3=0~0~0~0~1; endif; if lag==3; e1=1~0~0~0~0~0~0; e2=0~0~0~1~0~0~0; e3=0~0~0~0~0~0~1; endif; @ VECM(3) @ if lag==4; e1=1~0~0~0~0~0~0~0~0; e2=0~0~0~0~1~0~0~0~0; e3=0~0~0~0~0~0~0~0~1; endif; @ VECM(4) @ sto=e3*C0*e3'; retp(sto); endp; proc M10(theta); @ COV[s(t+1)-s(t), r(t)] @ local sto,stonum,g0,gam,j,b1,b2,b3,sigma,a0,e1,e2,e3,A,V,V11,V12,V21,V22, H,B,X1,theta1,theta2,C0,C1; sigma=zeros(2,2); theta1=theta[1:rows(theta)-3]; theta2=theta[rows(theta)-2:rows(theta)]; {A,V}=reverse(theta1,theta2); C0=C(0,A,V); C1=C(1,A,V); if lag==1; e1=1~0~0; e2=0~1~0; e3=0~0~1; endif; if lag==2; e1=1~0~0~0~0; e2=0~0~1~0~0; e3=0~0~0~0~1; endif; if lag==3; e1=1~0~0~0~0~0~0; e2=0~0~0~1~0~0~0; e3=0~0~0~0~0~0~1; endif; @ VECM(3) @ if lag==4; e1=1~0~0~0~0~0~0~0~0; e2=0~0~0~0~1~0~0~0~0; e3=0~0~0~0~0~0~0~0~1; endif; @ VECM(4) @ stonum=e2*A*C0*(e3'-A'*e2'); x1=stonum; retp(x1); endp; @----Box-Ljung Stat of order p for an Epsilon matrix, Ref: Lutkepohl p300----@ proc Qstat(eps,p); local Q, i, t1; t1=rows(eps); clear Q; i = 1; do while i <= p; Q = Q + (t1^2)/(t1-i)* sumc( diag( Ci(eps,i)'*inv(Ci(eps,0))*Ci(eps,i)*inv(Ci(eps,0)) ) ); i = i + 1; endo; retp(Q); endp; proc Ci(eps,i); @---auto-covariance matrix of epsilon matrix---@ local t, t1, m, Ci; t1=rows(eps); m=cols(eps); Ci=zeros(m,m); t=i+1; do while t <= t1; Ci = Ci + eps[t,.]'*eps[t-i,.]; t = t + 1; endo; Ci=Ci/t1; retp(Ci); endp; proc exdepp(theta); @--calculate expected depreciation for 1 obs--@ local e1, e2, e3, exdep, theta1, theta2; theta1=theta[1:rows(theta)-3]; theta2=theta[rows(theta)-2:rows(theta)]; if lag==1; e1=1~0~0; e2=0~1~0; e3=0~0~1; endif; @ VECM(1) @ if lag==2; e1=1~0~0~0~0; e2=0~0~1~0~0; e3=0~0~0~0~1; endif; @ VECM(2) @ if lag==3; e1=1~0~0~0~0~0~0; e2=0~0~0~1~0~0~0; e3=0~0~0~0~0~0~1; endif; @ VECM(3) @ if lag==4; e1=1~0~0~0~0~0~0~0~0; e2=0~0~0~0~1~0~0~0~0; e3=0~0~0~0~0~0~0~0~1; endif; @ VECM(4) @ {A,V}=reverse(theta1,theta2); exdep = e2*A0 + e2*A*y[.,nn]; retp(exdep); endp; proc rpp(theta); @--calculate expected excess return for 1 obs--@ local e1, e2, e3, rp, theta1, theta2; theta1=theta[1:rows(theta)-3]; theta2=theta[rows(theta)-2:rows(theta)]; if lag==1; e1=1~0~0; e2=0~1~0; e3=0~0~1; endif; @ VECM(1) @ if lag==2; e1=1~0~0~0~0; e2=0~0~1~0~0; e3=0~0~0~0~1; endif; @ VECM(2) @ if lag==3; e1=1~0~0~0~0~0~0; e2=0~0~0~1~0~0~0; e3=0~0~0~0~0~0~1; endif; @ VECM(3) @ if lag==4; e1=1~0~0~0~0~0~0~0~0; e2=0~0~0~0~1~0~0~0~0; e3=0~0~0~0~0~0~0~0~1; endif; @ VECM(4) @ {A,V}=reverse(theta1,theta2); rp = (e3 - e2*A)*y[.,nn] - e2*A0; retp(rp); endp; @===============================================================@ @ END PROCEDURES @ @===============================================================@ "Elapsed Time (minutes)";;(hsec-ts)/(60*100); output off;