var c_s r w_s x y n_s h_s q b c_b h_b w_b n_b k W_b W_s W pi z m d g f i s v t;
parameters  beta_s beta_b jot alpha lambda psi eta phi_pi phi_y phi_q k_ss rho sigma;

varexo u_t epsilon_r;

beta_s = 0.99;
beta_b = 0.98;
jot =0.1;
eta = 2;
psi = 0.1;
alpha = 0.64;
rho = 0.8;
phi_y= 0;
phi_q= 0;
phi_pi = 0.5;
omega_y = 0.05;
omega_q = 0.05;
k_ss = 0.6;
lambda= 0.5;
sigma = 0.010301;

model;
%savers
1/c_s = beta_s*z; %1
w_s = (1/x)*alpha*(y/n_s); %2
jot/h_s = (1/c_s)*q-beta_s*m; %3

%budget constraint savers
c_s+b+q*(h_s-h_s(-1))=r(-1)*b(-1)/pi+w_s*n_s; %4

%budget constraint borrowers and collateral constraint
c_b+(r(-1)*b(-1))/pi + q*(h_b-h_b(-1)) = b+w_b*n_b; %5
s=k*i; %6
%borrowers
1/c_b = beta_b*d+lambda*r; %7
w_b = (1/x)*(1-alpha)*(y/n_b); %8
jot/h_b = (1/c_b)*q-beta_b*f-lambda*k*g; %9

%keine Ahnung
s=k*i; %10


%define pi
pi = ((beta_b+beta_s)/2)*(pi(+1))-psi*x+u_t;%11
%Define W_s and W_b
%monetary policy
r=rho*r(-1)+(1-rho)*((1+phi_pi)*pi+phi_y*y+phi_q*q)+epsilon_r; %12
%Welfare
W_s = v; %13
W_b = t; %14
W = (1-beta_s)*W_s+(1-beta_b)*W_b; %15

%market clearing condition
y=c_s+c_b; % 16
% ltv ratio
k= k_ss-phi_y-phi_q*q; %17
%housing supply
h_s+h_b = 1; %18

%auxiliary variables (expectations)
z = (r/(pi(+1)*c_s(+1))); %19

m=(1/c_s(+1))*q(+1);%20

d=(r/(pi(+1)*c_b(+1))); %21

f = (1/c_b(+1))*q(+1);%22
g = (q(+1)*pi(+1)); %23
s = (r/pi(+1))*b; %24
i = (q(+1)*h_b);%25
v = (beta_s*(log(c_s)+jot*log(h_s)-(n_s^eta/eta))); %26
t = (beta_b*(log(c_b)+jot*log(h_b)-(n_b^eta/eta))); %27
end;


initval;
k=0.6; %ltv ratio
c_s = 2.75;% cons level savers
r=1.02532; %interest rate
w_s=0.8;% real wage rate saves
x=1.2214; %markup/ inverse of marginal cost
n_s =6; % working hours savers
h_s = 4; %housing stock savers
q =6; % price of housing in units of consumption
b=1.2; % bank loans
c_b=1.8; %consumption borrowers
h_b=6.5; %housing stock borrowers
w_b=0.7; %wage rate borrowers
n_b=5; %working hours borrowers
W_b=1.2; %individual welfare borrowers
W_s=1.5; %individual welfare saves
pi=1.3;
y=4.55; %output

 
end; 


shocks;

var epsilon_r= sigma^2;
var u_t = sigma^2;
end; 

steady;  

stoch_simul;
