/*@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ * 1. estimate model using first R obs 2. simulate x_sim(t+tao), for the out-of-sample P 3. calculate conditional distribution prob(u1 pp; Omegaj = hhat[jj+1:N,.]'hhat[1:N-jj,.]/N; Shat = Shat + ( 1 - jj/(m+1) ) * (Omegaj + Omegaj'); jj = jj + 1; endo; retp(Shat); endp; /*@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ * DGP_CIR: Data Generation as CIR process * * dp(t)=phi*(p_bar-p(t))*dt+sig*sqrt(p(t)*dW(t) * ************************************************************************************************* * Inputs: T - Length of time series * * h - discretization interval * * phi - mean reversion parameter Process * * p_bar - mean level * * sig1 - variance term * * see - seed of rndns * * Output: dat - time series * @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@*/ proc DGP_CIR(T,h,phi,p_bar,sig1,see); local TN,dat,Pt,i,X1,ee; TN=round(T/h); ee=sqrt(h)*rndns(TN,1,see); dat={}; Pt=p_bar;// here we use the estimated parameter as start value i=0; do while i < TN; i=i+1; X1=Pt+phi*(p_bar-Pt)*h+sig1*sqrt(pt)*ee[i] -0.5*(sig1*sqrt(pt))*(0.5*sig1/sqrt(pt))*h +0.5*(sig1*sqrt(pt))*(0.5*sig1/sqrt(pt))*(ee[i]^2); /*Theory implies that this condition will never be reached as when process approaches zero the volatility is switched off, that result depends on h going to zero here h is very small indeed I am including the condition as a final safe guard, here I am switching off the volatility manually something that should happens assymptotically*/ if X1 < 0; X1=Pt+phi*(p_bar-Pt)*h; print " same $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$"; endif; if i%(h^-1)==0; dat=dat|X1; endif; Pt=X1; endo; retp(dat); endp; /*@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ * DGP_CIRsim: Data Generation as CIR process for simulation, The only difference with above is that we are given the start value of X(0) * * dp(t)=phi*(p_bar-p(t))*dt+sig*sqrt(p(t)*dW(t) * *************************************************************************************************/ proc DGP_CIRsim(T,h,phi,p_bar,sig1,see,start); local TN,dat,Pt,i,X1,ee; TN=round(T/h); ee=sqrt(h)*rndns(TN,1,see); dat={}; Pt=start; // here we use the given X(0) as start value i=0; do while i < TN; i=i+1; X1=Pt+phi*(p_bar-Pt)*h+sig1*sqrt(pt)*ee[i] -0.5*(sig1*sqrt(pt))*(0.5*sig1/sqrt(pt))*h +0.5*(sig1*sqrt(pt))*(0.5*sig1/sqrt(pt))*(ee[i]^2); /*Theory implies that this condition will never be reached as when process approaches zero the volatility is switched off, that result depends on h going to zero here h is very small indeed I am including the condition as a final safe guard, here I am switching off the volatility manually something that should happens assymptotically*/ if X1 < 0; X1=Pt+phi*(p_bar-Pt)*h; endif; if i%((h^-1))==0; dat=dat|X1; endif; Pt=X1; endo; retp(dat); endp; /*@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ * Data Generation * * DGP: SM * * dr(t) = kapa_r*(theta(t)-r(t))*dt+sig1*dW1(t) * * dTheta(t) = kapa_Theta*(theta_bar-theta(t))*dt+(sig3*sqrt(theta(t)))*dW3(t) * * W's are mulually independent Brownian motions * ************************************************************************************************* * Inputs: T: Length of time series * * h: discretization interval * * kapa_r: mean reversion parameter Interest Rate Process * * sig1: variance term interest rate Process * * kapa_theta: mean reversion parameter mean process * * theta_bar: mean Level, also used as the starting value of the mean process * * sig3: variance term mean Process * @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@*/ proc(2)= DGP_SM(T,h,kapa_r,sig1,kapa_theta,theta_bar,sig3,see); local TN,e1,e2,dat,Pt,Mt,i,zi1,zi2,r,r2,rhop,I21,M1,XX,test; test={}; dat={}; TN=round(T/h); e1= sqrt(h)*rndns(TN,1,see); e2= sqrt(h)*rndns(TN,1,see); Pt=theta_bar; Mt=theta_bar; i=0; do while i < TN; i=i+1; XX=Pt+kapa_r*(Mt-Pt)*h+sig1*e1[i]; M1=Mt+(kapa_theta*(theta_bar-Mt))*h+sig3*sqrt(Mt)*e2[i]; if M1 < 0; M1=Mt+(kapa_theta*(theta_bar-Mt))*h; endif; if i%(h^-1)==0; dat=dat|XX; test=test|M1; endif; Pt=XX; Mt=M1; endo; retp(dat,test); endp; proc(2)= DGP_SMsim(T,h,kapa_r,sig1,kapa_theta,theta_bar,sig3,see,start1,start2); local TN,e1,e2,dat,Pt,Mt,i,zi1,zi2,r,r2,rhop,I21,M1,XX,test; test={}; dat={}; TN=round(T/h); e1= sqrt(h)*rndns(TN,1,see); e2= sqrt(h)*rndns(TN,1,see); Pt=start1; // here we use the given X(0) as start value Mt=start2; // here we use the given seta(0) as start value i=0; do while i < TN; i=i+1; XX=Pt+kapa_r*(Mt-Pt)*h+sig1*e1[i]; M1=Mt+(kapa_theta*(theta_bar-Mt))*h+sig3*sqrt(Mt)*e2[i]; if M1 < 0; M1=Mt+(kapa_theta*(theta_bar-Mt))*h; endif; if i%(h^-1)==0; dat=dat|XX; test=test|M1; endif; Pt=XX; Mt=M1; endo; retp(dat,test); endp; /*@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ * Data Generation * * DGP:SV * * dr(t) = kapa_r*(r_bar-r(t))*dt+(sqrt(V(t)))*dW1(t) * * dV(t) = kapa_v*(v_bar-V(t))*dt+(sig2*sqrt(V(t)))*dW2(t) * ************************************************************************************************* * Inputs: T: Length of time series * * h: discretization interval * * kapa_r: mean reversion parameter Interest Rate Process * * r_bar: mean Level, also used as the starting value of the mean process * * kapa_v: mean reversion parameter volatility process * * v_bar: mean Volatility Level, also used as the starting value of the vol process * * sig2: variance term Volatility Process * @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@*/ proc(2)= DGP_SV(T,h,kapa_r,r_bar,kapa_v,v_bar,sig2,rho,see); local p,TN,e1,e2,dat,Pt,Vt,i,zi1,zi2,r,r2,rhop,I21,V1,XX,test; test={}; p=1/h; TN=round(T/h); e1= sqrt(h)*rndns(TN,1,see); e2= sqrt(h)*rndns(TN,1,see); dat={}; Pt=r_bar; Vt=v_bar; i=0; do while i < TN; i=i+1; XX=Pt+kapa_r*(r_bar-Pt)*h+sqrt(Vt)*(e1[i]*((1-rho^2)^0.5)+rho*e2[i]); V1=Vt+(kapa_v*(v_bar-Vt))*h+sig2*sqrt(vt)*e2[i]; if V1 < 0; V1=Vt+(kapa_v*(v_bar-Vt))*h; endif; if i%(h^-1)==0; dat=dat|XX; test=test|v1; endif; Pt=XX; Vt=V1; endo; retp(dat,test); endp; proc(2)= DGP_SVsim(T,h,kapa_r,r_bar,kapa_v,v_bar,sig2,rho,see,start1,start2); local p,TN,e1,e2,dat,Pt,Vt,i,zi1,zi2,r,r2,rhop,I21,V1,XX,test; test={}; p=1/h; TN=round(T/h); e1= sqrt(h)*rndns(TN,1,see); e2= sqrt(h)*rndns(TN,1,see); dat={}; Pt=start1; Vt=start2; i=0; do while i < TN; i=i+1; XX=Pt+kapa_r*(r_bar-Pt)*h+sqrt(Vt)*(e1[i]*((1-rho^2)^0.5)+rho*e2[i]); V1=Vt+(kapa_v*(v_bar-Vt))*h+sig2*sqrt(vt)*e2[i]; if V1 < 0; V1=Vt+(kapa_v*(v_bar-Vt))*h; endif; if i%(h^-1)==0; dat=dat|XX; test=test|v1; endif; Pt=XX; Vt=V1; endo; retp(dat,test); endp; /*@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ * Data Generation * * DGP:SVj * ************************************************************************************************* * Inputs: T: Length of time series * * h: discretization interval * * kapa_r: mean reversion parameter Interest Rate Process * * r_bar: mean Level, also used as the starting value of the mean process * * kapa_v: mean reversion parameter volatility process * * v_bar: mean Volatility Level, also used as the starting value of the vol process * * sig2: variance term Volatility Process * @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@*/ proc(2)= DGP_SVJ(T,h,kapa_r,r_bar,kapa_v,v_bar,sig2,rho,lamdau,NUu,lamdad,NUd,see); local p,TN,e1,e2,dat,Pt,Vt,i,zi1,zi2,r,r2,rhop,I21,V1,XX,test,e3,jumpu,p_jumpu,jumpd,p_jumpd,jump; test={}; p=1/h; TN=round(T/h); e1= sqrt(h)*rndns(TN,1,see); e2= sqrt(h)*rndns(TN,1,see); e3 = rndus(TN,4,see); jumpu=-NUu*ln(e3[.,2]); p_jumpu=exp(-lamdau*h); p_jumpu=e3[.,1].>p_jumpu; jumpu=jumpu.*p_jumpu; jumpd=-NUd*ln(e3[.,4]); p_jumpd=exp(-lamdad*h); p_jumpd=e3[.,3].>p_jumpd; jumpd=jumpd.*p_jumpd; jump=jumpu-jumpd; dat={}; Pt=r_bar; Vt=v_bar; i=0; do while i < TN; i=i+1; XX=Pt+kapa_r*(r_bar-Pt)*h+sqrt(Vt)*(e1[i]*((1-rho^2)^0.5)+rho*e2[i])+jump[i]; V1=Vt+(kapa_v*(v_bar-Vt))*h+sig2*sqrt(vt)*e2[i]; if V1 < 0; V1=Vt+(kapa_v*(v_bar-Vt))*h; endif; /*Theory implies that this condition will never be reached as when process approaches zero the volatility is switched off, that result depends on h going to zero. Here h is very small indeed, I am including the condition as a final safe-guard, here I am switching off the volatility manually as a precaution something that should happens assymptotically*/ if i%(h^-1)==0; dat=dat|XX; test=test|v1; endif; Pt=XX; Vt=V1; endo; retp(dat,test); endp; proc(2)= DGP_SVJsim(T,h,kapa_r,r_bar,kapa_v,v_bar,sig2,rho,lamdau,NUu,lamdad,NUd,see,start1,start2); local p,TN,e1,e2,dat,Pt,Vt,i,zi1,zi2,r,r2,rhop,I21,V1,XX,test,e3,jumpu,p_jumpu,jumpd,p_jumpd,jump; test={}; p=1/h; TN=round(T/h); e1= sqrt(h)*rndns(TN,1,see); e2= sqrt(h)*rndns(TN,1,see); e3 = rndus(TN,4,see); jumpu=-NUu*ln(e3[.,2]); p_jumpu=exp(-lamdau*h); p_jumpu=e3[.,1].>p_jumpu; jumpu=jumpu.*p_jumpu; jumpd=-NUd*ln(e3[.,4]); p_jumpd=exp(-lamdad*h); p_jumpd=e3[.,3].>p_jumpd; jumpd=jumpd.*p_jumpd; jump=jumpu-jumpd; //calculate Jump; dat={}; Pt=start1; Vt=start2; i=0; do while i < TN; i=i+1; XX=Pt+kapa_r*(r_bar-Pt)*h+sqrt(Vt)*(e1[i]*((1-rho^2)^0.5)+rho*e2[i])+jump[i]; V1=Vt+(kapa_v*(v_bar-Vt))*h+sig2*sqrt(vt)*e2[i]; if V1 < 0; V1=Vt+(kapa_v*(v_bar-Vt))*h; endif; /*Theory implies that this condition will never be reached as when process approaches zero the volatility is switched off, that result depends on h going to zero. Here h is very small indeed, I am including the condition as a final safe-guard, here I am switching off the volatility manually as a precaution something that should happens assymptotically*/ if i%(h^-1)==0; dat=dat|XX; test=test|v1; endif; Pt=XX; Vt=V1; endo; retp(dat,test); endp; /*@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ * Data Generation * * DGP: CHEN * * dr(t) = kapa_r*(theta(t)-r(t))*dt+(sqrt(V(t)))*dW1(t) * * dV(t) = kapa_v*(v_bar-V(t))*dt+(sig2*sqrt(V(t)))*dW2(t) * * dTheta(t) = kapa_Theta*(theta_bar-theta(t))*dt+(sig3*sqrt(theta(t)))*dW3(t) * * W's are mulually independent Brownian motions * ************************************************************************************************* * Inputs: T: Length of time series * * h: discretization interval * * kapa_r: mean reversion parameter Interest Rate Process * * kapa_v: mean reversion parameter volatility process * * v_bar: mean Volatility Level, also used as the starting value of the vol process * * sig2: variance term Volatility Process * * kapa_theta: mean reversion parameter mean process * * theta_bar: mean Level, also used as the starting value of the mean process * * sig3: variance term mean Process * * sim_ind: indicator for generating the errors * * sim_ind = 0 if errors are to be generated randomly * * sim_ind = 1 if errors are to be be taken from a global variable (SGMM) * @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@*/ proc(3)= DGP_chen(T,h,kapa_r,kapa_v,v_bar,sig2,kapa_theta,theta_bar,sig3,see); local theta_fact,v_fact,TN,e1,e2,e3,dat,pt,vt,mt,i,xx,v1,m1; v_fact={};theta_fact={}; TN=round(T/h); e1= sqrt(h)*rndns(TN,1,see); e2= sqrt(h)*rndns(TN,1,see); e3= sqrt(h)*rndns(TN,1,see); dat={}; Pt=theta_bar; Vt=v_bar; Mt=theta_bar; i=0; do while i < TN; i=i+1; XX=Pt+kapa_r*(Mt-Pt)*h+sqrt(Vt)*e1[i]; V1=Vt+(kapa_v*(v_bar-Vt))*h+sig2*sqrt(vt)*e2[i]; if V1 < 0; V1=Vt+(kapa_v*(v_bar-Vt))*h; endif; M1=Mt+(kapa_theta*(theta_bar-Mt))*h+sig3*sqrt(Mt)*e3[i]; if M1 < 0; M1=Mt+(kapa_theta*(theta_bar-Mt))*h; endif; if i%(h^-1)==0; dat=dat|XX; v_fact=v_fact|v1; theta_fact=theta_fact|M1; endif; Pt=XX; Vt=V1; Mt=m1; endo; retp(dat,v_fact,theta_fact); endp; proc(3)= DGP_chensim(T,h,kapa_r,kapa_v,v_bar,sig2,kapa_theta,theta_bar,sig3,see,start1,start2,start3); local theta_fact,v_fact,TN,e1,e2,e3,dat,pt,vt,mt,i,xx,v1,m1; v_fact={};theta_fact={}; TN=round(T/h); e1= sqrt(h)*rndns(TN,1,see); e2= sqrt(h)*rndns(TN,1,see); e3= sqrt(h)*rndns(TN,1,see); dat={}; Pt=start1; Vt=start2; Mt=start3;// change start value for diffusion process i=0; do while i < TN; i=i+1; XX=Pt+kapa_r*(Mt-Pt)*h+sqrt(Vt)*e1[i]; V1=Vt+(kapa_v*(v_bar-Vt))*h+sig2*sqrt(vt)*e2[i]; if V1 < 0; V1=Vt+(kapa_v*(v_bar-Vt))*h; endif; M1=Mt+(kapa_theta*(theta_bar-Mt))*h+sig3*sqrt(Mt)*e3[i]; if M1 < 0; M1=Mt+(kapa_theta*(theta_bar-Mt))*h; endif; if i%(h^-1)==0; dat=dat|XX; v_fact=v_fact|v1; theta_fact=theta_fact|M1; endif; Pt=XX; Vt=V1; Mt=m1; endo; retp(dat,v_fact,theta_fact); endp; /*@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ * Data Generation * * DGP: feed * ************************************************************************************************* * Inputs: T: Length of time series * * h: discretization interval * * kapa_r: mean reversion parameter Interest Rate Process * * kapa_r_v: parameter capturig the effect of volatility on conditional mean * * rho: conditional correlation between short rate and its stochastic volatility * * kapa_v: mean reversion parameter volatility process * * v_bar: mean Volatility Level, also used as the starting value of the vol process * * sig2: variance term Volatility Process * * kapa_theta: mean reversion parameter mean process * * kapa_theta_v: parameter capturig the effect of volatility on mean theta * * theta_bar: mean Level, also used as the starting value of the mean process * * sig3: variance term mean Process * @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@*/ proc(3)= DGP_Feed(T,h,kapa_r,kapa_v,v_bar,sig2,kapa_theta,theta_bar,sig3,kapa_r_v,rho,see); local theta_fact,v_fact,TN,e1,e2,e3,dat,pt,vt,mt,i,xx,v1,m1; v_fact={};theta_fact={}; TN=round(T/h); e1= sqrt(h)*rndns(TN,1,see); e2= sqrt(h)*rndns(TN,1,see); e3= sqrt(h)*rndns(TN,1,see); dat={}; Pt=theta_bar; Vt=v_bar; Mt=theta_bar; i=0; do while i < TN; i=i+1; XX=Pt+kapa_r*(Mt-Pt)*h+kapa_r_v*(v_bar-Vt)*h+sqrt(Vt)*(e1[i]*((1-rho^2)^0.5)+rho*e2[i]); V1=Vt+(kapa_v*(v_bar-Vt))*h+sig2*sqrt(vt)*e2[i]; if V1 < 0; V1=Vt+(kapa_v*(v_bar-Vt))*h; endif; M1=Mt+(kapa_theta*(theta_bar-Mt))*h+sig3*sqrt(Mt)*e3[i]; if M1 < 0; M1=Mt+(kapa_theta*(theta_bar-Mt))*h; endif; if i%(h^-1)==0; dat=dat|XX; v_fact=v_fact|v1; theta_fact=theta_fact|M1; endif; Pt=XX; Vt=V1; Mt=m1; endo; retp(dat,v_fact,theta_fact); endp; proc(3)= DGP_Feedsim(T,h,kapa_r,kapa_v,v_bar,sig2,kapa_theta,theta_bar,sig3,kapa_r_v,rho,see,start1,start2,start3); local theta_fact,v_fact,TN,e1,e2,e3,dat,pt,vt,mt,i,xx,v1,m1; v_fact={};theta_fact={}; TN=round(T/h); e1= sqrt(h)*rndns(TN,1,see); e2= sqrt(h)*rndns(TN,1,see); e3= sqrt(h)*rndns(TN,1,see); dat={}; Pt=start1; Vt=start2; Mt=start3;// change start value for diffusion process i=0; do while i < TN; i=i+1; XX=Pt+kapa_r*(Mt-Pt)*h+kapa_r_v*(v_bar-Vt)*h+sqrt(Vt)*(e1[i]*((1-rho^2)^0.5)+rho*e2[i]); V1=Vt+(kapa_v*(v_bar-Vt))*h+sig2*sqrt(vt)*e2[i]; if V1 < 0; V1=Vt+(kapa_v*(v_bar-Vt))*h; endif; M1=Mt+(kapa_theta*(theta_bar-Mt))*h+sig3*sqrt(Mt)*e3[i]; if M1 < 0; M1=Mt+(kapa_theta*(theta_bar-Mt))*h; endif; if i%(h^-1)==0; dat=dat|XX; v_fact=v_fact|v1; theta_fact=theta_fact|M1; endif; Pt=XX; Vt=V1; Mt=m1; endo; retp(dat,v_fact,theta_fact); endp; /*@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ * Data Generation * * DGP: CHEN_JUMP * ************************************************************************************************* * Inputs: T: Length of time series * * h: discretization interval * * kapa_r: mean reversion parameter Interest Rate Process * * kapa_v: mean reversion parameter volatility process * * v_bar: mean Volatility Level, also used as the starting value of the vol process * * sig2: variance term Volatility Process * * kapa_theta: mean reversion parameter mean process * * theta_bar: mean Level, also used as the starting value of the mean process * * sig3: variance term mean Process * * sim_ind: indicator for generating the errors * * sim_ind = 0 if errors are to be generated randomly * * sim_ind = 1 if errors are to be be taken from a global variable (SGMM) * @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@*/ proc(3)= DGP_chenJ(T,h,kapa_r,kapa_v,v_bar,sig2,kapa_theta,theta_bar,sig3,lamdau,NUu,lamdad,NUd,see); local theta_fact,v_fact,TN,e1,e2,e3,dat,pt,vt,mt,i,xx,v1,m1,e4,jumpu,p_jumpu,jumpd,p_jumpd,jump; v_fact={};theta_fact={}; TN=round(T/h); e1= sqrt(h)*rndns(TN,1,see); e2= sqrt(h)*rndns(TN,1,see); e3= sqrt(h)*rndns(TN,1,see); dat={}; e4 = rndus(TN,4,see); jumpu=-NUu*ln(e4[.,2]); p_jumpu=exp(-lamdau*h); p_jumpu=e4[.,1].>p_jumpu; jumpu=jumpu.*p_jumpu; jumpd=-NUd*ln(e4[.,4]); p_jumpd=exp(-lamdad*h); p_jumpd=e4[.,3].>p_jumpd; jumpd=jumpd.*p_jumpd; jump=jumpu-jumpd; Pt=theta_bar; Vt=v_bar; Mt=theta_bar; i=0; do while i < TN; i=i+1; XX=Pt+kapa_r*(Mt-Pt)*h+sqrt(Vt)*e1[i]+jump[i]; V1=Vt+(kapa_v*(v_bar-Vt))*h+sig2*sqrt(vt)*e2[i]; if V1 < 0; V1=Vt+(kapa_v*(v_bar-Vt))*h; endif; M1=Mt+(kapa_theta*(theta_bar-Mt))*h+sig3*sqrt(Mt)*e3[i]; if M1 < 0; M1=Mt+(kapa_theta*(theta_bar-Mt))*h; endif; if i%(h^-1)==0; dat=dat|XX; v_fact=v_fact|v1; theta_fact=theta_fact|M1; endif; Pt=XX; Vt=V1; Mt=m1; endo; retp(dat,v_fact,theta_fact); endp; proc(3)= DGP_chenJsim(T,h,kapa_r,kapa_v,v_bar,sig2,kapa_theta,theta_bar,sig3,lamdau,NUu,lamdad,NUd,see,start1,start2,start3); local theta_fact,v_fact,TN,e1,e2,e3,dat,pt,vt,mt,i,xx,v1,m1,e4,jumpu,p_jumpu,jumpd,p_jumpd,jump; v_fact={};theta_fact={}; TN=round(T/h); e1= sqrt(h)*rndns(TN,1,see); e2= sqrt(h)*rndns(TN,1,see); e3= sqrt(h)*rndns(TN,1,see); dat={}; e4 = rndus(TN,4,see); jumpu=-NUu*ln(e4[.,2]); p_jumpu=exp(-lamdau*h); p_jumpu=e4[.,1].>p_jumpu; jumpu=jumpu.*p_jumpu; jumpd=-NUd*ln(e4[.,4]); p_jumpd=exp(-lamdad*h); p_jumpd=e4[.,3].>p_jumpd; jumpd=jumpd.*p_jumpd; jump=jumpu-jumpd; Pt=start1; Vt=start2; Mt=start3;// change start value for diffusion process i=0; do while i < TN; i=i+1; XX=Pt+kapa_r*(Mt-Pt)*h+sqrt(Vt)*e1[i]+jump[i]; V1=Vt+(kapa_v*(v_bar-Vt))*h+sig2*sqrt(vt)*e2[i]; if V1 < 0; V1=Vt+(kapa_v*(v_bar-Vt))*h; endif; M1=Mt+(kapa_theta*(theta_bar-Mt))*h+sig3*sqrt(Mt)*e3[i]; if M1 < 0; M1=Mt+(kapa_theta*(theta_bar-Mt))*h; endif; if i%(h^-1)==0; dat=dat|XX; v_fact=v_fact|v1; theta_fact=theta_fact|M1; endif; Pt=XX; Vt=V1; Mt=m1; endo; retp(dat,v_fact,theta_fact); endp; /*@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ * Data statistics * * *************************************************************************************************/ proc dis_stat(yt); local avg,std,skew,kurt,stat; avg=meanc(yt); std=stdc(yt); skew=meanc(((yt-meanc(yt))/stdc(yt))^3); kurt=meanc(((yt-meanc(yt))/stdc(yt))^4); stat=avg|std|skew|kurt; retp(stat); endp; /*@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ * estimate: estimate the parameters * ************************************************************************************************* * Inputs: dat1 - time series * * indicator - model indicator * * Output: est - estimated parameters * @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@*/ /* xt: is the lagged xt model_ind; model indicator = 1 SM = 2 SV = 3 SVJ : need to change the jumps = 4 CHEN = 5 FEEDBACk = 6 CHEN_JUMP = 7 CIR */ proc(1)=estimate(xt,model_ind); local b_start,b,f,g,retcode,cov0,SD_fnl; b={}; if model_ind==1; coset; __output=0; _co_Diagnostic = 1; _co_A = {0 0 1 0 0}; _co_B = {0.300};// add equality constraint for this one, becoz H fails _co_C = {1 0 0 0 0, 0 1 0 0 0, 0 0 1 0 0, 0 0 0 1 0, 0 0 0 0 1}; _co_D = {0, 0, 0, 0, 0}; _co_IneqProc = &ineq_two; b_start=1.8|0.03|0.3|0.06|0.04; {b,f,g,retcode} = co(&GMM_SM,b_start); // get std of parameters cov0=inv(hessp(&GMM_SM,b)); SD_fnl =sqrt(diag(cov0)); @Standard errors of the estimated coefficients@ print " std are=" SD_fnl; print " f=" f; elseif model_ind==2; coset; __output=0; _co_Algorithm=3; _co_LineSearch=4; _co_DirTol=1e-3; _co_C = {1 0 0 0 0 0, 0 1 0 0 0 0, 0 0 1 0 0 0, 0 0 0 1 0 0, 0 0 0 0 1 0, 0 0 0 0 0 1, 0 0 0 0 0 -1}; _co_D = {0, 0, 0, 0, 0, -1, 0}; _co_IneqProc = &ineq_two; b_start=0.3|0.06|3.5|0.00006|0.02|-0.5; {b,f,g,retcode} = co(&GMM_SV,b_start); // get std of parameters cov0=inv(hessp(&GMM_SV,b)); SD_fnl =sqrt(diag(cov0)); @Standard errors of the estimated coefficients@ print " std are=" SD_fnl; elseif model_ind==3; coset; __output=0; _co_Algorithm=3; _co_LineSearch=1; _co_DirTol=1e-4; _co_TrustRadius=1; _co_IneqProc = &ineq_two; _co_A = {0 0 0 0 0 0 1 0 0 0, 0 0 0 0 0 0 0 1 0 0, 0 0 0 0 0 0 0 0 1 0, 0 0 0 0 0 0 0 0 0 1}; _co_B = {5.4979, 0.0011, 3.121, 0.002};// add equality constraint for this one, becoz H fails, fix lamda in SVJ estimation _co_C = { 1 0 0 0 0 0 0 0 0 0, 0 1 0 0 0 0 0 0 0 0, 0 0 1 0 0 0 0 0 0 0, 0 0 0 1 0 0 0 0 0 0, 0 0 0 0 1 0 0 0 0 0, 0 0 0 0 0 1 0 0 0 0, 0 0 0 0 0 -1 0 0 0 0}; _co_D = {0,0,0,0,0, -1, 0}; b_start=0.230503|0.052496|2.292159|0.000019|0.0100042|-0.105|7.899973|0.001056|1.600042|0.001922; {b,f,g,retcode} = co(&gmm_SVJ,b_start); print "f=" f; elseif model_ind==4; coset; __output=0; _co_Algorithm=3; _co_LineSearch=1; _co_Trust=1; _co_IneqProc = &ineq_three; b_start=0.2|3|0.0003|0.01|0.3|0.06|0.04; //_co_A = {0 1 0 0 0 0 0 }; //_co_B = {2.9051};// add equality constraint for this one, becoz H fails _co_C = {1 0 0 0 0 0 0, 0 1 0 0 0 0 0, 0 0 1 0 0 0 0, 0 0 0 1 0 0 0, 0 0 0 0 1 0 0, 0 0 0 0 0 1 0, 0 0 0 0 0 0 1}; _co_D = {0, 0, 0, 0, 0, 0, 0}; {b,f,g,retcode} = co(&gmm_C,b_start); print "f=" f; elseif model_ind==5; coset; __output=0; _co_Algorithm=3; _co_LineSearch=1; _co_Trust=1; _co_IneqProc = &ineq_three; _co_DirTol=1e-4; b_start=0.363825|2.119171|0.000465|0.00555|0.287034|0.060095|0.184442|8.106309|0.000205|2.828375|0.000471; _co_C = {1 0 0 0 0 0 0 0 0 0 0, 0 1 0 0 0 0 0 0 0 0 0, 0 0 1 0 0 0 0 0 0 0 0, 0 0 0 1 0 0 0 0 0 0 0, 0 0 0 0 1 0 0 0 0 0 0, 0 0 0 0 0 1 0 0 0 0 0, 0 0 0 0 0 0 1 0 0 0 0, 0 0 0 0 0 0 0 1 0 0 0, 0 0 0 0 0 0 0 0 1 0 0, 0 0 0 0 0 0 0 0 0 1 0, 0 0 0 0 0 0 0 0 0 0 1}; _co_D = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; {b,f,g,retcode} = co(&gmm_CJ,b_start); elseif model_ind==6;//CIR coset; __output=0; _co_Algorithm=3; _co_LineSearch=4; _co_C = { 1 0 0, 0 1 0, 0 0 1}; _co_D = { 0, 0, 0}; _co_IneqProc = &ineq_one; b_start=0.1801|0.05|0.02549; {b,f,g,retcode} = co(&GMM_cir,b_start); endif; retp(b); endp; /*@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ * CS_stat: Calculates The Test Statistics * ***************************************************************************************************************** * Inputs: xt - time series R The first R observations that used for estimation * * tao - a vector indicating the different step ahead con. int. to be examined * * S - number of sample paths to be simulated N - number of sample paths to be simulated for SV * * mod_ind1 - model specification 1 * mod_ind2 - model specification 2 * * h - discretization interval * * u_bar - confidence interval * * Output: * vt - Test statistics will have rows(tao) results * @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@*/ proc (1)= CS_stat(xt,R,N,tao,S,mod_ind1,mod_ind2,h,u_bar,parameter); local T,tt,xp,p_true,b,f,g,retcode,see,vt,p_sim1,p_sim2,i,sup_vt,b1,b2; see=1234;//dont change seed, to use the same random error,but different start value of X(t) T=rows(xt); vt=zeros(rows(tao),1); b1=parameter[6:11,1];// default model is SV, mod_ind1=2; if mod_ind2==1; b2=parameter[1:5,1]; elseif mod_ind2==3; b2=parameter[12:21,1]; elseif mod_ind2==4; b2=parameter[22:28,1]; elseif mod_ind2==5; b2=parameter[29:39,1]; elseif mod_ind2==6; b2=parameter[40:42,1]; endif; i=0; do while i u_bar[1,1]).*(xp .< u_bar[2,1]); p_sim1=Con_den(xt[1:tt,.],tao[i],S,N,mod_ind1,h,u_bar,see,b1);// prob(u1