function [param1,ss] = finalcode2026calib
% Calibrate parameters (b,d,phi2,met2,betab,L1,L2) in the steady state and compute the steady state equilibrium

%%% £¨A£©Impatient household part   
betai=0.95;
phi=0.7;   
j=0.075; 
rhoXh=0.99;  
rhoChi=0.93; 
eta=0.5;   

%%% £¨B£©Enterprise part 
betae=0.95;      
beta=0.1;     
met=0.7;    
deltak=0.025;  
psi=0.6;   
rhoA=0.9; 
alpha=0.55;

%%% £¨C£©Patient household part
betap=0.994;   

%%% £¨D£©Commercial bank part
betab=0.97;   
miufin=0.99;
rhoEta=0.15;  

%%% £¨E£©Retailer part
theta=0.75;    
epsilon=6;   

%%% £¨F£©Central bank(monetary authority)and monetary policy rule part
rhoM=0.9; 
rhoy=0.15; 
rhopi=1.5;  

%%% £¨G£©Government part
rhoG=0.9; 
rhoB=0.24;

%--------------------------------------------------------- 
% Steady-state targets and model-implied values
%---------------------------------------------------------

Xh=1;         
Chi=1; 
A=1;  
Pi=1;
Pistar=1;
Xe=epsilon/(epsilon-1); 
Eta=0.08;
Np=0.4;
Ni=0.4;
Rd=1/betap;  

B1=(1-betab/betap)/(1-betab*rhoB);
Rmi=(1+betab*rhoB*B1-(1-(1-rhoB)*miufin*Eta)*B1)/betab;
Rme=(1+betab*rhoB*B1-(1-(1-rhoB)*miufin*Eta)*B1)/betab;

A7=(1-betae*(Rme))/Rme; %Auxiliary variable 7, A7=Lambdae2/Lambdae, Equation (52)
A72=1;                          %Auxiliary variable 72, A72=Lambdae4/Lambdae, Equation (54)
A8=alpha/Xe/(1/betae-1+deltak);  %Auxiliary variable 8, A8=K/Ye, Equation (55)
A9=(betae*beta/Xe)/(1-betae-met*A7);  %Auxiliary variable 9, A9=Qh*He/Ye, Equation (53)
A10=met/Rme*A9;    %Auxiliary variable 10, A10=Le/Ye, Equation (22)
A130=(alpha+beta)/Xe-deltak*A8+(1-Rme)*A10;  %  Auxiliary variable 13, A13=Ce/Ye, Equation (24)

A3=(1-betai*(Rmi))/Rmi;  % Auxiliary variable 3, A3=Lambdai2/Lambdai, Equation (42)
A4=((1-psi)*(1-alpha-beta)/Xe)/(1+(Rmi-1)*phi/Rmi*j*Xh/(1-betai-phi*A3));   %  Auxiliary variable 4, A4=Ci/Ye, Equation (14)
A5=j*Xh/(1-betai-phi*A3)*A4;  %  Auxiliary variable 5, A5=Qh*Hi/Ye, Equation (43)
A6=phi/Rmi*A5;  % Auxiliary variable 6, A6=Li/Ye, Equation (16)

A2=(1-miufin*Eta)*(A6+A10);  %  Auxiliary variable 2, A2=Dp/Ye, Equation (31)
A21=0.16;                            %  Auxiliary variable 21, A21=G/Ye
A1=psi*(1-alpha-beta)/Xe+1-1/Xe+(Rd-1)*A2-A21;  %  Auxiliary variable 1, A1=Cp/Ye, Equation (20)
A0=j*Xh/(1-betap)*A1;   %  Auxiliary variable 0, A0=Qh*Hp/Ye

Hs=1.0;
A13=(A0+A5+A9)/Hs;  %  Auxiliary variable 13, A13=Qh/Ye
He=A9/A13;     %  Auxiliary variable 13, A13=He
Ye=((A8)^alpha*(He)^beta*(Np^psi*Ni^(1-psi))^(1-alpha-beta))^(1/(1-alpha));

Qh=Ye*A13;
K=A8*Ye;
Ik=deltak*K;
F=(1-1/Xe)*Ye;
Li=A6*Ye;
Le=A10*Ye;
Ce=A130*Ye;
Hi=A5*Ye/Qh;
Dp=A2*Ye;
Hp=A0*Ye/Qh;
Cp=A1*Ye;
Lambdap=1/Cp;
G=A21*Ye;
T=G;

Ci=A4*Ye;
Lambdai=1/Ci;
Lambdai2=A3*Lambdai;
Lambdae=1/Ce;
Lambdae2=A7*Lambdae;
Lambdae4=A72*Lambdae;

Wi=((1-psi)*(1-alpha-beta)*Ye/Xe)/Ni;
L2=(Wi*Lambdai)/Ni^eta; % calibrated parameter 5
Wp=(psi*(1-alpha-beta)*Ye/Xe)/Np;
L1=Wp*Lambdap/Np^eta; % calibrated parameter 4
       
Cb=Rmi*Li+Rme*Le+(1-Rd)*Dp-Li-Le;
Lambdab=1/Cb;
Lambdab2=Lambdab*(1-betab/betap)/(1-betab*rhoB);
Kb=Li+Le-Dp;

RmiRd=Rmi-Rd;
RmeRd=Rme-Rd;
RrRe=Lambdae/betae/Lambdae*Pi/Rme;
RrRi=Lambdai/betai/Lambdai*Pi/Rmi;
C=Cp+Ci+Ce+Cb;


param1 = [betai,phi,j,rhoXh,rhoChi,eta,L2,...
    betae,beta,met,deltak,alpha,psi,rhoA,betap,L1,...
    betab,miufin,rhoEta,theta,epsilon,rhoM,rhoy,rhopi,rhoG,rhoB]';
ss = [Ci,Lambdai,Qh,Hi,Li,Rmi,Pi,Lambdai2,Xh,Chi,Wi,Ni,...
    Ce,Lambdae,He,Le,Lambdae2,Lambdae4,Ye,Xe,K,Ik,A,Rme,...
    Wp,Np,Cp,Lambdap,Hp,Dp,Rd,F,T,...
    Cb,Lambdab,Lambdab2,Kb,Eta,Pistar,G,C,RmiRd,RmeRd,RrRe,RrRi]';

end

