I am learning how to model some Large-Scale OLG models (life cycle) in Julia.
- Hubbard, Skinner & Zeldes (1995)
- Imrohoroglu, Imorohoroglu & Joines (1995)
- Carroll (1997)
- Conesa & Krueger (1999)
- Attanasio, Low & Sanchez-Marcos (2006)
- Huggett, Ventura & Yaron (2006)
- Braun and Joines (2014)
- Heer & Maussner (2009), Dynamic General Equilibrium Modeling Computational Methods and Applications.
with: Python implementation
- https://github.com/robertdkirkby/LifeCycleOLGReadingList
- https://www.robertdkirkby.com/life-cycle-and-olg-models/
- https://github.com/BHeer42/LargeScaleOLGmodel
- Cheat Sheet
- After testing the functionality of the code in
.ipynb
, the entire code must be wrapped inside amain()
function. Then, the script can be called and run in the terminal.Run Julia from the terminalusing Packages function main() the code end @time main()
cd "path_to_script_containing_folder" julia script.jl
in Julia
(*) does not work all the time
Documentation https://juliapackages.com/p/dynare
- Installation
using Pkg
pkg"add Dynare"
- Running
using Dynare
(if there is an error related to 'OpenBLAS32' )
import LinearAlgebra, OpenBLAS32_jll
LinearAlgebra.BLAS.lbt_forward(OpenBLAS32_jll.libopenblas_path)
- Invoke
.mod'
file
context = @dynare "path/model.mod";
The results are stored in the context
structure.
- View results
The context structure is saved in the directory
<path to modfile>/<modfilenane>/output/<modfilename>.jld2
. It can be loaded with
using JLD2
DD = load("<path to modfile>/<modefilename>/output/<modefilename>.jld2")``
The IRF graphs are saved in <path to modfile>/<modfilenane>/graphs
.
in Matlab
Quick Start: here
addpath /Applications/Dynare/x.y/matlab
cd '/Users/USERNAME/work'
dynare example1
to edit
edit example1.mod
# Pkg.add("NLsolve")
using NLsolve
# solving for x,y -> z, with parameters a,b,c
function system_eq!(F, z, a, b, c)
x, y = z
F[1] = x^2 + y^2 - a + 2b
F[2] = (x * y)^c - a - b^2
end
#specify values of parameters
a = 1.0
b = 2.0
c = 2.0
z_guess = [0.0, 0.0] # Initial guess for x and y
# Solve the system of equations
result = nlsolve((F, z) -> system_eq!(F, z, a, b, c), z_guess)
# Extract the solution
x_solution = result.zero[1]
y_solution = result.zero[2]
Note: When applying this solver, the correct guess is very important. With backward iteration, remember to take the previously solved known value as the guess. For example, in Auerbach-Kotlikoff, the guess to solve k[39]
should take the initial guess of k
,n
in k[40]
, k[41]
, and n[40]
.
while
loop
max_iter = 10
i = 1
tol = 1e-6
err = 0.1
while i <= max_iter && abs(err) > tol
do something
if abs(err) > tol
i += 1
else
break
end
end
for
loop
forward
for s in 1:1:60
k[s] = solve(k[s-1)
end
for
loop
backward
for s in 60:-1:1
k[s] = solve(k[s+1])
end