Skip to content

Commit

Permalink
updates; Trang's comments
Browse files Browse the repository at this point in the history
  • Loading branch information
annabellasd authored and jlperla committed Jan 3, 2024
1 parent 83ef363 commit 7f1fcf2
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 41 deletions.
4 changes: 2 additions & 2 deletions lectures/multi_agent_models/aiyagari.md
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ Household(;r = 0.01,
u = sigma == 1 ? x -> log(x) : x -> (x^(1 - sigma) - 1) / (1 - sigma),
R = setup_R!(fill(-Inf, n, a_size), a_vals, s_vals, r, w, u),
# -Inf is the utility of dying (0 consumption)
Q = setup_Q!(zeros(n, a_size, n), s_i_vals, z_chain)) = (; r, w, sigma, beta, z_chain, a_min, a_max, a_size, a_vals, z_size, n, s_vals, s_i_vals, u, R, Q)
Q = setup_Q!(zeros(n, a_size, n), s_i_vals, z_chain)) = (;r, w, sigma, beta, z_chain, a_min, a_max, a_size, a_vals, z_size, n, s_vals, s_i_vals, u, R, Q)
function setup_Q!(Q, s_i_vals, z_chain)
for next_s_i in 1:size(Q, 3)
Expand Down Expand Up @@ -368,7 +368,7 @@ k_vals = prices_to_capital_stock.(Ref(am), r_vals)
# Plot against demand for capital by firms
demand = rd.(k_vals)
labels = ["demand for capital" "supply of capital"]
labels = ["demand for capital" "supply of capital"]
plot(k_vals, [demand r_vals], label = labels, lw = 2, alpha = 0.6)
plot!(xlabel = "capital", ylabel = "interest rate", xlim = (2, 14), ylim = (0.0, 0.1))
```
Expand Down
12 changes: 6 additions & 6 deletions lectures/multi_agent_models/arellano.md
Original file line number Diff line number Diff line change
Expand Up @@ -590,14 +590,14 @@ using DataFrames, Plots
Compute the value function, policy and equilibrium prices

```{code-cell} julia
ae = ArellanoEconomy(beta = .953, # time discount rate
ae = ArellanoEconomy(beta = .953, # time discount rate
gamma = 2., # risk aversion
r = 0.017, # international interest rate
rho = .945, # persistence in output
eta = 0.025, # st dev of output shock
r = 0.017, # international interest rate
rho = .945, # persistence in output
eta = 0.025, # st dev of output shock
theta = 0.282, # prob of regaining access
ny = 21, # number of points in y grid
nB = 251) # number of points in B grid
ny = 21, # number of points in y grid
nB = 251) # number of points in B grid
# now solve the model on the grid.
vfi!(ae)
Expand Down
15 changes: 8 additions & 7 deletions lectures/multi_agent_models/lake_model.md
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ function transition_matrices(lm)
A = [(1 - lambda) * (1 - d) + b (1 - d) * alpha + b
(1 - d) * lambda (1 - d) * (1 - alpha)]
A_hat = A ./ (1 + g)
return (A, A_hat)
return (;A, A_hat)
end
function rate_steady_state(lm)
Expand Down Expand Up @@ -630,7 +630,7 @@ Following {cite}`davis2006flow`, we set $\alpha$, the hazard rate of leaving emp
We will make use of (with some tweaks) the code we wrote in the {doc}`McCall model lecture <../dynamic_programming/mccall_model>`, embedded below for convenience.

```{code-cell} julia
function solve_mccall_model(mcm; U_iv = 1.0, V_iv = ones(length(mcm.w)), tol = 1e-5,iter = 2_000)
function solve_mccall_model(mcm; U_iv = 1.0, V_iv = ones(length(mcm.w)), tol = 1e-5, iter = 2_000)
(;alpha, beta, sigma, c, gamma, w, E, u) = mcm
# necessary objects
Expand Down Expand Up @@ -671,13 +671,14 @@ u(c, sigma) = c > 0 ? (c^(1 - sigma) - 1) / (1 - sigma) : -10e-6
# model constructor
McCallModel(;alpha = 0.2,
beta = 0.98, # discount rate
beta = 0.98, # discount rate
gamma = 0.7,
c = 6.0, # unemployment compensation
c = 6.0, # unemployment compensation
sigma = 2.0,
u = u, # utility function
w = range(10, 20, length = 60), # w= wage values; E= distribution over wage values
E = Expectation(BetaBinomial(59, 600, 400))) = (;alpha, beta, gamma, c, sigma, u, w, E)
u = u, # utility function
w = range(10, 20, length = 60), # w= wage values
E = Expectation(BetaBinomial(59, 600, 400))) = # E = distribution over wage values
(;alpha, beta, gamma, c, sigma, u, w, E)
```

Expand Down
2 changes: 1 addition & 1 deletion lectures/multi_agent_models/lucas_model.md
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ function LucasTree(;gamma = 2.0,
h[i] = beta * mean((y^alpha .* shocks).^(1 - gamma))
end
return (gamma = gamma, beta = beta, alpha = alpha, sigma = sigma, phi = phi, grid = grid, shocks = shocks, h = h)
return (;gamma, beta, alpha, sigma, phi, grid, shocks, h)
end
# approximate Lucas operator, which returns the updated function Tf on the grid
Expand Down
24 changes: 12 additions & 12 deletions lectures/multi_agent_models/markov_perf.md
Original file line number Diff line number Diff line change
Expand Up @@ -440,13 +440,13 @@ A = I + zeros(3, 3)
B1 = [0.0, 1.0, 0.0]
B2 = [0.0, 0.0, 1.0]
R1 = [ 0.0 -a0 / 2.0 0.0;
-a0 / 2.0 a1 a1 / 2.0;
0.0 a1 / 2.0 0.0]
R1 = [ 0.0 -a0 / 2.0 0.0;
-a0 / 2.0 a1 a1 / 2.0;
0.0 a1 / 2.0 0.0 ]
R2 = [ 0.0 0.0 -a0 / 2.0;
0.0 0.0 a1 / 2.0;
-a0 / 2.0 a1 / 2.0 a1]
R2 = [ 0.0 0.0 -a0 / 2.0;
0.0 0.0 a1 / 2.0;
-a0 / 2.0 a1 / 2.0 a1 ]
Q1 = Q2 = gamma
S1 = S2 = W1 = W2 = M1 = M2 = 0.0
Expand Down Expand Up @@ -480,8 +480,8 @@ In particular, let's take F2 as computed above, plug it into {eq}`eq_mpe_p1p` an
We hope that the resulting policy will agree with F1 as computed above

```{code-cell} julia
Lamda1 = A - (B2 * F2)
lq1 = QuantEcon.LQ(Q1, R1, Lamda1, B1, bet=beta)
Lambda1 = A - (B2 * F2)
lq1 = QuantEcon.LQ(Q1, R1, Lambda1, B1, bet=beta)
P1_ih, F1_ih, d = stationary_values(lq1)
F1_ih
```
Expand All @@ -493,7 +493,7 @@ tags: [remove-cell]
@testset begin
@test P1_ih[2, 2] ≈ 5.441368459897164
@test d ≈ 0.0
@test Lamda1[1, 1] ≈ 1.0 && Lamda1[3, 2] ≈ -0.07584666305807419
@test Lambda1[1, 1] ≈ 1.0 && Lambda1[3, 2] ≈ -0.07584666305807419
@test F1_ih ≈ [-0.6684661291052371 0.29512481789806305 0.07584666292394007]
@test isapprox(F1, F1_ih, atol=1e-7) # Make sure the test below comes up true.
end
Expand Down Expand Up @@ -860,9 +860,9 @@ we set up the matrices as follows:

```{code-cell} julia
# create matrices needed to compute the Nash feedback equilibrium
A = [delta_1 0 -delta_1 * b[1];
0 delta_1 -delta_1 * b[2];
0 0 1]
A = [delta_1 0 -delta_1 * b[1];
0 delta_1 -delta_1 * b[2];
0 0 1 ]
B1 = delta_1 * [1 -D[1, 1];
0 -D[2, 1];
Expand Down
4 changes: 2 additions & 2 deletions lectures/multi_agent_models/rational_expectations.md
Original file line number Diff line number Diff line change
Expand Up @@ -670,9 +670,9 @@ kappa0 = 95.5
kappa1 = 0.95
# formulate the LQ problem
A = [1 0 0
A = [1 0 0
0 kappa1 kappa0
0 0 1]
0 0 1 ]
B = [1.0, 0.0, 0.0]
Expand Down
1 change: 0 additions & 1 deletion lectures/multi_agent_models/schelling.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ kernelspec:
language: julia
name: julia-1.9
---
##AT THIS ONE BUT LUCAS
(schelling)=
```{raw} html
<div id="qe-notebook-header" style="text-align:right;">
Expand Down
20 changes: 10 additions & 10 deletions lectures/multi_agent_models/uncertainty_traps.md
Original file line number Diff line number Diff line change
Expand Up @@ -236,16 +236,16 @@ using DataFrames, LaTeXStrings, Parameters, Plots
```

```{code-cell} julia
UncertaintyTrapEcon(;a = 1.5, # risk aversion
gamma_x = 0.5, # production shock precision
rho = 0.99, # correlation coefficient for theta
sigma_theta = 0.5, # standard dev. of theta shock
num_firms = 100, # number of firms
sigma_F = 1.5, # standard dev. of fixed costs
c = -420.0, # external opportunity cost
mu_init = 0.0, # initial value for mu
gamma_init = 4.0, # initial value for gamma
theta_init = 0.0, # initial value for theta
UncertaintyTrapEcon(;a = 1.5, # risk aversion
gamma_x = 0.5, # production shock precision
rho = 0.99, # correlation coefficient for theta
sigma_theta = 0.5, # standard dev. of theta shock
num_firms = 100, # number of firms
sigma_F = 1.5, # standard dev. of fixed costs
c = -420.0, # external opportunity cost
mu_init = 0.0, # initial value for mu
gamma_init = 4.0, # initial value for gamma
theta_init = 0.0, # initial value for theta
sigma_x = sqrt(a / gamma_x)) = # standard dev. of shock
(;a, gamma_x, rho, sigma_theta, num_firms, sigma_F, c, mu_init, gamma_init, theta_init, sigma_x)
```
Expand Down

0 comments on commit 7f1fcf2

Please sign in to comment.