function [obj] = Objfn(theta,targetMom,shockMat,dyn)

global oo_ M_ options_ % Dynare structures to be pass to resol.m

%setting the parameters
set_param_value('BETTA',theta(1)); 
set_param_value('GAM',theta(2)); 

[oo_.dr,info,M_,options_,oo_] = resol(0,M_,options_,oo_); %run model solution in Dynare
ystart = oo_.dr.ys(oo_.dr.order_var,1);
ss = ystart;

[err, y_] = dynare_simul_(3, M_.nstatic,M_.npred,M_.nboth,M_.nfwrd,M_.exo_nbr, ...
                          ystart,shockMat,M_.Sigma_e,options_.DynareRandomStreams.seed,ss, ...
                          oo_.dr.g_0, oo_.dr.g_1, oo_.dr.g_2, oo_.dr.g_3);

% this is just for demonstration purpose
obj = y_';%theta*theta';
end 