Main approaches
Back to our problem, how to we differentiate the model?
Main approaches:
- Manual
- Finite Differences
- Symbolic Differentiation
- Automatic Differentiation
Computational Economics (ECO309)
2025-05-28
Study Neoclassical Model of Growth with Deterministic Productivity Shocks
Transition Equation
Definition:
Control
Objective:
Let’s review them:
Optimality Condition:
Definition:
Transition:
Optimality conditions
Transition
?
: Help]
: Package Management;
: System Consoleccall
fcall
PyCall
] add PackageName
Project.toml
; cd path_to_the_right_project
; pwd
(print working directory)] activate .
(.
universally means current director)] add PackageName
Back to our problem, how to we differentiate the model?
Main approaches:
eps()
Two main libraries:
Example using Symbolics:
does not provide mathematical insights but solves the other problems
can differentiate any piece of code
two flavours
Consider this simple function
Instead of rewriting source code, we can use dual numbers to perform exactly the same calculations.
struct DN<:Number
x::Float64
dx::Float64
end
+(a::DN,b::DN) = DN(a.x+b.x, a.dx+b.dx)
-(a::DN,b::DN) = DN(a.x-b.x, a.dx-b.dx)
*(a::DN,b::DN) = DN(a.x*b.x, a.x*b.dx+a.dx*b.x)
/(a::DN,b::DN) = DN(a.x/b.x, (a.dx*b.x-a.x*b.dx)/b.dx^2)
...
Try it on function f
What do we miss ?
This approach (and automatic differentiation in general) is compatible with control flow operations (if
, while
, …)
Let’s see it with the dual numbers defined by ForwardDiff
library:
import ForwardDiff: Dual
x = Dual(1.0, 1.0)
a = 0.5*x
b = sum([(x)^i/i*(-1)^(i+1) for i=1:5000])
# compare with log(1+x)
There are many flavours of automatic differenation (check JuliaDiff.org)
General formulation of a linearized model:
Remark:
In the neoclassical model:
The linearized system is:
What is the solution of our problem?
In the neoclassical model
The states are
The controls
In the linearized model:
Replacing in the system:
If we make the full substitution:
This must be true for all
This is a quadratic, matrix (
requires special solution method
there are multiple solutions: which should we choose?
today: linear time iteration selects only one solution
To solve the model we use the backard operator:
We need to study