# Dunare AIM Solver Subsystem

<introduction></introduction>

## Contents

- AIM Solver Subsystem
- APPENDIX 1: AIM System SPecification and Dynare Mapping
- APPENDIX 2: dynAIMsolver1 Function Specification

## AIM Solver Subsystem

The AIM subsystem in the AIM subdirectory of the main Dynare matlab directory contains MATLAB functions necessary for using Gary Anderson's AIM 1st order solver as an alternative to Dynare's default mjdgges solver (see http://www.federalreserve.gov/Pubs/oss/oss4/aimindex.html ).

It cosists of:

- New Dynare function dynAIMsolver1(jacobia_, M_, dr) which is called from dr1.m and which maps Dynare system to the AIM package subsystem. It then derives the solution for gy=dr.hgx and gu=dr.hgu from the AIM outputs. ("1" in the title is for 1st order solver).

- A subset of MATLAB routines from Gary Anderson's own AIM package needed to compute and solve system passed on and returned by dynAIMsolver1 whose names start with SP.. of which SPAmalg.m is the main driver:

- SPAmalg.m
- SPBuild_a.m
- SPShiftright.m
- SPExact_shift.m
- SPNumeric_shift.m
- SPObstruct.m
- SPEigensystem.m
- SPReduced_form
- SPCopy_w.m
- SPAimerr.m

The path to the AIM directory, if exists, is added by dynare_config.m using addpath

USE:

Dynare DR1.m tries to invoke AIM solver instead default mjdgges if options_.useAIM == 1 is set and, if not check only, and if 1st order solution is needed, i.e.:

      if (options_.useAIM == 1) && (task == 0) && (options_.order == 1)

For a start, options_.useAIM = 0 is set by default in global_initialization.m so that system uses mjdgges by default.

If AIM is to be used, options_.useAIM = 1 needs to be set either in the model modelname.mod file, before invoking, estimate and/or stoch_simul, or by issuing appropriate command for estimate and/or stoch_simul.

RELEASE NOTES:

In the current implementation, as of July 2008, only first order solution is supported and handling of exceptions is rather fundamental and, in particular, when Blanchard and Kahn conditions are not met, only a large penalty value 1.0e+8 is being set.

Hence, system may not coverge or the resluts may not be accurate if there were many messages like

- "Error in AIM: aimcode=4 : Aim: too few big roots", or
- "Error in AIM: aimcode=3 : Aim: too many big roots"

especially when issued close to the point of convergence.

However, if other exceptions occur and aimcode (see codes below) is higher than 5, the system resets options_.useAIM = 0 and tries to use mjdgges instead.

## APPENDIX 1: AIM System SPecification and Dynare Mapping

AIM System for thau lags and theta leads, and:

where xt+i is system vectors at time t for all lag/lead t+i and zt is vector of exogenous shocks.

The AIM input is array of matrices H:

and its solution given as:

where Xt is matrix of vectors of all current system variables and forward looking leads xi for i=t,...,t+theta:

and AIM output in the form of endogenous transition matrix bb:

and, for simple case of one lag system, the matrix Phi derived as:

For more lags, the phi equation becomes more complicated (see documentation on G.Anderson's site above).

Dynare AIM Mapping - input

For Dynare jacobian = [fy'-tau... fy'i ... fy'+theta fu'] - where -tau and +theta are subscripts, we have that its subset without exogenous term fu' and expanded with zero columns represents H, i.e.:

and for exogenous shocks terms:

Output Dynare solution output:

where Xt is again matrix of vectors all current system variables and forward looking leads xi for i=t,..., t+theta, is mapped so that:

- gy (or dr.ghx) is a reordered subset of AIM SPAmalg.m output bb without zero columns, and,
- gu (or dr.ghu) is derived from reordered AIM SPObstruct.m output as phi in:

## APPENDIX 2: dynAIMsolver1 Function Specification

function [dr,aimcode]=dynAIMsolver1(jacobia_,M_,dr)

INPUTS

- jacobia_ - [matrix] 1st order derivative of the model
- dr - [matlab structure] Decision rules for stochastic simulations.
- M_ - [matlab structure] Definition of the model.

OUTPUTS

- dr [matlab structure] Decision rules for stochastic simulations.
- aimcode [integer] status

    aimcode status is resolved by calling AIMerr as

- (c==1) e='Aim: unique solution.';
- (c==2) e='Aim: roots not correctly computed by real_schur.';
- (c==3) e='Aim: too many big roots.';
- (c==35) e='Aim: too many big roots, and q(:,right) is singular.';
- (c==4) e='Aim: too few big roots.';
- (c==45) e='Aim: too few big roots, and q(:,right) is singular.';
- (c==5) e='Aim: q(:,right) is singular.';
- (c==61) e='Aim: too many exact shiftrights.';
- (c==62) e='Aim: too many numeric shiftrights.';
- else e='Aimerr: return code not properly specified';

SPECIAL REQUIREMENTS

Dynare use:

         1) the lognormal block in DR1 is being invoked for some models and changing
         values of ghx and ghy. We need to return the AIM output
         values before that block and run the block with the current returned values
         of gy (i.e. dr.ghx) and gu (dr.ghu) if it is needed even when the AIM is used
         (it does not depend on mjdgges output).

         2) for forward looking models, passing into dynAIMsolver aa ={Q'|1}*jacobia_
         can produce ~ one order closer results to the Dynare solutiion
         then when if plain jacobia_ is passed,
         i.e. diff < e-14 for aa and diff < *e-13 for jacobia_ if Q' is used.

GP July 2008

part of Dynare, copyright Dynare Team (1996-2008) Gnu Public License.