% Exchange Rate Volatility with Capital % Cameron Shelton and Jamus Lim clear all; % Calibration alpha=0.3; % Capital-labor share of production tech=100; % Technology parameter H1=100; % Money supply country 1 H2=100; % Money supply country 2 N=30; % Number of agents in each country in each generation T=500; % Number of periods w1=100; % Initial wages in country 1 w2=100; % Initial wages in country 2 pix=0.3; % Propensity to experiment a=0.25; % Probability of experimenting on savings-consumption b=0.25; % Probability of experimenting on capital-currency c=0.25; % Probability of experimenting on currency-country % Matrices of Variables W1=zeros(1,T); % Wages of country 1 W2=zeros(1,T); % Wages of country 2 P1=zeros(1,T); % Prices of country 1 P2=zeros(1,T); % Prices of country 2 e=zeros(1,T); % Exchange Rate r1=zeros(1,T); % Rental rate of country 1 r2=zeros(1,T); % Rental rate of country 2 K1=zeros(1,T); % Capital stock of country 1 K2=zeros(1,T); % Capital stock of country 2 S1=zeros(1,T); % Real value in monetary holdings of currency 1 S2=zeros(1,T); % Real value in monetary holdings of currency 2 M1=zeros(N,T); % Nominal currency holdings of currency 1 M2=zeros(N,T); % Nominal currency holdings of currency 2 k11=zeros(N,T); % Real capital investments of citizens 1 in country 1 k12=zeros(N,T); % Real capital investments of citizens 1 in country 2 k21=zeros(N,T); % Real capital investments of citizens 2 in country 1 k22=zeros(N,T); % Real capital investments of citizens 2 in country 2 s11=zeros(N,T); % Real value of investments in citizens 1 in currency 1 s12=zeros(N,T); % Real value of investments in citizens 1 in currency 2 s21=zeros(N,T); % Real value of investments in citizens 2 in currency 1 s22=zeros(N,T); % Real value of investments in citizens 2 in currency 2 C1young=zeros(N,T); % Consumption of country 1 for young C1old=zeros(N,T); % Consumption of country 1 for old C2young=zeros(N,T); % Consumption of country 2 for young C2old=zeros(N,T); % Consumption of country 2 for old U1=zeros(N,T); % Utility of citizens in country 1 U2=zeros(N,T); % Utility of citizens in country 2 F1=zeros(N,T); % Fitness of strategies in country 1 F2=zeros(N,T); % Fitness of strategies in country 2 UU1=zeros(N,1); % Experimental utility of citizens in country 1 UU2=zeros(N,1); % Experimental utility of citizens in country 2 FF1=zeros(N,1); % Experimental fitness of strategies in country 1 FF2=zeros(N,1); % Experimental fitness of strategies in country 2 % Strategy choices A1=rand(N,T+1); % Saving-consumption choice for country 1 A2=rand(N,T+1); % Saving-consumption choice for country 2 B1=rand(N,T+1); % Currency-capital choice for country 1 B2=rand(N,T+1); % Currency-capital choice for country 2 C1=rand(N,T+1); % Currency-country choice for country 1 C2=rand(N,T+1); % Currency-country choice for country 2 D1=rand(N,T+1); % Capital-country choice for country 1 D2=rand(N,T+1); % Capital-country choice for country 2 % Experimental strategy choices E1=zeros(N,4); % Experimental strategies for country 1 E2=zeros(N,4); % Experimental strategies for country 2 % Equations % C(j,i,t)(t+1) = M1(t)/P1(t+1) + M2(t)/P2(t+1) + R1(t+1)k1(j,i,t)(t+1) + R2(t+1)k2(j,i,t)(t+1) Consumption when old % C(j,i,t)(t) = W(t) - M1(t)/P1(t) - M2(t)/P2(t) - k1(j,i,t)(t+1) - k2(j,i,t)(t+1) Consumption when young % N*w(t) - K1(t+1) - K2(t+1) = H1(t)/P1(t) + H2(t)*e(t)/P2(t) Money market equilibrium % tech*alpha*K(j,t)^(alpha-1) = r(j,t) Marginal product of capital % tech*K(j,t)^alpha - tech*K(j,t)*alpha*K(j,t)^(alpha-1) = W(j,t) Marginal product of labor % Initial values W1(1,1)=w1; W2(1,1)=w2; for i=1:N k11(i,2)=W1(1,1)/N*A1(i,1)*(1-B1(i,1))*(D1(i,1)); k21(i,2)=W2(1,1)/N*A2(i,1)*(1-B2(i,1))*(D2(i,1)); k12(i,2)=W1(1,1)/N*A1(i,1)*(1-B1(i,1))*(1-D1(i,1)); k22(i,2)=W2(1,1)/N*A2(i,1)*(1-B2(i,1))*(1-D2(i,1)); end K1(1,2)=sum(k11(:,2),1)+sum(k21(:,2),1); K2(1,2)=sum(k12(:,2),1)+sum(k22(:,2),1); for i=1:N s11(i,1)=W1(1,1)/N*A1(i,1)*(B1(i,1))*(C1(i,1)); s21(i,1)=W2(1,1)/N*A2(i,1)*(B2(i,1))*(C2(i,1)); s12(i,1)=W1(1,1)/N*A1(i,1)*(B1(i,1))*(1-C1(i,1)); % Line 100 s22(i,1)=W2(1,1)/N*A2(i,1)*(B2(i,1))*(1-C2(i,1)); end S1(1,1)= sum(s11(:,1),1)+sum(s21(:,1),1); S2(1,1)= sum(s12(:,1),1)+sum(s22(:,1),1); P1(1,1)=H1/S1(1,1); P2(1,1)=H2/S2(1,1); e(1,1)=P1(1,1)/P2(1,1); for i=1:N C1young(i,1)=W1(1,1)/N*(1-A1(i,1)); C2young(i,1)=W2(1,1)/N*(1-A2(i,1)); end % Portfolio allocation decisions for capital for t=2:T for i=1:N k11(i,t)=W1(1,t-1)/N*A1(i,t-1)*(1-B1(i,t-1))*(D1(i,t-1)); k21(i,t)=W2(1,t-1)/N*A2(i,t-1)*(1-B2(i,t-1))*(D2(i,t-1)); k12(i,t)=W1(1,t-1)/N*A1(i,t-1)*(1-B1(i,t-1))*(1-D1(i,t-1)); k22(i,t)=W2(1,t-1)/N*A2(i,t-1)*(1-B2(i,t-1))*(1-D2(i,t-1)); end K1(1,t)=sum(k11(:,t),1)+sum(k21(:,t),1); % Capital of country 1 at time t K2(1,t)=sum(k12(:,t),1)+sum(k22(:,t),1); % Capital of country 2 at time t % Marginal products of capital and labor r1(1,t)=tech*alpha*K1(1,t)^(alpha-1); r2(1,t)=tech*alpha*K2(1,t)^(alpha-1); W1(1,t)=tech*K1(1,t)^(alpha) - tech*K1(1,t)*alpha*K1(1,t)^(alpha-1); W2(1,t)=tech*K2(1,t)^(alpha) - tech*K2(1,t)*alpha*K2(1,t)^(alpha-1); % Portfolio allocation decisions for currency for i=1:N s11(i,t)=W1(1,t)/N*A1(i,t)*(B1(i,t))*(C1(i,t)); s21(i,t)=W2(1,t)/N*A2(i,t)*(B2(i,t))*(C2(i,t)); s12(i,t)=W1(1,t)/N*A1(i,t)*(B1(i,t))*(1-C1(i,t)); s22(i,t)=W2(1,t)/N*A2(i,t)*(B2(i,t))*(1-C2(i,t)); end S1(1,t)= sum(s11(:,t),1)+sum(s21(:,t),1); % Real savings of currency 1 at time t S2(1,t)= sum(s12(:,t),1)+sum(s22(:,t),1); % Real savings of currency 2 at time t % Prices P1(1,t)=H1/S1(1,t); P2(1,t)=H2/S2(1,t); e(1,t)=P1(1,t)/P2(1,t); % Consumption and utility for i=1:N C1young(i,t)=W1(1,t)/N*(1-A1(i,t)); C2young(i,t)=W2(1,t)/N*(1-A2(i,t)); C1old(i,t)=s11(i,t-1)*P1(1,t-1)/P1(1,t) + s12(i,t-1)*P2(1,t-1)/P2(1,t) + k11(i,t)*r1(1,t) + k12(i,t)*r2(1,t); C2old(i,t)=s21(i,t-1)*P1(1,t-1)/P1(1,t) + s22(i,t-1)*P2(1,t-1)/P2(1,t) + k21(i,t)*r1(1,t) + k22(i,t)*r2(1,t); U1(i,t-1)=log(C1young(i,t-1)) + log(C1old(i,t)); U2(i,t-1)=log(C2young(i,t-1)) + log(C2old(i,t)); end % Genetic algorithms % Imitation operator F1(:,t-1)=U1(:,t-1)/sum(U1(:,t-1)); % Fitness of strategies of generation t-1 in country 1 F2(:,t-1)=U2(:,t-1)/sum(U2(:,t-1)); % Fitness of strategies of generation t-1 in country 2 for i=1:N x1=rand; y1=0; counter=0; while x1 > counter y1=y1+1; counter=sum(F1(1:y1,t-1)); end A1(i,t+1)=A1(y1,t-1); B1(i,t+1)=B1(y1,t-1); C1(i,t+1)=C1(y1,t-1); D1(i,t+1)=D1(y1,t-1); x2=rand; y2=0; counter=0; while x2 > counter y2=y2+1; counter=sum(F2(1:y2,t-1)); end A2(i,t+1)=A2(y2,t-1); B2(i,t+1)=B2(y2,t-1); C2(i,t+1)=C2(y2,t-1); D2(i,t+1)=D2(y2,t-1); % Line 200 end % Experimentation operator E1(:,1)=A1(:,t-1); E1(:,2)=B1(:,t-1); E1(:,3)=C1(:,t-1); E1(:,4)=D1(:,t-1); E2(:,1)=A2(:,t-1); E2(:,2)=B2(:,t-1); E2(:,3)=C2(:,t-1); E2(:,4)=D2(:,t-1); for i=1:N z1=rand; % whether to experiment if z1 < pix q1=rand; % which portfolio choice to experiment v1=rand; % experimental value if q1=U1(i,t-1) A1(i,t+1)=E1(i,1); B1(i,t+1)=E1(i,2); C1(i,t+1)=E1(i,3); D1(i,t+1)=E1(i,4); end if UU2(i,1)>=U2(i,t-1) A2(i,t+1)=E2(i,1); B2(i,t+1)=E2(i,2); C2(i,t+1)=E2(i,3); D2(i,t+1)=E2(i,4); end end end end end time=1:T; % Graph exchange rate subplot(2,2,1), plot(time,e,'k'); xlabel('Time'); ylabel('Exchange Rate'); legend('Exchange Rate'); figure(gcf); % Graph real interest rate subplot(2,2,2), plot(time,r1,'b',time,r2,'r'); xlabel('Time'); ylabel('Real Interest Rate'); legend('Interest Rate 1','Interest Rate 2'); figure(gcf); % Graph capital subplot(2,2,3), plot(time,K1,'b',time,K2,'r'); xlabel('Time'); ylabel('Capital'); legend('Capital 1','Capital 2'); figure(gcf); % Graph wages subplot(2,2,4), plot(time,W1,'b',time,W2,'r'); xlabel('Time'); ylabel('Wages'); legend('Wages 1','Wages 2'); figure(gcf);