clear; clc; close all;
cd('/Users/julioortiz/Dropbox/ME/replication/code/Appendix_D');

%Set up parameters and shocks
param(1) = 2.556;
param(2) = 0.434;
param(3) = -0.006;
param(4) = 1.663;  
param(5) = 1.5304;

Nsim = 2000;
N = 100;
T = 115;
burn = 1000;

shocks.v=randn(Nsim,N,T+burn);
shocks.w=randn(Nsim,1,T+burn);

%RE
[moments_RE, moments_sd_RE,disagree_RE,K_RE] = simulated_moments_RE(param,N,T,burn,Nsim,shocks);

%OC
param(6) = 0.7224;
[moments_OC, moments_sd_OC,disagree_OC,K_OC] = simulated_moments_OC(param,N,T,burn,Nsim,shocks);
     
%DE
param(6) = 0.2328;
[moments_DE, moments_sd_DE,disagree_DE,K_DE] = simulated_moments_DE(param,N,T,burn,Nsim,shocks);

%ME
param(6) = 0.5641;
[moments_ME, moments_sd_ME,disagree_ME,K_ME] = simulated_moments_ME(param,N,T,burn,Nsim,shocks);

simmom_RE=[moments_RE; moments_sd_RE];
simmom_OC=[moments_OC; moments_sd_OC];
simmom_DE=[moments_DE; moments_sd_DE];
simmom_ME=[moments_ME; moments_sd_ME];

BGMS = [simmom_RE(:,1) simmom_OC(:,1) simmom_DE(:,1) simmom_ME(:,1)];
CG   = [simmom_RE(:,2) simmom_OC(:,2) simmom_DE(:,2) simmom_ME(:,2)];
K    = [K_RE K_OC K_DE K_ME];
disagree = [disagree_RE disagree_OC disagree_DE disagree_ME];

updating_rules = [simmom_RE(:,3:5) simmom_OC(:,3:5) simmom_DE(:,3:5) simmom_ME(:,3:5)];

save('simulation_results.mat','BGMS','CG','K','disagree','updating_rules');
