
clc; clear all; close all

%% This code computes the steady state of a TANK model 
% calibration taken from Gali et al. (JEEA 2007)
% This version: September 5, 2021

%% Structural Parameters (quarterly calibration)
beta=0.99;                    % discount factor
eta=0.12;                     % share of fuel in consumption 
theta = 0.7;
alpha_o=1/3;                  % elasticity of oil production wrt capital
alpha_no=1/3;                 % elasticity of non-oil production wrt capital
eps=6;                        % elasticity of substitution between differentiated goods
delta=0.025;                  % depreciation rate
gamma=1;                      % Inverse of intertemporal elast. of subst. (relative risk aversion)
varpi=0.2;                    % Intra-temporal elasticity of subs. of labor (inverse of Frisch elasticity)
varphi=0.5;                   % fraction of rule-of thumb
G=0.2;                        % public spending over GDP ratio
d=1;                          % public debt over GDP ratio
%% Steady State
P=1;                         % price (agg)
PO=1;                        % oil pice
PNO=1;                       % non-oil price
Infl=1;                      % inflation targeting (agg)
Infl_o=1;                    % oil inflation targeting
Infl_no=1;                   % non-oil inflation targeting
YO=1;               
YNO=1;
Y=YO+YNO;
%Y=1;                        % production (agg)
L=1/3;                       % labor
IR_r=1/beta;                 % real interest rate
IR=Infl/beta;                % nominal interest rate
Lambdaq=1;                   % marginal value of investment (in terms of Lambda)  
Rk=1/beta-(1-delta);          % rental rate of capital
MCO=(eps-1)/eps;             % real marginal costs (oil)
MCNO=(eps-1)/eps;            % real marginal costs (non-oil)
KO=alpha_o*MCO*YO/Rk; 
KNO=alpha_no*MCNO*YNO/Rk;
K=KO+KNO;
WR=(1-alpha_o)*MCO*YO/L; 
WNR=(1-alpha_no)*MCNO*YNO/L;
%W=(1-varphi)*WR +varphi*WNR; 
W=WR+WNR;
IO=delta*KO;
INO=delta*KNO;
I=IO+INO;
C=Y-I-G;                     % consumption
CO=eta*C;
CNO=(1-eta)*C;
Tau_NR=W*L-C;                % non ricardians taxes
D=4*d;                       % public debt
Tau_R=(G+(1/beta-1)*D-varphi*Tau_NR)/(1-varphi); % ricardans taxes
Lambda=C^(-gamma);           % marginal utlity of consumption
AO=YO/(KO^(alpha_o)*L^(1-alpha_o)); % production/productivity fuction (oil)
ANO=YNO/(KNO^(alpha_no)*L^(1-alpha_no)); % production/productivity fuction (non-oil)
psi=W/(L^(varpi)*C^(gamma)); % disutility of labor supply
%% Steady-state values
Gss=G;
AOss=AO;
ANOss=ANO;
Inflss=Infl;
IRss=IR;
Tau_Rss=Tau_R;
Tau_NRss=Tau_NR;
Dss=D;

%% Parameters not affecting the steady state
rho_Infl=1.5;             % monetary polcy response on policy rate (inflation)
rho_Infl_O=1.5;
rho_Infl_NO=1.5;
rho_y=0.0;                % monetary polcy response on output gap
chi=2.48;                 % investment adjustment cost (as in CEE). If 0, Lambdaq is constant
rhoAO=0.9;                % tfp persistence (oil)
rhoANO=0.9;               % tfp persistence (non-oil)
rhoG=0.9;                 % public spending persistence
rhoM=0.0;                 % monetary policy inertia
phiG=0.1;                 % tax reaction to G
phiD=0.33;                % tax reaction to debt
calvo=0.75;               % price rigidity in calvo framework
% adjusment cost coefficient to have the same linear Phillips Curve of the Calvo framework 
chip=(eps-1)*calvo/(Inflss^2*(1-calvo)*(1-beta*calvo)); 

%% Save parameters
save par beta alpha_o alpha_no delta gamma varpi Gss theta AOss ANOss eta psi Inflss IRss eps varphi...
         rho_Infl rho_Infl_O rho_Infl_NO rho_y chi rhoAO rhoANO rhoG rhoM chip phiG phiD Tau_Rss Tau_NRss Dss
     

