% Basic SMOE Model with Monopolistic Competion. 


%----------------------------------------------------------------


% 0. Housekeeping


%----------------------------------------------------------------





close all





%----------------------------------------------------------------


% 1. Defining variables


%----------------------------------------------------------------


var ygap, ynhat, yhat, yfhat, e, i, s, ph, pih, pi, rn, pf, pif, a;

varexo eps_a, eps_pif, eps_yf; 


parameters alpha, beta, rho, phi, gamma, theta, eta, omega, rho_yf, rho_pif, rho_a,  
sigma, sigma_a, lambda, phi_pi, phi_y;



%----------------------------------------------------------------


% 2. Calibration


%----------------------------------------------------------------


% Degree of openness
alpha = 0.4;
 
% Time preference
beta  = 0.99;
 
% Subjective discount rate
rho   = -log(beta);
 
% Inverse of labor supply elasticity
phi   = 3;
 
% Substitutability between good produced in different foreign countries, from viewpoint of domestic consumer
gamma = 1;
 
% Price stickiness
theta   = 0.75;
 
% The substitutability between domestic and foreign goods from the viewpoint %of the domestic consumer
 
eta=1;
 
% Measures the wealth effect of labor supply, sigma<1 the substitution effect % on LS from a higher real wage dominates and leads to higher employment
% when sigma>1 the converse is true, a higher real wage gives a smaller %marginal utility of consumption and employment is lowered
% when sigma=1 the utility of consumption is logarithmic and the effects %cancel each other out

sigma   = 1;
 
%definition
omega=sigma*gamma+(1-alpha)*(sigma*eta-1);
 
% Sensitivity of aggregate demand to the relative producer price (terms of trade)
 
sigma_a = sigma/((1-alpha)+alpha*omega);

%definition
lambda = ((1-beta*theta)*(1-theta))/theta;
 
% Persistence parameters for AR-processes
rho_yf    = 0.8;
rho_pif   = 0.8;
rho_a     = 0.9;
 
% Weights for Taylor rule
phi_pi  = 1.5;
phi_y   = 0.5;
 

%----------------------------------------------------------------


% 3. Model


%----------------------------------------------------------------

model;
 
% Exogenous shocks in AR(1)
 
yfhat=rho_yf*yfhat(-1)+eps_yf;
pif=rho_pif*pif(-1)+eps_pif;
a=rho_a*a(-1)+eps_a;
 
% DIS 
ygap=ygap(+1)-(1/sigma_a)*(i-pih(+1)-rn);
 
% NKPC 
pih=beta*pih(+1)+lambda*(sigma_a+phi)*ygap;

pi=pih+alpha*s-alpha*s(-1);
 
% Taylor rule CITR
%i=rho+phi_pi*pi+phi_y*ygap;

% Taylor rule DITR
i=rho+phi_pi*pih+phi_y*ygap;
 
%Natural interest rate
rn=rho-(sigma_a*(1+phi)/(sigma_a+phi))*(1-rho_a)*a
+((sigma_a*phi)/(sigma_a+phi))*((sigma_a/sigma)-1)*yfhat(+1)
-((sigma_a*phi)/(sigma_a+phi))*((sigma_a/sigma)-1)*yfhat;
 
%Natural output
ynhat=((1+phi)/(sigma_a+phi))*a-((sigma-sigma_a)/(sigma_a+phi))*yfhat;
yhat=ynhat+ygap;
 
 
%nominal effective exchange rate as a function of ToT
%and the relative price between foreign and domestic compostie goods
%as in gali eq (16) page 156
e=s-pf+ph;

%If the CB wants to defend a peg set e=0 and shut down the TR, the fixed
%exchange rate is the monetary policy objective to the CB
%e=0;
 
% terms of trade gali (29)
s=sigma_a*(yhat-yfhat);
 
%price levels ad hoc
ph=pih+ph(-1);

pf=pif+pf(-1);
 
end;
%----------------------------------------------------------------


% 4. Computation


%----------------------------------------------------------------




initval;
ynhat   = 0;
yhat    = 0;
ygap    = 0;
i       = 0.010053;
pih     = 0;
pif     = 0;
pi      = 0;
ph      = 0;
pf      = 0;
yfhat   = 0;
a       = 0;
e       = 0;
rn      = 0.010053;
s       = 0;

end;

shocks;

var eps_yf=1;
var eps_a=1;
var eps_pif=1;
 
end;

steady;

set_dynare_seed=7;

%See manual p 29 section 3.8 for complete list of commands in stoch_simul
stoch_simul(periods=1000,irf=0);
datatomfile('simuldataSMOE',[]);
return;


