to:雁茗轩
请务必参考page 17-18/29
Monte Carlo techniques for computation of GI step1-7
同时执行79楼程序,才容易理解.
##########
N=60 #the maximum horizon
R=1000 #the number of replications
noh:112 #no. of histories
1. Pick a history and shock, W(t-1),v(t),by some combination of..
2. For a given horizon N, randomly sample (N + 1)x R values
of the (Kdimensional)innovation
#generate standardized shocks from lstar model
st_shock_idx=sample(seq(1:length(std_res)),R*(N+1),replace = TRUE)
length(st_shock_idx)
st_shock=matrix(std_res[st_shock_idx],R,N+1)
dim(st_shock) # 1000 x 61
shockz=st_shock*sd_res
3. Use the first N random shocks (obtained under step 2) to
compute the realization.....
4. Use the same draw of N random shocks plus one additional
draw of the random shock to produce a realization...
5. Repeat steps 3 and 4 R times and form the averages...
###
for(i in 1:noh){
hist=hist_m[i,];
# benchmark profile
.....
.....
######compute "new" histories
histv=cbind(1,y,histv[,2],y,histv[,2])
realvb[k]=mean(histv[,4]);
} #end k shock profile
6. Take the difference between the two averages to form a
Monte Carlo estimate of the GI,
GI[i,]=realvb-realzb;
}# end i numbers of histories