

%----------------------------------------------------------------
% 0. Housekeeping
%----------------------------------------------------------------

close all;

%----------------------------------------------------------------
% 1. Defining variables
%----------------------------------------------------------------

var b c  xhh xfh xhf  x p w ca tauh tauf realw  ;
varexo e1 e2;

// same warning concerning beta and gamma
parameters beta phi  phif r wl wfh whh   A  omega rho sigma  bbar Psi l;

%----------------------------------------------------------------
% 2. Calibration
%----------------------------------------------------------------

beta    =  0.96;
r       =  1/beta-1;
phi     =  0.25;
phif    =  0.25;
wl      =  0.5;
wfh     =  0.25;
whh     =  1-wl-wfh;
A       =  1;
B       =  1;
omega   =  1;
rho     =  0.1;  
sigma   =  0.008;
bbar    =  0;
Psi     =  0.00072;
l       =1        ;


%----------------------------------------------------------------
% 3. Model   
%----------------------------------------------------------------

model; 
  1/(p*c)*(1+Psi*(b-bbar)) = beta*(1+r)/(p(+1)*c(+1));   % Forward-looking Euler from HH problem
   %w/c/p=l ;                                          % Labor-leisure trade-off
  xhh=whh^(1/(1-phi))*x;                               % Domestic intermediate demand
  xfh=wfh^(1/(1-phi))*exp(tauh)^(phi/(1-phi))*p^(1/(1-phi))*x; % Domestic foreign intermediates demand
  l=(p/w)^(1/(1-phi))*wl^(1/(1-phi))*x;                % Domestic labor demand
  (wl*l^phi+whh*xhh^phi+wfh*(xfh*exp(tauh))^phi)^(1/phi) = xhf + xhh + c;  % Market clearing for domestic goods
  p=A*(exp(tauf))^phif*xhf^(phif-1);   % Foreign intermediate good demand
  ca=(b-b(-1))/(p*x-p*xhh-xfh); % Determination of CA
  p*c+b+Psi/2*(b-bbar)^2=(1+r)*b(-1)+w*l; % HH BC
  x = (wl*l^phi+whh*xhh^phi+wfh*(xfh*exp(tauh))^phi)^(1/phi); % Production
  tauf = rho*tauf(-1)+e2; % Foreign efficiency of using imported intermediaries
  tauh = rho*tauh(-1)+e1; % Domestic efficiency of using imported intermediaries
  realw = w/p;
end;



%----------------------------------------------------------------
% 4. Computation
%----------------------------------------------------------------
 
initval;
 b =   1/Psi*(beta*(1+r)-1)+bbar ;
 c =   0.5;
 xhh  =0.5;
 xfh  =0.5;
 xhf  =0.5;
 x    =0.5;
 p    = 4;
 w    =1;
 ca   =0; 
 tauh=0; 
 tauf=0;
 realw=0.3;
 %l=0.8;
end;

shocks;
var e1 = sigma^2;
var e2 = sigma^2;
end;

steady(maxit=100000);

stoch_simul(periods=400, irf=20, order=2);





