Close all
var  cs hs ns r ws q cb hb nb b wb k y pi ws wb Ws Wb W; % I appear to b missing an equation for ns and nb (working hours), which wasnt specified in the paper, unsure whether it is a parameter or variable in any case.
varexo u_t epsilon;

parameters  betas betab j eta k alpha X theta rhoa rhoj rho phi_y phi_pi phi_b psi;

        betas = 0.99; %Discount factor for savers
        betab = 0.98; %Discount factor for borrowers
        j = 0.1; %Weight of housing in utility function
        eta = 2.0; %Parameter associated with labor elasticity 
        k  = 0.9; %loan-to-value ratio
        alpha  = 0.64; %Labor share for savers
        X = 1.2; %Steady-state markup
        theta   = 0.75; %Probability of not changing prices
        rhoa = 0.9; %Technology persistence 
        rhoj = 0.95; %Housing demand shock persistence
        rho = 0.8; %Interest-Rate-Smoothing Parameter in Taylor Rule
        phi_y = 0.5;%May be wrong, double check
        phi_pi = 0.3;%May be wrong, double check, I have used the coordinated value
        phi_b = 0.8; % May be wrong, my intuition is that we test benchmark vs coordinated and non coordinated.
        psi = 0.1; %May be wrong, double check. Or is it psi=((1-theta)*(1-((betab+betas)/2)*theta)/theta) as in text
        F = 0; %F is lump sum transfers, not sure what the equation or value should be
        Lambda = 0.5; % Multiplier on the borrowing constraint. Unsure what to set lambda as as could not find a value for it in the paper.
model;

%Savers
1/cs = 1/betas*(r/(pi(+1)*cs(+1)));%1
ws = (ns^(eta-1))*cs;%2
j/hs = (1/cs)*q-(betas*(1/cs(+1))*q(+1));%3
%budget constraint savers
cs = (r(-1)*b(-1)/pi)+(ws)*(ns)+f-b-q*(hs-hs(-1)); %4 This doesn't appear in the main equations section.

%borrowers 
%budget constraint and collateral constraint
cb = q*hb(-1)+wb*nb+b-q*hb-(r(-1)*b(-1))/pi; %5
b = (k*q(+1)*hb)/(r/pi(+1)); %6
1/cb = betab*(r/(pi(+1)*cb(+1)))+lambda*r; %7
wb = nb^(eta-1)*cb; %8
j/hb = (1/cb)*q-(betab*(1/cb(+1))*q(+1))-lambda*k*q(+1)*pi(+1);%9 On main equations it is shown as lambda b, why?

ws = (1/X)*alpha*(y/ns);
wb = (1/X)*(1-alpha)*(y/nb);

%Define pi
pi = ((betab+betas)/2)*(pi(+1))-psi*x+u_t;%May be wrong as unsure how psi is obtained.

%Monetary Policy
r = (r(-1)^rho)*((((pi)^(1+phi_pi))*((y/y(-1))^(phi_y))*r)^(1-rho))*epsilon;  %10

%Define Ws and Wb
%Welfare
Ws = (betas*(log(cs)+j*log(hs)-(ns^eta/eta))); %11 May be wrong, could be ns^rta+m as it differes in the main equations section
Wb = (betab*(log(cb)+j*log(hb)-(nb^eta/eta))); %12 May be wrong, could be nb^rta+m as it differes in the main equations section
W = (1-betas)*Ws+(1-betab)*Wb;

%market clearing condition
y=cs+cb; % 16
% ltv ratio
k = kss*(b/b(-1))^phi_b; %17
%housing supply
hs+hb = 1; %18

end;

initval; 
k=0.6; %ltv ratio
cs = 2.75;% cons level savers
r=1.02532; %interest rate, unsure if I should give r a starting value as Matlab states that r it may not be used when I do give it a starting value.
X=1.2214; %markup/ inverse of marginal cost
ns =6; % working hours savers
hs = 4; %housing stock savers
q =6; % price of housing in units of consumption
b=1.2; % bank loans
cb=1.8; %consumption borrowers
hb=6.5; %housing stock borrowers
wb=0.7; %wage rate borrowers
ws=0.7; %wage rate for savers
nb=5; %working hours borrowers
Wb=1.2; %individual welfare borrowers
Ws=1.5; %individual welfare saves
pi=1.3; %price level
y=4.55; %output

 
end; 
steady;

shocks;

var epsilon= sigma^2;
var u_t = sigma^2;
end; 