This implements the code for The endogenous grid method for discrete‐continuous dynamic choice models with (or without) taste shocks, published in Quantitative Economics (2017) by Fedor Iskhakov, Thomas H. Jørgensen, John Rust and Bertel Schjerning
This julia package is based on the matlab code accompanying the published paper, available at https://github.com/fediskhakov/dcegm.
- This runs
12.5xfaster than the published matlab version. Details
- The solution is checked for numerical equivalence with the matlab version.
- I provide a state-dependent extensions to their version.
- I provide interactive apps that make it easy to study model behavior as the user varies model parameters.
How to Use this
This package is not (yet) officially registered, you so follow instructions below for installation
- Download latest julia
- start julia. you see something like this:
➜ julia _ _ _ _(_)_ | Documentation: https://docs.julialang.org (_) | (_) (_) | _ _ _| |_ __ _ | Type "?" for help, "]?" for Pkg help. | | | | | | |/ _` | | | | |_| | | | (_| | | Version 1.1.0 (2019-01-21) _/ |\__'_|_|_|\__'_| | Official https://julialang.org/ release |__/ | julia>
- Hit the
]key to switch to package manager mode. the prompt switches to
- Download this package by pasting this into the
(v1.1) pkg>prompt and hitting enter.
- After this is done, hit backspace or
ctrl-cto go back to standard
julia> cd(joinpath(DEPOT_PATH,"dev","DCEGM")) # go to the location of DCEGM on your computer
- Go back to package mode by typing
(v1.1) pkg> activate . # tell pkg manager to modify current directory (DCEGM) pkg> instantiate # download all dependencies (DCEGM) pkg> precompile # precompile package
🎉Now try it out. Go back to command mode with
julia> using DCEGM julia> @time DCEGM.runf(); # run @fedishakov's version of the model 0.012842 seconds (13.53 k allocations: 16.122 MiB)
The package is thoroughly unit tested. Please run
] test while in the activated project. The main test concerns the file
test/F_test.jl, where we test the output of this version against the one obtained from @fediskhakov s matlab version up to numerical accuracy. That is, first we save the value and policy functions from the matlab code to ASCII format on disk, then we compute the julia model, then we compare each computed value and policy function. There are many more tests, though.
# hit ] (@v1.4) pkg> activate . (DCEGM) pkg> test
julia> DCEGM.iminimal() # interact with the minimal model julia> DCEGM.iminimalb() # interact with the minimal model with bequest julia> DCEGM.ifedor() # interact with fedors model julia> DCEGM.igmodel() # interact with the general model
in each instance, you'll see a new window like that one:
A quick demonstration of how the
upper_env method works. Given an array of
MLines (my version of a line, i.e. an array of
x-y pairs representing a
Point), this constructs the upper envelope over the lines. Particular attention must be paid to intersections between lines.
Also, points where 2 lines intersect on the initial grid of both lines are not intersections.
This is the output of function
bm() which is here. Matlab time is taken only for model solution, no setup or disk write operation. Please check the source code for questions.
julia> DCEGM.bm() Hi! This is Matlab version 22.214.171.1241785 (R2019b) Update 3 running on my laptop t: 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 Retirement model solved with 500 asset points 25 periods at 0.0000020 lambda 0.350 sigma in 1.509s wrote policy and value function to ascii in output/ . exiting matlab. julia timing: BenchmarkTools.Trial: memory estimate: 117.82 MiB allocs estimate: 179885 -------------- minimum time: 121.571 ms (16.45% GC) median time: 125.947 ms (18.26% GC) mean time: 129.230 ms (20.44% GC) maximum time: 149.955 ms (31.12% GC) -------------- samples: 39 evals/sample: 1
The julia version runs 12.5 times faster than the matlab version.