Skip to content

Commit

Permalink
Add steady state capital (#13)
Browse files Browse the repository at this point in the history
* Add steady state capital for large T with an example

* Modify plotting function linestyle

* Minor cosmetic changes
  • Loading branch information
joannakonieczny authored May 30, 2024
1 parent 83654d3 commit ca784b9
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
23 changes: 21 additions & 2 deletions example.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,12 @@ using Plots, DataFrames
my_model = GrowthModel(0.95, 0.02, 2.0, 0.3, 1.0)

# ╔═╡ 500630d6-97ff-4266-ab70-6f3889097314
function plot_allocation(allocation::DataFrame)
plot(allocation.t, allocation.K, xlabel="t", ylabel="K_t", label="capital")
function plot_allocation(allocation::DataFrame, kss::Union{Real,Nothing}=nothing)
p = plot(allocation.t, allocation.K, xlabel="t", ylabel="K_t", label="capital")
if !isnothing(kss)
hline!(p[1], [kss], label="steady state capital", linestyle=:dash)
end
p
end

# ╔═╡ 7354f6ed-fb29-4247-90c7-7718a3a395ff
Expand All @@ -27,6 +31,17 @@ best_allocation = solve(my_model, 20, 0.2)
# ╔═╡ e527fc57-60e0-44dc-9943-bc9095a2166f
plot_allocation(best_allocation)



# ╔═╡ 69167b33-034d-480b-9a06-193c11c61c49
kss = RamseyGrowthModel.steady_state_K(my_model)

# ╔═╡ 77398e1c-55a3-4ae7-868a-cdb7cdf2a8f2
kss_best_allocation = solve(my_model, 100, kss)

# ╔═╡ 47943756-3c8d-4241-ad2a-e02e55965685
plot_allocation(kss_best_allocation, kss)

# ╔═╡ 00000000-0000-0000-0000-000000000001
PLUTO_PROJECT_TOML_CONTENTS = """
[deps]
Expand Down Expand Up @@ -1170,5 +1185,9 @@ version = "1.4.1+1"
# ╠═500630d6-97ff-4266-ab70-6f3889097314
# ╠═7354f6ed-fb29-4247-90c7-7718a3a395ff
# ╠═e527fc57-60e0-44dc-9943-bc9095a2166f
# ╠═41792cc7-80d5-4689-ab54-d94e76eb05c7
# ╠═69167b33-034d-480b-9a06-193c11c61c49
# ╠═77398e1c-55a3-4ae7-868a-cdb7cdf2a8f2
# ╠═47943756-3c8d-4241-ad2a-e02e55965685
# ╟─00000000-0000-0000-0000-000000000001
# ╟─00000000-0000-0000-0000-000000000002
4 changes: 4 additions & 0 deletions src/RamseyGrowthModel.jl
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ function shooting(model::GrowthModel, T::Integer, K₀::Real, C₀::Real)::DataF
allocation
end

function steady_state_K(model::GrowthModel)::Real
f′(k::Real) = ForwardDiff.derivative(model.f, k)
find_zero(x -> f′(x) - 1/model.β + 1 - model.δ, (0, Inf64))
end

"""
Returns the best possible capital and consumption allocation (as a DataFrame).
Expand Down

0 comments on commit ca784b9

Please sign in to comment.