
clc; clear all; close all %#ok<CLALL> 

%% 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)
betta=0.99;                    % discount factor
etta=0.03;                     % share of fuel in consumption 
thetta = 0.18;                 % intertemporal elasticity of substitution between oil and non oil goods
alppha_o=1/3;                  % elasticity of oil production wrt capital
alppha_no=1/3;                 % elasticity of non-oil production wrt capital
eps=8;                        % elasticity of substitution between differentiated goods
epsl=8;
deltta=0.025;                  % depreciation rate
gama=0.95;                   % Inverse of intertemporal elast. of subst. (relative risk aversion)
varppi=0.2;                    % Intra-temporal elasticity of subs. of labor (inverse of Frisch elasticity)
varphi=0.3;                   % fraction of rule-of thumb
G=0.2;                        % public spending over GDP ratio
d=1;                          % public debt over GDP ratio
thettap=0.82;                  % NK baseline
thettaw=0.65;
mu=0.5;                       % indexation
eps2=1;                       % capacity utilization parameter 2
eps1=1/betta-(1-deltta)*eps2;   % capacity utilization parameter 1
omegga=0.02;                   % 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/betta;                 % real interest rate
IR=Infl/betta;                % nominal interest rate
Lambdaq=1;                   % marginal value of investment (in terms of Lambda)  
Rk=1/betta-(1-deltta);         % rental rate of capital
MCO=(eps-1)/eps;             % real marginal costs (oil)
MCNO=(eps-1)/eps;            % real marginal costs (non-oil)
KO=alppha_o*MCO*YO/Rk;        % capital (oil)
KNO=alppha_no*MCNO*YNO/Rk;    % capital (non-oil)
K=KO+KNO;                    % capital (agg)
WR=(1-alppha_o)*MCO*YO/L;     % wage of ricardian
WNR=(1-alppha_no)*MCNO*YNO/L; % wage of non-ricardian
I=deltta*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/betta-1)*D-varphi*Tau_NR)/(1-varphi); % ricardans taxes
Lambda=C^(-gama);           % marginal utlity of consumption
AO=YO/(KO^(alppha_o)*L^(1-alppha_o)); % production/productivity function (oil)
ANO=YNO/(KNO^(alppha_no)*L^(1-alppha_no)); % production/productivity function (non-oil)
M=1;                          % monettary policy shock
Bstar=1;
psi=WNR/(L^(varppi)*C^(gama)); % disutility of labor supply

WelfRss=((1/(1-gama))*C^(1-gama)-psi*L^(1+varppi)/(1+varppi))/(1-betta);
WelfNRss=((1/(1-gama))*C^(1-gama)-psi*L^(1+varppi)/(1+varppi))/(1-betta);
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/(betta*exp(1));
Pexo=1;
POss=1;
POstarss=1;
Zphiss=1;
sigOstarss=0.0026; % SS volatility of oil shockk
sig_sigOstarss=0.0025; % SS volatility of uncertianty shock

%% Parameters not affecting the steady state
rho_Infl=1.5;             % monettary polcy response on policy rate (inflation)
rho_Infl_NO=1.5;           % monettary polcy response on policy rate (oil inflation)
rho_Infl_s=1.5;          % monettary polcy response on policy rate (subsidized inflation)
rho_y=0.0;                % monettary 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;                 % monettary policy inertia
phiG=0.1;                 % tax reaction to G
phiD=0.33;                % tax reaction to debt
rhophi=0.8;
rhoir=0.8;                
rhoPOstar=0.9;            % oil chock persistency
rhosOstar=0.7;            % oil uncertainty persistency
chip=10;
psiB=0.00074;


%% Save parameters
save par betta eps1 eps2 epsl alppha_o alppha_no deltta gama varppi Gss thettap thettaw mu omegga thetta AOss ANOss Mss etta psi Inflss Infl_NOss IRss eps varphi...
        chip  rho_Infl_NO rho_Infl_s  chi rhoAO rhoANO rhoG rhoM phiG phiD Tau_Rss Tau_NRss Dss...
         Pexo rhophi rhoPOstar psiB phiS phiV IRexo POss Zphiss Bstarss...
        Css WelfRss WelfRss WelfRss...
        sigOstarss sig_sigOstarss rhosOstar rho_Infl rho_y
     

