
clc; clear all; close all

%% This code computes the steady state of a TANK model 
% Most calibration taken from Gali et al. (JEEA 2007)
% This version: Feb 12, 2022

%% Structural Parameters (quarterly calibration)
beta=0.99;                    % discount factor
eta=0.03;                     % share of fuel in consumption 
theta = 0.18;                  % intertemporal elasticity of substitution between oil and non oil goods
alpha_o=1/3;                  % elasticity of oil production wrt capital
alpha_no=1/3;                 % elasticity of non-oil production wrt capital
eps=8;                       % elasticity of substitution between differentiated goods
epsl=8;
delta=0.025;                  % depreciation rate
gamma=0.95;                      % 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.7;                   % fraction of rule-of thumb
G=0.2;                        % public spending over GDP ratio
d=1;                          % public debt over GDP ratio
thetap=0.82;                  % NK baseline
thetaw=0.65;
mu=0.5;                         % indexation
eps2=1;                       % capacity utilization parameter 2
eps1=1/beta-(1-delta)*eps2;   % capacity utilization parameter 1
omega=0.05;                   % scale of subsidies

phiV=0.005;                   % risk premium parameter
phiS=0.005;                   % UIP risk premium

%% Steady State
Infl=1;                      % inflation targeting (agg)
YO=1;                        % oil production
YNO=1;                       % non-oil production
Y=YO+YNO;                    % production (aggregate)
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;        % capital (oil)
KNO=alpha_no*MCNO*YNO/Rk;    % capital (non-oil)
K=KO+KNO;                    % capital (agg)
WR=(1-alpha_o)*MCO*YO/L;     % wage of ricardian
WNR=(1-alpha_no)*MCNO*YNO/L; % wage of non-ricardian
I=delta*K;                   % investment (agg) 
C=Y-I-G;                     % consumption
Css=C;
Tau_NR=WNR*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 function (oil)
ANO=YNO/(KNO^(alpha_no)*L^(1-alpha_no)); % production/productivity function (non-oil)
M=1;                          % monetary policy shock
Bstar=1;
psi=WNR/(L^(varpi)*C^(gamma)); % disutility of labor supply

WelfRss=((1/(1-gamma))*C^(1-gamma)-psi*L^(1+varpi)/(1+varpi))/(1-beta);
WelfNRss=((1/(1-gamma))*C^(1-gamma)-psi*L^(1+varpi)/(1+varpi))/(1-beta);
Welfss=(1-varphi)*WelfRss+varphi*WelfNRss;
%% Steady-state and exogenous values
Gss=G;
Mss=M;
Bstarss=Bstar;
AOss=AO;
ANOss=ANO;
Inflss=1;
Infl_NOss=1;
IRss=IR;
Tau_Rss=Tau_R;
Tau_NRss=Tau_NR;
Dss=D;
IRexo=1/(beta*exp(1));
Pexo=1;
POss=1;
POstarss=1;
Zphiss=1;

%% Parameters not affecting the steady state
%rho_Infl=1.5;             % monetary polcy response on policy rate (inflation)
rho_Infl_O=1.5;           % monetary polcy response on policy rate (oil inflation)
rho_Infl_s=1.5;          % monetary polcy response on policy rate (subsidized inflation)
%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.9;                 % monetary policy inertia
phiG=0.1;                 % tax reaction to G
phiD=0.33;                % tax reaction to debt
rhophi=0.8;
rhoPOstar=0.6;
chip=10;
psiB=0.00074;
rhoIRstar=0.9;


%% Save parameters
save par beta eps1 eps2 epsl alpha_o alpha_no delta gamma varpi Gss thetap thetaw mu omega theta AOss ANOss Mss eta psi Inflss Infl_NOss IRss eps varphi...
        chip  rho_Infl_O rho_Infl_s  chi rhoAO rhoANO rhoG rhoM phiG phiD Tau_Rss Tau_NRss Dss...
        rhoIRstar Pexo rhophi rhoPOstar psiB phiS phiV IRexo POss Zphiss Bstarss...
         Css WelfRss WelfRss WelfRss
         % rho_Infl rho_y
     

