I am currently a Ph.D. student in economics, and I am looking to find a way to model and solve dynamic systems of nonlinear equations. The goal is to create a dynamic Computable General Equilibrium (CGE) model in Julia. I am currently a beginner in dynamic systems and have never programmed such a model for conducting simulations. Thank you in advance for your responses.
I have experience in dynamical systems in Julia but not much experience in economics modelling. Can you describe in more detail what a "dynamic Computable General Equilibrium (CGE) " means?
You may want to take a look at GitHub - DynareJulia/Dynare.jl: A Julia rewrite of Dynare: solving, simulating and estimating DSGE models.
A more specific description of your model would help. Eg parameters, endogenous objects, relevant functional equations (equilibrium conditions, optimality), state space, whether it is continuous or discrete time, etc. And whether you just want to solve a few times, or estimate (ie solve a gazillion of times, fast).
A CGE (Computable General Equilibrium) is a mathematical model that comprises a set of equations (often nonlinear) describing the behaviors of various economic agents within an economy. These models enable the modeling of an economy and conducting simulations. For instance, they help understand how an increase in public spending affects the initial state of an economy and towards which new equilibrium state different economic aggregates will converge. As far as I understand, dynamic models like these allow predictions for the future. I hope this clarifies it.
I don’t have specifications yet for the model I want to build. I wanted to know if someone knew how to create a small dynamic model to solve, such as the Ramsey model, so that I can understand how this can be done in JULIA.
Are these equations differential equations? or are they stochastic processes? The packages that can be helpful for you depend on this context. But in any case, to the best of my understanding, Julia seems to have the best-of-class packages for various flavours of dynamical modelling. Perhaps have a look in the functionality offered by:
- DifferentialEquations.jl for differential equations
- JumpProcesses.jl for stochastic processes
- NonlinearSolve.jl for finding steady states of differentialk equations (via the
- ModelingToolkit.jl for building a model based on symbolic notation
- DynamicalSystems.jl for analyzing the model, not building it
I am sure more people from the economics side can add more information here about relevant packages. E.g., the Dynare.jl mentioned above seems to be directly relevant for you.
The same as in other languages, but note that a lot hinges on the methodology you use. Eg using a spectral/collocation method,
- you write out the functional equations
- set up a scheme of function approximations, parametrized by some vector \theta
- calculate r residuals at collocation points,
- encode the mapping r(\theta) in a callable,
- solve for r(\theta) \approx 0.
For 2. and 5., I use
which I find very robust (I use them for larger models). A Ramsey model is about 50 lines of code I guess.
A good textbook that will get you started is eg Miranda and Fackler. Reading it would allow you to code the Ramsey model from first principles, and then you can decide if you want a toolkit.
I am assuming that the Ramsey model is just for learning. The method you will eventually find useful will depend on the complexity of the model and your requirements (nonlinear or linear solution).
While some econ models (especially continuous time) have a PDE representation, classic PDE solvers are usually not very useful outside special cases since they expect traditional boundary conditions, while in most simple macro models agents live forever. My preference is spectral methods for mid-scale models, but larger models are still tricky (some are using deep learning).
What do you think about instead jump-based standard nonlinear optimization with automatic discretion of the time dimension using InfiniteOpt ?
I suppose it really depends upon the specific model that the user is interested in studying. Most CGE models are done in an optimization context where there is some objective function, and then a set of constraints that explain how the world works–things like you cannot spend in the next period more than you had in the prior period.
So I have found that
NonlinearSolve.jl is generally pretty good for numerically solving these problems. Now keep in mind, in many cases econ papers will try to find some analytic solution to these simple model, which are easier to interpret. An analytic solution will let you see the functions for the optimal values of the quantities or variables of interest.
In the case of DSGE or such models, I think a lot of that can be done with the
ControlSystems.jl package. Many DSGE models are solved using linear quadratic regulators. So the
lqr() function in
ControlSystems will do what you want.
InfiniteOpt are design for trajectory optimization or more complex optimal control problems. The user could use these, but I think that any kind of analysis would generally begin with LQR and then move to something more sophisticated when LQR does not work. For example, LQR usually assumes that the system begins at a fixed point and defines the control law–or in the econ case, the consumption vector or something–that keeps the system at that optimal fixed point. But if you question involves how do you get from a point far from the fixed point to the fixed point then you would need tools like
InfiniteOpt, etc., and Trajectory Optimization.
What year are you in? QuantEcon is a fairly comprehensive resource - it provides code for alot of the canonical dynamic models in economics.