clear all
close all
clc

% set parameters
beta = 0.993;
kappa = 1-40^(-1);
%spF = 0.03;
psi = 0.6;
epsp = 11;
epsw = 11;
alpha = 1/4;
delta0 = 0.05;
delta2 = 0.03; % squared term capital adjustment cost
g = 0.2;
bb = 0.7; 
sigma = 0.9;
psid = 1.2;

upse = 0.96;
upsc = 0.96;
v = 0.96;
Delta = 1;
etap = 1.1;
m=0.2;
deltaT = 0.04;

% parameters unrelated to steady state
phip = 0;
phiw = 0;
psik = 3; % capital adjustment cost
eta = 1; % Frisch elasticity

% Taylor rule
rhor = 0.6;
phipi = 1.5;
phiy = 0.25;
sr = 0.025;

% Shock processes
rhof = 0.97;
sf = 0.01;
rhoA = 0.9;
sA = 0.01;
rhot = 0.95;
st = 0.01;
indp = 0.3;
indw = 0.3;



% solve for steady state
Rds = beta^(-1);
Rdes = beta^(-1);
Rdcs = beta^(-1);


Rvs = Rdcs;
Rves = Rvs + Rdcs*(psid-1);

Rfs = Rdcs;
Rfcs = Rdcs;
Rfes = Rves/psid;
Rtrs = Rds;

Qs = (Rfs - kappa)^(-1);
M1s = beta/(Qs*(1-beta*kappa));
M2s = 1 + (M1s-1)*psi;
pws = (epsp-1)/epsp;
Ks = (alpha*pws/(M2s*(1/beta - (1-delta0))))^(1/(1-alpha));
Ys = Ks^(alpha);
Is = delta0*Ks;
Gs = g*Ys;
ws = (1-alpha)*pws*Ks^(alpha);
delta1 = (alpha*pws*Ks^(alpha-1)/M2s);

fcbs = 0; 
fws = psi*Is/(Qs*(1-kappa));
mrss = ((epsw-1)/epsw)*ws;
fs = fws - fcbs;
Pes=1;
rers = ((2*v-1)/(1-v)*(v/(2*v-1)-Pes^(1-etap)))^(1/(1-etap));
Pcs = (v/(2*v-1)-((1-v)/(2*v-1))*rers^(etap-1))^(1/(1-etap));

alphas = 1;
alphaes = alphas;
alphacs = alphas;

Omegas = 1;
Omegaes = Omegas;
Omegacs = Omegas;

ns = deltaT*Qs*fs/(1-sigma*Rds);
Vs = (Qs*fs-ns)/(psid*rers);
dcs = Qs*fs +(m/(1-m))*Vs -ns;
ncs = ns;
nes = ns;

syms Ccs Ces;
eqns2 = [Ys==v*(Ces+Is+Gs)+(1-v)*(1-m)/m*(Ccs+Is+Gs),...
         Ys==(1-v)*m/(1-m)*(Ces+Is+Gs)+v*(Ccs+Is+Gs)];
S2 = solve(eqns2,[Ccs Ces]);
Ccs = double(S2.Ccs);
Ces = double(S2.Ces);
     
des = (psid-1)*rers*Vs;
bes = (Ces - mrss - (Rds-1)*des + deltaT*Qs*fs)/((Rds-1)*rers);

mues = (1/Ces)*(1-beta*bb)/(1-bb);
mucs = (1/Ccs)*(1-beta*bb)/(1-bb);

chie = mues*mrss;
chic = mucs*mrss;


save param_sw beta kappa psi epsp epsw alpha delta0 delta1 delta2 g bb sigma psid...
     upse upsc v Delta deltaT etap m phip phiw psik eta rhor phipi phiy sr...
     rhof sf rhoA sA rhot st indp indw ...
     Rds Rfs Rvs Rves Rtrs Qs M1s M2s pws Ks Ys Is Gs ws fws fcbs mrss fs...
     Pes nes Omegaes alphaes rers Pcs Vs ncs dcs des...
     Omegacs alphacs Ccs Ces mues mucs chie chic

%%
dynare tomeme_frictionless.mod