clear var_share;
horizon=[1 4 8 12 30];

%get the std of shocks;
%load result_aug7th;
dr=oo_.dr;
num_var=length(dr.ys);
bigV=zeros(size(shock,2));

[yy,k2] = simult_jh(zeros(num_var,1),oo_.dr,shock,1);

bigA=zeros(num_var);
bigA(:,k2)=dr.ghx;
bigB      =dr.ghu;

for iter=1:size(shock,2);

name=['oo_.posterior_mode.shocks_std.' shocknames(iter,:)];       
        bigV(iter,iter)=eval(name)^2;
end;
bigkron=inv(kron(eye(num_var),eye(num_var))-kron(bigA,bigA));
stackB=(bigB*bigV*bigB');
vec_tmp0all=bigkron*stackB(:);
tmp0all=reshape(vec_tmp0all,num_var,num_var);
for iter=1:size(shock,2);
name=['oo_.posterior_mode.shocks_std.' shocknames(iter,:)];  
bigV1=zeros(size(shock,2));
 bigV1(iter,iter)=eval(name)^2;
for iter0=1:length(horizon)
    tmp0=zeros(num_var);tmp1=zeros(num_var);
    
    for step=1:horizon(iter0)
        tmp0=tmp0+(bigA)^(step-1)*bigB*bigV*((bigA)^(step-1)*bigB)';
        tmp1=tmp1+(bigA)^(step-1)*bigB*bigV1*((bigA)^(step-1)*bigB)';
    end
    var_share(:,iter0,iter)=diag(tmp1)./diag(tmp0).*100;
    
end;
stackB1=(bigB*bigV1*bigB');
vec_tmp1all=bigkron*stackB1(:);
tmp1all=reshape(vec_tmp1all,num_var,num_var);
var_share(:,length(horizon)+1,iter)=diag(tmp1all)./diag(tmp0all).*100;
end;
share_pick=var_share(pickvar,:,:);
