Nash-Ramsey Toolbox
==================

This toolbox computes Nash and Ramsey equilibria for DSGE models using
Dynare 6.5.  It accompanies the JME paper; the replication scripts and
worked examples are included alongside the core programs.

Instructions are available at http://www.lguerrieri.com/Nash_ramsey_website/

If using this toolbox please cite

@article{BGL2019,
  author  = {Bodenstein, Martin and Guerrieri, Luca and LaBriola, Joe},
  title   = {{Macroeconomic Policy Games}},
  journal = {Journal of Monetary Economics},
  year    = {2019},
  volume  = {101},
  pages   = {64--81},
  doi     = {10.1016/j.jmoneco.2018.07.015},
}


FIRST-TIME SETUP
----------------
Before using the toolbox for the first time, or after moving it to a new
location, run the following from the MATLAB command window:

    run setup_toolbox

This embeds the correct absolute paths into setpathdynare6_5.m (see below).
It only needs to be run once per location.


DIRECTORY STRUCTURE
-------------------

nash_ramsey_toolbox_051026/          <- toolbox root
|
|-- setup_toolbox.m                  <- run once after installation (see above)
|-- setpathdynare6_5.m               <- path-setup script; call at the start of every session
|
|-- toolbox_programs/                <- core toolbox (82 .m files)
|       create_ramsey.m              solve Ramsey optimal policy problem
|       get_nash.m                   solve Nash equilibrium
|       get_ramsey.m                 solve Ramsey equilibrium
|       convertmodfiles.m            convert .mod files for toolbox use
|       dynparse.m                   Dynare .mod file parser
|       ... (and more)
|
|-- utilities/                       <- plotting and helper functions (47 .m files)
|       makeirf.m                    impulse response function charts
|       makechart*.m                 chart-generation helpers
|       printpref*.m                 print/export helpers
|       hpfast.m, bpass.m            filtering utilities
|       anneal.m                     simulated annealing optimizer
|       ... (and more)
|
|-- JME_paper/
|       main.pdf                     the published paper
|
|-- JME_paper_replication_and_examples/
|       readme.txt                   describes each example in detail
|       BBCDL_model_excl2ndorder/    figures 1, 2, 4 and table 1
|       BBCDL_model_2ndorder/        figure 3
|       GK_model/                    figures 5-6
|       GK_model_with_altruism/      figure 7
|       LQ_BBCDL_model/              LQ verification


STARTING A SESSION
------------------
At the top of any script that uses the toolbox, add:

    run setpathdynare6_5

This adds Dynare, toolbox_programs, and utilities to the MATLAB path.
Because setpathdynare6_5.m contains absolute paths (written by setup_toolbox),
it works correctly regardless of which subdirectory you run it from.


HOW setup_toolbox WORKS
------------------------
MATLAB scripts typically set paths with relative references such as
'../../utilities', which break as soon as the calling script is moved to
a different folder depth.

setup_toolbox.m solves this by:

  1. Using mfilename('fullpath') to locate itself, which always returns
     the correct absolute path regardless of MATLAB's current working
     directory or operating system.

  2. Building absolute paths to utilities/ and toolbox_programs/ with
     fullfile(), which uses the correct separator (/ on Mac/Linux, \ on
     Windows) automatically.

  3. Reading setpathdynare6_5.m and replacing the dir2 and dir3
     assignments in-place with the absolute paths just computed.

After setup_toolbox has been run, setpathdynare6_5.m can be copied into
any subfolder of the project and will still point to the right directories.


DYNARE VERSION
--------------
The toolbox requires Dynare 6.5.  setpathdynare6_5.m looks for it in the
standard installation locations:

  Mac (Apple Silicon)   /Applications/Dynare/6.5-arm64/matlab
  Mac (Intel)           /Applications/Dynare/6.5/matlab
  Windows               C:\dynare\6.5\matlab
  Linux                 /usr/lib/dynare/matlab

If Dynare is installed elsewhere, set the dynare_path variable at the top
of setpathdynare6_5.m to the full path of its matlab subdirectory.
