-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathZhen_SOG_Model.m
74 lines (58 loc) · 1.3 KB
/
Zhen_SOG_Model.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
%Stochastic Optimal Growth with Capital Persistence. Homework for Zhen.
clear
global v0 beta delta alpha k_m k0 M a0 j;
alpha = 0.3;
beta = 0.96;
delta = 0.1; % depreciation rate (annual)
epsilon = 0.05;
z_H = 1 + epsilon;
z_L = 1 - epsilon;
amat = [z_H z_L]';
p = 0.5;
M = zeros(2,2); %M for markov transition kernel
M(1,1) = p;
M(2,2) = p;
M(2,1) = 1-p;
M(1,2) = 1-p;
tol = 0.01;
maxits = 1000;
dif = tol+1000;
its = 0;
kgrid = 49; % grid points + 1
kmin = 0.5;
kmax = 7;
grid = (kmax-kmin)/kgrid;
k_m = kmin:grid:kmax;
k_m = k_m';
[N,n] = size(k_m);
polfun = zeros(kgrid+1,2);
v0 = zeros(N,2);
dif = 10;
its = 0;
k11 = zeros(N,2);
while dif > tol %& its < maxits
for j = 1:2
for i = 1:N
k0 = k_m(i,1);
a0 = amat(j,1);
k1 = fminbnd(@valfun_stoch,kmin,kmax);
v1(i,j) = -valfun_stoch(k1);
k11(i,j) = k1;
end
end
dif = norm(v1-v0);
v0 = v1;
its = its+1
end
for i = 1:N
con(i,1) = k_m(i,1)^(alpha) - k11(i,1) + (1-delta)*k_m(i,1);
polfun(i,:) = k_m(i,:)^(alpha) - k11(i,:) + (1-delta)*k_m(i,:);
end
figure
plot(k_m,polfun,'LineWidth', 1)
xlabel('k')
ylabel('c')
figure
plot(k_m, [k11, k_m], 'Linewidth',1)
xlabel('k')
ylabel('k next')