1 Star 0 Fork 0

ymhong / Computer Codes

Create your Gitee Account
Explore and code with more than 8 million developers,Free private repositories !:)
Sign up
Clone or Download
5. Hong, Liu and Wang 2009 JoE 5.83 KB
Copy Edit Web IDE Raw Blame History
ymhong authored 2021-03-05 00:34 . first
/* THIS IS THE PROGRAM FOR RiSK SPILLOVER BETWEEN TWO FOREIGN EXCHANGES: Euro/Dollar and Yen/Dollar*/
new;
/* load the data: two stock indices */
load dataCAViaR[12427,3]=dataCAViaR5.txt;
N1=1;
N2=3107;
dataCAViaR=dataCAViaR[N1:N2,.];
/* SAMPLE SIZE */
T=N2-N1+1;
/* Compute the VaR according to Engle's Asymmetric slope CAViaR model */
/* Compute the VaR for Euro/Dollar */
y=dataCAViaR[.,1];
VaR=zeros(T,2); /* 1% and 5% VaR */
ysort= sortc(y[1:300], 1);
let THETA[1,2]= 0.01 0.05;
/*BETA={0.7018 0.8541 -0.0575 0.2520,
0.6889 0.7462 0.0689 0.1603};
BETA={0.377333 0.888206 0.119249 0.288056,
0.330088 0.843126 0.160101 0.160188};
BETA={0.8701 0.822 -0.0923 0.182,
0.704 0.729 0.075 0.1461};
*/
/*
BETA={0.6079 0.8541 -0.0217 0.3177,
0.6889 0.733 0.0811 0.1279};
@ the empirical result in this group can be used @
BETA={0.9947 0.7865 -0.0354 0.2652,
0.8967 0.6693 0.0164 0.116}; */
BETA={0.9947 0.7865 -0.0354 0.2652,
0.8967 0.6693 0.0164 0.116};
j=1; do until j>T;
if j==1;
NumA=round(300*THETA[1,1]);
VaR[j,1] = (-1)* ysort[NumA];
NumB=round(300*THETA[1,2]);
VaR[j,2] = (-1)* ysort[NumB];
else;
VaR[j,1] = BETA[1,1] + BETA[1,2] * VaR[j-1,1] + BETA[1,3] * y[j-1] * (y[j-1] > 0)
- BETA[1,4] * y[j-1] * (y[j-1] < 0);
VaR[j,2] = BETA[2,1] + BETA[2,2] * VaR[j-1,1] + BETA[2,3] * y[j-1] * (y[j-1] > 0)
- BETA[2,4] * y[j-1] * (y[j-1] < 0);
endif;
j=j+1;
endo;
UvaR01=(y .<-VaR[.,1]);
Uvar01=Uvar01-meanc(Uvar01);
UvaR05=(y .<-VaR[.,2]);
Uvar05=Uvar05-meanc(Uvar05);
/* Compute the VaR for Yen/Dollar */
y=dataCAViaR[.,2];
VaR=zeros(T,2); /* 1% and 5% VaR */
ysort= sortc(y[1:300], 1);
let THETA[1,2]= 0.01 0.05;
/*BETA={1.5573 0.7697 -0.2982 0.2465,
1.0722 0.6731 -0.0341 0.1127};
BETA={1.805677 0.657694 -0.09966 0.489407,
1.422133 0.518572 0.111467 0.231643};
BETA={1.745 0.7123 -0.2491 0.1837,
0.4289 0.8517 -0.0306 0.1205};
*/
/*
BETA={2.0081 0.6687 -0.2999 0.3286,
0.7769 0.7472 -0.033 0.1623}; */
BETA={2.3679 0.5695 -0.0665 1.0781,
0.8432 0.7765 -0.037 0.0891};
j=1; do until j>T;
if j==1;
VaR[j,1] = -ysort[round(300*THETA[1,1]), 1];
VaR[j,2] = -ysort[round(300*THETA[1,2]), 1];
else;
VaR[j,1] = BETA[1,1] + BETA[1,2] * VaR[j-1,1] + BETA[1,3] * y[j-1] * (y[j-1] > 0)
- BETA[1,4] * y[j-1] * (y[j-1] < 0);
VaR[j,2] = BETA[2,1] + BETA[2,2] * VaR[j-1,1] + BETA[2,3] * y[j-1] * (y[j-1] > 0)
- BETA[2,4] * y[j-1] * (y[j-1] < 0);
endif;
j=j+1;
endo;
VvaR01=(y .<-VaR[.,1]);
vvar01=vvar01-meanc(vvar01);
VvaR05=(y .<-VaR[.,2]);
vvar05=vvar05-meanc(vvar05);
/* KERNEL FUNCTIONS */
/* THE pi CONSTANT */
Con1=pi;
/* BARTLETT KERNEL */
proc Wbar(u);
local Y;
Y=(1-u).*(u.<=1);
retp(Y);
endp;
/* DANIELL KERNEL */
proc Wdan(u);
local Y;
Y=sin(Con1*u)./(Con1*u);
retp(Y);
endp;
/* PARZEN KERNEL */
proc Wpar(u);
local X,Y;
X=(Con1/6)*u;
Y = (1-6.*X^2+6.*X^3).*(X.<=0.5) + (2.*(1-X)^3).*(X.>0.5).*(X.<=1.0);
retp(Y);
endp;
/* QS KERNEL */
proc Wqs(u);
local Y;
Y=sqrt(5/3)*Con1*u;
Y=(3./Y^2).*(sin(Y)./Y - cos(Y));
retp(Y);
endp;
/* TRUNCATED KERNEL */
proc Wtr(u);
local Y;
Y=(u.<=1);
retp(Y);
endp;
proc Kbar(n0,p0);
local j,Y,c0;
c0=cols(p0);
Y=zeros(N0,c0);
j=1;
do until j==N0+1;
Y[j,.]=Wbar(j./p0);
j=j+1;
endo;
retp(Y);
endp;
proc Kdan(n0,p0);
local j,Y,c0;
c0=cols(p0);
Y=zeros(n0,c0);
j=1;
do until j==n0+1;
Y[j,.]=Wdan(j./p0);
j=j+1;
endo;
retp(Y);
endp;
proc Kpar(n0,p0);
local j,Y,c0;
c0=cols(p0);
Y=zeros(n0,c0);
j=1;
do until j==n0+1;
Y[j,.]=Wpar(j./p0);
j=j+1;
endo;
retp(Y);
endp;
proc Kqs(n0,p0);
local j,Y,c0;
c0=cols(p0);
Y=zeros(n0,c0);
j=1;
do until j==n0+1;
Y[j,.]=Wqs(j./p0);
j=j+1;
endo;
retp(Y);
endp;
proc Ktr(n0,p0);
local j,Y,c0;
c0=cols(p0);
Y=zeros(n0,c0);
j=1;
do until j==n0+1;
Y[j,.]=Wtr(j./p0);
j=j+1;
endo;
retp(Y);
endp;
/* M: Lag orders */
M=5~10~15~20~25~30~35~40~45~50;
Ka=Kbar(T-1,M);
Kb=Kdan(T-1,M);
Kc=Kpar(T-1,M);
Kd=Kqs(T-1,M);
/* SQUARED KERNEL WEIGHT FOR Q1 */
/* Use the Daniell kernel only */
KSa=Kb;
KSa=KSa.*KSa;
/* cols(M)=number of M, 1=number of kernels */
C1ka=zeros(1,cols(M));
D1ka=C1ka;
C1kb=C1ka;
D1kb=C1ka;
j=1;
do until j==T;
C1ka=C1ka+(1-j/T)*KSa[j,.];
D1ka=D1ka+(1-j/T)*(1-(j+1)/T)*KSa[j,.].*KSa[j,.];
j=j+1;
endo;
/* STANDARDIZATION FACTORS OF Q2a */
C2ka=2*C1ka+1;
D2ka=2*D1ka+(1-1/T);
/* STANDARD DEVIATION OF THE TEST STATISTICS */
V1ka=sqrt(2*D1ka);
V2ka=sqrt(2*D2ka);
ALTER=1;
do until ALTER==4+1;
/* ALTER 1--4: test spillover in mean and volatility */
if ALTER==1;
U=Uvar01;
V=Vvar01;
elseif ALTER==2;
U=Vvar01;
V=Uvar01;
elseif ALTER==3;
U=Uvar05;
V=Vvar05;
elseif ALTER==4;
U=Vvar05;
V=Uvar05;
/* ALTER 9-12: Test model adequacy */
endif;
/* COMPUTE CROSS-CORRELATIONS */
/* SUBVECTORS */
/* t=j+1 to T */
proc U1(j);
local Y;
Y=U[j+1:T,1];
retp(Y);
endp;
/* t=1 to T-j */
proc U2(j);
local Y;
Y=U[1:T-j,1];
retp(Y);
endp;
/* t=j+1 to T */
proc V1(j);
local Y;
Y=V[j+1:T,1];
retp(Y);
endp;
/* t=1 to T-j */
proc V2(j);
local Y;
Y=V[1:T-j,1];
retp(Y);
endp;
/* BELOW CORRELATIONS */
proc CUV1(j);
local Y;
Y=U1(j)'V2(j);
retp(Y/T);
endp;
proc CUV2(j);
local Y;
Y=U2(j)'V1(j);
retp(Y/T);
endp;
CUU0=U'U/T;
CVV0=V'V/T;
/* CORRS1 IS U LEADS AHEAD OF V
CORRS2 IS V LEADS AHEAD OF U */
CORRS1=zeros(T-1,1);
CORRS2=CORRS1;
j=1;
do until j==T;
CORRS1[j,1]=CUV1(j);
CORRS2[j,1]=CUV2(j);
j=j+1;
endo;
CORRS1=CORRS1.*CORRS1/(CUU0*CVV0);
CORRS2=CORRS2.*CORRS2/(CUU0*CVV0);
CORRS0=U'V/T;
CORRS0=CORRS0.*CORRS0/(CUU0*CVV0);
/* TEST STATISTICS */
Q1a=(T*CORRS1'KSa - C1ka)./V1ka;
Q2a=(T*((CORRS1+CORRS2)'KSa+CORRS0)-C2ka)./V2ka;
STAT1=Q1a;
STAT2=Q2a;
STAT=STAT1~STAT2;
/* P-VALUES */
PVALUE1=cdfnc(Q1a);
PVALUE2=cdfnc(Q2a);
PVALUE=PVALUE1~PVALUE2;
format /rd 13,8;
output file=EurYen.sta on;
ALTER~STAT;
output off;
output file=EurYen.pva on;
ALTER~PVALUE;
output off;
ALTER=ALTER+1;
endo;
R
1
https://gitee.com/ymhong/code.git
git@gitee.com:ymhong/code.git
ymhong
code
Computer Codes
master

Search