= 0.3
α = 0.96
β = 4.0
γ = 0.1
δ = 0.2 s
0.91
A representative agent uses capital \(k_t\) to produce \(y_t\) using the following production function:
\[y_t = k_t^{\alpha}\]
He chooses to consume an amount \(c_t \in ]0, y_t]\) and invests what remains:
\[i_t = y_t - c_t\]
He accumulates capital \(k_t\) according to:
\[k_{t+1} = \left( 1-\delta \right) k_{t} + i_{t}\]
where \(\delta\) is the depreciation rate and \(i_t\) is the amount invested.
The goal of the representative agent is to maximize:
\[\sum_{t\geq 0} \beta^t U(c_t)\]
where \(U(x)=\frac{x^{1-\gamma}}{1-\gamma}\) and \(\beta<1\) is the discount factor.
For now, we ignore the objective and assume that the saving rate \(s=\frac{c_t}{y_t}\) is constant over time.
Create a NamedTuple
to hold parameter values \(\beta=0.96\), \(\delta=0.1\), \(\alpha=0.3\), \(\gamma=4\).
= 0.3
α = 0.96
β = 4.0
γ = 0.1
δ = 0.2 s
0.91
struct SolowModel
::Float64
α::Float64
β::Float64
γ::Float64
δend
= SolowModel(
sm 0.3::Float64,
0.96::Float64,
4.0::Float64,
0.1::Float64,
)
UndefVarError: UndefVarError: `T` not defined in `Main`
Suggestion: check for spelling errors or missing imports.
UndefVarError: `T` not defined in `Main`
Suggestion: check for spelling errors or missing imports.
Stacktrace:
[1] top-level scope
@ ~/Teaching/ensae/mie37/tutorials/jl_notebook_cell_df34fa98e69747e1a8f8a730347b8e2f_W5sZmlsZQ==.jl:1
# dictionary (symbol=>float)
= Dict(
d :α => 0.3,
:β => 0.96,
:γ => 4.0,
:δ => 0.1
)
Dict{Symbol, Float64} with 4 entries:
:α => 0.3
:γ => 4.0
:δ => 0.1
:β => 0.96
:α] d[
0.3
# namedtuple
= (; α=0.3, β=0.96, γ=4.0, δ=0.1, s=0.2) model
(α = 0.3, β = 0.96, γ = 4.0, δ = 0.1, s = 0.2)
#unpack values with keywords
= model.α
α = model.β
β
= model (;α,β)
(α = 0.3, β = 0.96, γ = 4.0, δ = 0.1)
Write down the formula of function \(f\) such that \(k_{t+1}\): \(k_{t+1} = f(k_t)\).
Define a function f(k::Float64, p::NamedTuple)::Float64
to represent \(f\) for a given calibration
# add saving rate
function f(k,p)
= p
(;α, β, γ, δ, s)
# production
= k^α
y = s*y
i
= (1-δ)*k + i
K
return K
end
f (generic function with 2 methods)
@time f(2.0, model)
0.000011 seconds (1 allocation: 16 bytes)
2.0462288826689834
Write a function simulate(k0::Float64, T::Int, p::NamedTuple)::Vector{Float64}
to compute the simulation over T
periods starting from initial capital level k0
.
function simulate(k0, T, p)
= [k0]
res for t=1:T
= res[end]
k = f(k, p)
K push!(res, K)
end
return res
end
simulate (generic function with 1 method)
= 50
T = simulate(2.0, T, model) res
51-element Vector{Float64}:
2.0
2.0462288826689834
2.089528674917447
2.1300608401704926
2.167981873889157
2.2034426980783923
2.236588248806851
2.2675572178060395
2.2964819166036654
2.323488237574935
⋮
2.6574948869350297
2.659891647730072
2.662121260861985
2.6641953419773485
2.6661247051029044
2.667919417201969
2.6695888491235507
2.6711417231678323
2.6725861574799716
Make a nice plot to illustrate the convergence. Do we get convergence from any initial level of capital?
using Plots # all exported functions become available including `plot``
import Plots
Plots.dosomething
= 0:T
tvec plot(tvec, res; title="Solow Model")
# make the plot with different capital levels
= 80
T = simulate(1.0, T, model)
res_1 = simulate(2.0, T, model)
res_2 = simulate(3.0, T, model); res_3
= 0:T
tvec = plot(tvec, res_1; title="Solow Model", label="\$k_0=1.0\$");
pl plot!(pl, tvec, res_2; label="\$k_0=2.0\$");
plot!(pl, tvec, res_3; label="\$k_0=3.0\$");
pl
# what about other value of svaing rates ?
= simulate(2.0, T, merge(model, (;s=0.1)))
res_1 = simulate(2.0, T, merge(model, (;s=0.2)))
res_2 = simulate(2.0, T, merge(model, (;s=0.3)));
res_3 = plot(tvec, res_1; title="Solow Model", label="\$s=1.0\$", xlabel="\$t\$");
pl plot!(pl, tvec, res_2; label="\$s=2.0\$");
plot!(pl, tvec, res_3; label="\$s=3.0\$");
pl
Suppose you were interested in using f
to compute the steady-state. What would you propose to measure convergence speed? To speed-up convergence? Implement these ideas.