% To find better solution for GMM.

clear;

% We take first round results from the previous version as the initial seed.
load 'C:\Users\LoweryR\Documents\My Dropbox\UND_research_Banking\Final_files\data_files\theta_GMM1st_initial_KLW.mat';
x_initial = x_1stGMM;
% Note that this is different approach from GMM1st_051013_KLW.m since we don't do grid search.

lb = [0,0,-Inf,-Inf,-Inf,-Inf,-Inf,-Inf,-Inf,-Inf];
ub = Inf*ones(1,10);
options = optimset('TolX',10^-24,'MaxFunEvals',2500,'TolFun',10^-24,'Algorithm','interior-point');
AA = []; b = []; Aeq = []; beq = []; nonlcon = [];
addpath 'C:\Users\LoweryR\Documents\My Dropbox\UND_research_Banking\Final_files\function_files'; % Depending on where you save the function file, you may need this command.
[x_opt,fval_opt,exitflag_opt] = fmincon(@param_obj_KLW,x_initial,AA,b,Aeq,beq,lb,ub,nonlcon,options);

save('C:\Users\LoweryR\Documents\My Dropbox\UND_research_Banking\Final_files\output_files\GMM1st_KLW.mat','x_initial','x_opt','fval_opt','exitflag_opt'); % NOTE: this results can be a little differnt depending on optimization routine.