%CC.M %This program approximates the equilibrium of the economy with an aggregate debt limit and financial rents accruing to domestic residents. The output is a pair of vectors of parameters, aL and aH, which parameterize the variable R_t*c_t as exp(X*aL) if the current productivity shock is z^1 and as exp(X*aH) if the current productivity shock is z^2, where X is a matrix defined below. % %Calls CC_VARIABLES.M % clc clear all format compact %Deep parameters and steady-state values [RSTAR, SIG, OMEGA, BETTA1, ALFA, MU, z, PAIZ, KAPA, Kss, QQss, Css, Hss, LAss, Ass, Yss, BETTAss] = cc_ss; zL = z(1); zH = z(2); DH = KAPA*QQss*Kss;%upper bound on debt DL = -10; %lower bound on debt m = 1000; %number of grid points n = 50; %number of regressors a = chebygrid(DL,DH,m); %debt grid in levels X = chebyreg(m,n); %regressors D = inv(X'*X); %Regression Parameters Low state aL = zeros(n,1); aL(1) = log(LAss/RSTAR);%log(LAss/RSTAR*.5); %Regression Parameters High state aH = aL; uu = 0.01; u = 1; dist=1; dist_old =1; iter =1; while dist>1e-12 laL_o_rL = exp(X*aL) ; laH_o_rH = exp(X*aH); [rL, rH, laH, laL, hL, hH, yL, yH, cL, cH, apL, apH, bettaL, bettaH] = cc_variables(laL_o_rL, laH_o_rH,a, DL, DH); WL = chebyreg2(apL,DL,DH,n); WH = chebyreg2(apH,DL,DH,n); lapLH_o_rpLH = exp(WL*aH); lapLL_o_rpLL = exp(WL*aL); [rpLL, rpLH, lapLH, lapLL] = cc_variables(lapLL_o_rpLL, lapLH_o_rpLH,apL, DL, DH); lapL = [lapLL lapLH] * PAIZ(1,:)'; lapHL_o_rpHL = exp(WH*aL); lapHH_o_rpHH = exp(WH*aH); [rpHL, rpHH, lapHH, lapHL] = cc_variables(lapHL_o_rpHL, lapHH_o_rpHH,apH, DL, DH); lapH = [lapHL lapHH] * PAIZ(2,:)'; rhsL = log (bettaL .* lapL); rhsH = log (bettaH .* lapH); aLold = aL; aHold = aH; aold = [aLold;aHold]; aLnew = D*X'*rhsL; aHnew = D*X'*rhsH; anew = [aLnew;aHnew]; dist = max(abs(anew-aold)) u = (uu + u*(1-uu)) * (dist<=dist_old) + 0.01*(dist>dist_old); [dist