clc; clear all;
addpath('C:\dynare\6.5\matlab')


if ~isdir('Latex/Efficient')
    mkdir('Latex/Efficient')
end

%==========================================================================
% Main Parameters
%==========================================================================
BBETA      = 0.99; % 0.995
RSTRSTSS   = 1/BBETA;
GGAMMAC    = 1; %(Above 1 - 1.4 with current paramterization explodes in NK) CO:1
GGAMMA     = 0.6;  %Between 0 and  3 homebias
CCHI       = 3; %1.5; 
GGAMMAD    = GGAMMAC;
EPS        = 6;%3.8; % ELasticity of substitution over varieties.
GGAMMAST   = GGAMMA;
MMBAR      = 1;
OOMEGA     = 500;
SSIGMA     = 1;
EPSH       = 1; % (1-3) CO:1
EPSF       = 1; % (1-3) CO:1
MMU        = 1.1;
TAUH       = (EPS*GGAMMA - EPS + 1)/(EPS*GGAMMA);
TAUH_W      = 0;
TAUH_P      = 0;
TTHETAH     = 0.75;
%TTHETAF     = 0;
RRHOI      = 0;
RHOA       = 0.74;
RHOZ       = 0.6;
RHOBCS     = 0;
RHONST     = 0;
OPT        = 0;
FXIR       = 0;
STD_PSI    = 0.01; %SWITCH
STD_A      = 0.0064;
STD_C      = 0.0001;
STD_Z      = 0.0289;
B0=0;
B1=0;
B2=0;
B3=0;
PHI_PIH    = 2.78;
PHI_PIH_2    = 2.78;
PHI_Y = 0.5;
PHI_G   = 0;
FXIR=0;
EPSW= 6; %4.3; % ELasticity of substitution over varieties LABOR
PPSI=1;
TTHETAHW = 0.75;

	lambda_w = ((1-TTHETAHW)/TTHETAHW)*(1-BBETA*TTHETAHW)/(1+CCHI*EPSW);
	lambda = ((1-BBETA*TTHETAH)*(1-TTHETAH))/TTHETAH;
save PARAM_M1 BBETA GGAMMA CCHI EPS EPSH EPSF GGAMMAST MMBAR OOMEGA SSIGMA EPSW RHOA PPSI TTHETAHW RHONST STD_PSI STD_A STD_Z TAUH_P TAUH_W FXIR GGAMMAC TTHETAH PHI_PIH;

Ramsey      = 0;  %do not do Ramsey, not implemented (Needs to write trend depreciation model)
osr         = 1;  %do all optimal rules
logutility  = 1;
dixit       = 0;
OSR_OC_FLEX = zeros(4,1);
OSR_CES_FLEX = zeros(4,1); 
OSR_DS_FLEX = zeros(4,1);
OSR_DSCES_FLEX = zeros(4,1);
OSR_OC_STICKY = zeros(4,1);
OSR_CES_STICKY = zeros(4,1); 
OSR_DS_STICKY = zeros(4,1);
OSR_DSCES_STICKY = zeros(4,1);
results_opt_rule_F = zeros(3,1);
results_opt_rule_S = zeros(3,1);
results_OC_TAYLOR = zeros(12,1);

results_OSR_TAYLOR = zeros(7,8);
results_adhoc = zeros(7,8);
results_bank = zeros(7,8);

%% Simulation

PHI_PIH    = 2.78;
%PHI_PIH_2    = 2.78;
save PARAM_M1 BBETA GGAMMA CCHI EPS EPSH EPSF GGAMMAST MMBAR OOMEGA SSIGMA EPSW RHOA PPSI TTHETAHW RHONST STD_PSI STD_A STD_Z TAUH_P TAUH_W FXIR GGAMMAC TTHETAH PHI_PIH PHI_PIH_2;
dynare nk_wr -DCalvo=1 -Dlogutility=1 -Dosr=1 -Dramsey_policy=0 -Ddixit=0 -DtaylorPPI=1 -DtaylorCPI=0  -DRez=0 -DXgap=1 -Dsubsidy=1
pause(1);
PHI_PIH = x_opt_hat(1);
save PARAM_M1 BBETA GGAMMA CCHI EPS EPSH EPSF GGAMMAST MMBAR OOMEGA SSIGMA EPSW RHOA PPSI TTHETAHW RHONST STD_PSI STD_A STD_Z TAUH_P TAUH_W FXIR GGAMMAC TTHETAH PHI_PIH PHI_PIH_2;
dynare nk_wr -DCalvo=1 -Dlogutility=1 -Dosr=1 -Dramsey_policy=0 -Ddixit=0 -DtaylorPPI=1 -DtaylorCPI=0   -DRez=0 -DXgap=1 -Dsubsidy=1
save OC_TAYLOR0 oo_ M_;
results_OC_TAYLOR(1:9,1)= 100*values_all;
results_OC_TAYLOR(10,1)= (values_all(7)^2 + 0.25*values_all(4)^2)*100;
results_OC_TAYLOR(11,1)= PHI_PIH;
results_OC_TAYLOR(12,1)= (GGAMMA/2)*((1+CCHI)*values_all(4)^2 + (EPS/lambda)*values_all(7)^2 + (TTHETAHW/lambda_w)*values_all(6)^2)*100;
