Differences between revisions 1 and 10 (spanning 9 versions)
Revision 1 as of 2008-07-13 12:12:54
Size: 2314
Editor: email
Comment:
Revision 10 as of 2008-11-17 17:50:28
Size: 6721
Comment:
Deletions are marked like this. Additions are marked like this.
Line 3: Line 3:
== List of tests == == Status of testing program ==

The program performs the following tests:
Line 6: Line 8:
 1. Den Haan Marcet statistique  1. Den Haan Marcet statistics
Line 8: Line 10:
== SVN archive == For the time being, only the following solutions are implemented:
 * Krueger, Kubler and Malin (KKM)
 * Kim, Kim and Kollman (KKK)
Line 10: Line 14:
Archive name: http://www.cepremap.cnrs.fr/svn/JedcTestSuiteTestsA Others are coming soon.
Line 12: Line 16:
=== Content ===
 * Cuba-1.3: a mutlidimensional integration library http://www.feynarts.de/cuba/ (version 1.4 is available)
 * RandomLib: a random generator library using Mersenne Twister http://charles.karney.info/random/
 * SamplePack: low discrepancy sequences http://www.uni-kl.de/AG-Heinrich/SamplePack.html
 * burkardt: code for Niederreiter sequences http://people.scs.fsu.edu/~burkardt/cpp_src/niederreiter2/niederreiter2.html
 * [:KkK:kkk:]: the solutions computed by Kim, Kim, Kollmann
 * [:KkM:kkm:]: the solutions computed by Kubler, Krueger and Malin
 * libseq_beta_04.21.01: low dicrepancy sequence library http://www.multires.caltech.edu/software/libseq/
 * [:Parser.Src:parser.src:]: Dynare parser code + libraries from dynare++ + testing code
 * testing: beginning of testing code (code for transforming polar to Euclydian coordinates)
== Installing and running the program ==
Line 23: Line 18:
=== Comments ===
 * My original idea was to use Dynare parser to generate the model to be tested. I think now it is unecessarily complicated. It is simpler to code the models directly in C++, providing for the changes in spefications and parameter values.
 * The model is made of forward looking, backward looking and static equations
   * for backward looking and static equations, it is sufficient to return the residual of the equation
   * for forward looking equations, we need both the conditional expectation of the residual (tests 1 and 2) and the residual for a given value of next period variables (den Haan Marcet statistic). It is therefore necessary to factorize all the elements of the equation that don't need to be integrated and write in another function the part of the equation that needs integration.
==== Example ====
The testing program is designed to run on the two following platforms: GNU/Linux and Windows/Cygwin.

You need the following software to run the program:
 * GNU C++ compiler (g++)
 * GNU Fortran 95 compiler (gfortran); under Cygwin, you have to manually install it: the package is downloadable [http://quatramaran.ens.fr/~coudert/gfortran/gfortran-4.4-Cygwin-i686.tar.bz2 here], and installation instructions are [http://gcc.gnu.org/wiki/GFortranBinariesCygwin there]
 * development files for the GNU Scientific Library (GSL), which should be in a package called {{{libgsl0-dev}}}
 * GNU make
 * subversion
 * MATLAB

Download the source of the testing program with:
Line 30: Line 30:
void error(ytm1,yt,frwd_part,e,params,error)
{
  error[0] = yt[1] - params[0]*ytm1[1]-e[0];
  error[1] = yt[0] - params[1]*frwd_part[0];
}
svn checkout http://www.cepremap.cnrs.fr/svn/JedcTestSuiteTestsA
}}}
Line 36: Line 33:
void forward_part(ytm1,yt,ytp1,e,params,frwd)
{
  frwd_part[0] = ytp1[0]*ytp1[1];
}
Then go into the {{{JedcTestSuiteTestsA}}}, and configure the package.

Under GNU/Linux, type:
{{{
./configure --with-matlab=/usr/local/matlab76
Line 41: Line 39:
then {{{forward_part}}} can be integrated as needed over the distribution of {{{ytp1}}} (where you should give the right MATLAB installation directory)

Under Windows/Cygwin, type:
{{{
export FC=/usr/local/gfortran/bin/gfortran
export FCLIBS=/usr/local/gfortran/lib/gcc/i686-pc-cygwin/4.4.0/libgfortran.a
./configure --with-matlab=/cygdrive/c/Progra~1/MATLAB
}}}
(note that you shoud use "Progra~1" instead of "Program Files" when giving the path to MATLAB directory, since spaces in pathnames are not supported)

Finally, compile the testing program by typing:
{{{
make
}}}

This should have created a program called {{{tester}}}. Run this program with:
{{{
./tester
}}}
(it is important to run it from the directory where it was built)

The program will perform the tests for each of the 30 specifications, and for each specification for each solution method. For accuracy tests 1 and 2, it displays relative error for every equation. For accuracy test 3, and for all Euler equations (first separately, then together), it computes the DHM statistics several times, and displays the fraction of times that the statistics was out of the bilateral 5% confidence interval.

== Code overview ==

The class {{{ModelSpec}}} implements the abstract representation of a given specification, and has 8 subclasses {{{ModelSpecA1, ModelSpecA2, ...}}} corresponding to the 8 models. An instance of such a class contains all the parameters of the model and the logic for computing the relative errors of all equations, given the values of the variables and the shocks.

Note that in class {{{ModelSpec}}}, the convention is to work with a vector of variables [[latex($$y_t$$)]] of length [[latex($$5n+1$$)]] (where [[latex($$n$$)]] is the number of countries). The vector [[latex($$y_t$$)]] contains consumption level [[latex($$c_t^j$$)]], labor [[latex($$l_t^j$$)]], investment [[latex($$i_t^j$$)]], capital (end of period stock)[[latex($$k_{t+1}^j$$)]], technology level [[latex($$a_t^j$$)]] and [[latex($$\lambda_t$$)]] (Lagrange multiplier of aggregate budget constraint) (see {{{ModelSpec.hh}}} for more details). Shocks are in a vector [[latex($$e_t$$)]] of size [[latex($$n+1$$)]] (idiosyncratic shocks + global shock).

Relative errors are computed using [[latex($$y_{t-1}$$)]], [[latex($$y_t$$)]], [[latex($$y_{t+1}$$)]] and [[latex($$e_t$$)]], following section 1.5 of Michel's May 2007 notes. The forward looking part of the Euler equation is separately computed by {{{ModelSpec::forward_part()}}}, so that it can be integrated over, and then fed back to {{{ModelSpec::errors()}}} (which computes the [[latex($$5n+1$$)]] errors).

Solution methods are implemented via a subclass of {{{ModelSolution}}} (see {{{kkm/KKMSolution.cc}}} and {{{kkk/KKKSolution.cc}}}). The purpose of these classes is to provide a uniformized wrapper around the participant's solutions. The main method of those classes is the policy function, which provides [[latex($$y_t$$)]] given [[latex($$y_{t-1}$$)]] and [[latex($$e_t$$)]].

The three tests are implemented in class {{{SolutionTester}}}.

The main function is in {{{tester.cc}}}: it constructs the abstract representations of the 30 model specifications, and then performs the tests for all solution methods.

=== KKM solution ===

Source for KKM solution is in {{{kkm/}}} subdirectory. It consists of a non-linear solver (all the Fortran files in {{{kkk/}}}), which are combined in {{{libhybrid.a}}} by the Makefile.

Each of the {{{TestA*}}} subdirectory contains three Fortran 90 files, and a CSV file with Chebychev polynomial coefficients for each number of countries.

Since KKM's code makes uses of global variables, it was necessary to create a dynamically loadable object for each specification, and to load objects on the fly (see class {{{KKMSolution}}}).

The following should also be noted:

 1. KKM don't provide a value for [[latex($$\lambda_t$$)]]. The testing program uses the value of [[latex($$\tau^1 u'_c(c^1_t, l^1_t)$$)]] (marginal utility of consumption of first country) as a replacement.
 1. tests for specification A2 with KKM solution give abnormally large errors on marginal labor equation, because KKM did not implement the right specification in that case (they use [[latex($$\gamma=1$$)]] and [[latex($$\eta=1$$)]] instead of [[latex($$\gamma=0.25$$)]] and [[latex($$\eta=0.1$$)]])
 1. KKM don't provide a solution for specification A7 with 4 and 6 countries, because their solution method doesn't converge with those particular specifications
 1. in some tests, the technological shock falls outside of the truncated interval. The program prints messages like: {{{error: tech shock above zmax in function ChebPoly}}}. This issue yet needs to be solved.

=== KKK solution ===

Data for KKK solution is in {{{kkk/}}} subdirectory. There is one MAT-file for each specification.

Class {{{KKKSolution}}} reads the files, and computes the second-order approximation.

Note that the simulated time paths computed by the testing program do not use the technique of "pruning" the 3rd and higher order terms (as described in Kim, Kim, Schaumburg and Sims (2007)), while "pruning" was used in KKK's 2007 paper. This is simply due to the fact that the testing program uses a generic simulation routine, only based on the one-period ahead policy function provided by the participants; it does not exploit the pecularities of a given solution.

Testing program for problem A

Status of testing program

The program performs the following tests:

  1. accuracy on a sphere in the state space
  2. accuracy on a stochastic simulation
  3. Den Haan Marcet statistics

For the time being, only the following solutions are implemented:

  • Krueger, Kubler and Malin (KKM)
  • Kim, Kim and Kollman (KKK)

Others are coming soon.

Installing and running the program

The testing program is designed to run on the two following platforms: GNU/Linux and Windows/Cygwin.

You need the following software to run the program:

Download the source of the testing program with:

svn checkout http://www.cepremap.cnrs.fr/svn/JedcTestSuiteTestsA

Then go into the JedcTestSuiteTestsA, and configure the package.

Under GNU/Linux, type:

./configure --with-matlab=/usr/local/matlab76

(where you should give the right MATLAB installation directory)

Under Windows/Cygwin, type:

export FC=/usr/local/gfortran/bin/gfortran
export FCLIBS=/usr/local/gfortran/lib/gcc/i686-pc-cygwin/4.4.0/libgfortran.a
./configure --with-matlab=/cygdrive/c/Progra~1/MATLAB

(note that you shoud use "Progra~1" instead of "Program Files" when giving the path to MATLAB directory, since spaces in pathnames are not supported)

Finally, compile the testing program by typing:

make

This should have created a program called tester. Run this program with:

./tester

(it is important to run it from the directory where it was built)

The program will perform the tests for each of the 30 specifications, and for each specification for each solution method. For accuracy tests 1 and 2, it displays relative error for every equation. For accuracy test 3, and for all Euler equations (first separately, then together), it computes the DHM statistics several times, and displays the fraction of times that the statistics was out of the bilateral 5% confidence interval.

Code overview

The class ModelSpec implements the abstract representation of a given specification, and has 8 subclasses ModelSpecA1, ModelSpecA2, ... corresponding to the 8 models. An instance of such a class contains all the parameters of the model and the logic for computing the relative errors of all equations, given the values of the variables and the shocks.

Note that in class ModelSpec, the convention is to work with a vector of variables latex($$y_t$$) of length latex($$5n+1$$) (where latex($$n$$) is the number of countries). The vector latex($$y_t$$) contains consumption level latex($$c_t^j$$), labor latex($$l_t^j$$), investment latex($$i_t^j$$), capital (end of period stock)latex($$k_{t+1}^j$$), technology level latex($$a_t^j$$) and latex($$\lambda_t$$) (Lagrange multiplier of aggregate budget constraint) (see ModelSpec.hh for more details). Shocks are in a vector latex($$e_t$$) of size latex($$n+1$$) (idiosyncratic shocks + global shock).

Relative errors are computed using latex($$y_{t-1}$$), latex($$y_t$$), latex($$y_{t+1}$$) and latex($$e_t$$), following section 1.5 of Michel's May 2007 notes. The forward looking part of the Euler equation is separately computed by ModelSpec::forward_part(), so that it can be integrated over, and then fed back to ModelSpec::errors() (which computes the latex($$5n+1$$) errors).

Solution methods are implemented via a subclass of ModelSolution (see kkm/KKMSolution.cc and kkk/KKKSolution.cc). The purpose of these classes is to provide a uniformized wrapper around the participant's solutions. The main method of those classes is the policy function, which provides latex($$y_t$$) given latex($$y_{t-1}$$) and latex($$e_t$$).

The three tests are implemented in class SolutionTester.

The main function is in tester.cc: it constructs the abstract representations of the 30 model specifications, and then performs the tests for all solution methods.

KKM solution

Source for KKM solution is in kkm/ subdirectory. It consists of a non-linear solver (all the Fortran files in kkk/), which are combined in libhybrid.a by the Makefile.

Each of the TestA* subdirectory contains three Fortran 90 files, and a CSV file with Chebychev polynomial coefficients for each number of countries.

Since KKM's code makes uses of global variables, it was necessary to create a dynamically loadable object for each specification, and to load objects on the fly (see class KKMSolution).

The following should also be noted:

  1. KKM don't provide a value for latex($$\lambda_t$$). The testing program uses the value of latex($$\tau^1 u'_c(c^1_t, l^1_t)$$) (marginal utility of consumption of first country) as a replacement.

  2. tests for specification A2 with KKM solution give abnormally large errors on marginal labor equation, because KKM did not implement the right specification in that case (they use latex($$\gamma=1$$) and latex($$\eta=1$$) instead of latex($$\gamma=0.25$$) and latex($$\eta=0.1$$))

  3. KKM don't provide a solution for specification A7 with 4 and 6 countries, because their solution method doesn't converge with those particular specifications
  4. in some tests, the technological shock falls outside of the truncated interval. The program prints messages like: error: tech shock above zmax in function ChebPoly. This issue yet needs to be solved.

KKK solution

Data for KKK solution is in kkk/ subdirectory. There is one MAT-file for each specification.

Class KKKSolution reads the files, and computes the second-order approximation.

Note that the simulated time paths computed by the testing program do not use the technique of "pruning" the 3rd and higher order terms (as described in Kim, Kim, Schaumburg and Sims (2007)), while "pruning" was used in KKK's 2007 paper. This is simply due to the fact that the testing program uses a generic simulation routine, only based on the one-period ahead policy function provided by the participants; it does not exploit the pecularities of a given solution.

JedcTestsuiteWiki: TestBenchProblemA (last edited 2010-08-18 10:57:35 by SébastienVillemot)