
% This LaTeX was auto-generated from an M-file by MATLAB.
% To make changes, update the M-file and republish this document.

\documentclass{article}
\usepackage{graphicx}
\usepackage{color}

\sloppy
\definecolor{lightgray}{gray}{0.5}
\setlength{\parindent}{0pt}

\begin{document}

    
    
\section*{Dunare AIM Solver Subsystem}


\subsection*{Contents}

\begin{itemize}
\setlength{\itemsep}{-1ex}
   \item AIM Solver Subsystem
   \item APPENDIX 1: AIM System SPecification and Dynare Mapping
   \item APPENDIX 2: dynAIMsolver1 Function Specification
\end{itemize}


\subsection*{AIM Solver Subsystem}

\begin{par}
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  \begin{verbatim}http://www.federalreserve.gov/Pubs/oss/oss4/aimindex.html\end{verbatim} ).
\end{par} \vspace{1em}
\begin{par}
It cosists of:
\end{par} \vspace{1em}
\begin{itemize}
\setlength{\itemsep}{-1ex}
   \item New Dynare function \textbf{dynAIMsolver1(jacobia\_, M\_, dr)} which is called from \textbf{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).
\end{itemize}
\begin{itemize}
\setlength{\itemsep}{-1ex}
   \item 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 \textbf{SPAmalg.m} is the main driver:
\end{itemize}
\begin{itemize}
\setlength{\itemsep}{-1ex}
   \item SPAmalg.m
   \item SPBuild\_a.m
   \item SPSparse.m
   \item SPShiftright.m
   \item SPExact\_shift.m
   \item SPNumeric\_shift.m
   \item SPObstruct.m
   \item SPEigensystem.m
   \item SPReduced\_form
   \item SPCopy\_w.m
   \item SPAimerr.m
\end{itemize}
\begin{par}
The path to the AIM directory, if exists, is added by \textbf{dynare\_config.m} using addpath
\end{par} \vspace{1em}
\begin{par}
\textbf{USE:}
\end{par} \vspace{1em}
\begin{par}
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.:
\end{par} \vspace{1em}

\begin{verbatim}  if (options_.useAIM == 1) && (task == 0) && (options_.order == 1)\end{verbatim}
    \begin{par}
For a start, options\_.useAIM = 0 is set by default in \textbf{global\_initialization.m} so that system uses mjdgges by default.
\end{par} \vspace{1em}
\begin{par}
If AIM is to be used, options\_.useAIM = 1 needs to be set either in the model \begin{verbatim}modelname\end{verbatim}.mod file, before invoking, estimate and/or stoch\_simul, or by issuing appropriate command for estimate and/or stoch\_simul.
\end{par} \vspace{1em}
\begin{par}
\textbf{RELEASE NOTES:}
\end{par} \vspace{1em}
\begin{par}
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.
\end{par} \vspace{1em}
\begin{par}
Hence, system may not coverge or the resluts may not be accurate if there were many messages like
\end{par} \vspace{1em}
\begin{itemize}
\setlength{\itemsep}{-1ex}
   \item "Error in AIM: aimcode=4 : Aim: too few big roots", or
   \item "Error in AIM: aimcode=3 : Aim: too many big roots"
\end{itemize}
\begin{par}
especially when issued close to the point of convergence.
\end{par} \vspace{1em}
\begin{par}
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.
\end{par} \vspace{1em}


\subsection*{APPENDIX 1: AIM System SPecification and Dynare Mapping}

\begin{par}
AIM System for thau lags and theta leads, and:
\end{par} \vspace{1em}
\begin{par}
$$i=-\tau...+\theta $$
\end{par} \vspace{1em}
\begin{par}
$$ \sum_{i=-\tau}^\theta(H_i*x_{t+i})= \Psi*z_t$$
\end{par} \vspace{1em}
\begin{par}
where xt+i is system vectors at time t for all lag/lead t+i and zt is vector of exogenous shocks.
\end{par} \vspace{1em}
\begin{par}
The AIM input is array of matrices \textbf{H}:
\end{par} \vspace{1em}
\begin{par}
$$H=[H_{-\tau} \ ...\  H_i \ ...\ H_{+\theta}] $$
\end{par} \vspace{1em}
\begin{par}
and its solution given as:
\end{par} \vspace{1em}
\begin{par}
$$ X_t=\sum_{i=-\tau}^{-1}(B_i*x_{t+i}) + \phi*\Psi*z_t$$
\end{par} \vspace{1em}
\begin{par}
where Xt is matrix of vectors of all current system variables and forward looking leads xi for i=t,...,t+theta:
\end{par} \vspace{1em}
\begin{par}
$$X_t= \left[\begin{array}{c} {x_{t+\theta} } \\ {...} \\ {x_{t} } \end{array}\right]$$
\end{par} \vspace{1em}
\begin{par}
and AIM output in the form of endogenous transition matrix \textbf{bb}:
\end{par} \vspace{1em}
\begin{par}
$$bb=[B_{-\tau}...  B_i \ ...\ B_{-1}]$$
\end{par} \vspace{1em}
\begin{par}
and, for simple case of one lag system, the  matrix Phi derived as:
\end{par} \vspace{1em}
\begin{par}
$$ \phi=(H_O+H_1*B_{-1})^{-1}$$
\end{par} \vspace{1em}
\begin{par}
For more lags, the phi equation becomes more complicated (see documentation on G.Anderson's site above).
\end{par} \vspace{1em}
\begin{par}
\textbf{Dynare AIM Mapping - input}
\end{par} \vspace{1em}
\begin{par}
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 \textbf{H}, i.e.:
\end{par} \vspace{1em}
\begin{par}
$$ [f_{y,-\tau}' \ ...\ f_{y,i}' \ ...\  f_{y,+\theta}']=[H_{-\tau} \ ...\  H_i \ ...\ H_{+\theta}] $$
\end{par} \vspace{1em}
\begin{par}
and for exogenous shocks terms:
\end{par} \vspace{1em}
\begin{par}
$$ f_u' = - \Psi$$
\end{par} \vspace{1em}
\begin{par}
\textbf{Output} Dynare solution output:
\end{par} \vspace{1em}
\begin{par}
$$ X_t = \sum_{i=-\tau}^{-1}(g_{y,t+i}*x_{t+i})+ g_u*z_t $$
\end{par} \vspace{1em}
\begin{par}
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:
\end{par} \vspace{1em}
\begin{itemize}
\setlength{\itemsep}{-1ex}
   \item gy (or dr.ghx) is a reordered subset of AIM \textbf{SPAmalg.m} output \textbf{bb} without zero columns, and,
   \item gu (or dr.ghu) is derived from reordered AIM \textbf{SPObstruct.m} output as phi in:
\end{itemize}
\begin{par}
$$dr.ghu=g_u= - \phi * \Psi= - \phi * f_u'$$
\end{par} \vspace{1em}


\subsection*{APPENDIX 2: dynAIMsolver1 Function Specification}

\begin{par}
\textbf{function [dr,aimcode]=dynAIMsolver1(jacobia\_,M\_,dr)}
\end{par} \vspace{1em}
\begin{par}
\textbf{INPUTS}
\end{par} \vspace{1em}
\begin{itemize}
\setlength{\itemsep}{-1ex}
   \item jacobia\_  - [matrix]           1st order derivative of the model
   \item dr        - [matlab structure] Decision rules for stochastic simulations.
   \item M\_        - [matlab structure] Definition of the model.
\end{itemize}
\begin{par}
\textbf{OUTPUTS}
\end{par} \vspace{1em}
\begin{itemize}
\setlength{\itemsep}{-1ex}
   \item  dr         [matlab structure] Decision rules for stochastic simulations.
   \item  aimcode    [integer]          status
\end{itemize}

\begin{verbatim}aimcode status is resolved by calling AIMerr as\end{verbatim}
    \begin{itemize}
\setlength{\itemsep}{-1ex}
   \item     (c==1)  e='Aim: unique solution.';
   \item     (c==2)  e='Aim: roots not correctly computed by real\_schur.';
   \item     (c==3)  e='Aim: too many big roots.';
   \item     (c==35) e='Aim: too many big roots, and q(:,right) is singular.';
   \item     (c==4)  e='Aim: too few big roots.';
   \item     (c==45) e='Aim: too few big roots, and q(:,right) is singular.';
   \item     (c==5)  e='Aim: q(:,right) is singular.';
   \item     (c==61) e='Aim: too many exact shiftrights.';
   \item     (c==62) e='Aim: too many numeric shiftrights.';
   \item     else    e='Aimerr: return code not properly specified';
\end{itemize}
\begin{par}
\textbf{SPECIAL REQUIREMENTS}
\end{par} \vspace{1em}
\begin{par}
Dynare use:
\end{par} \vspace{1em}

\begin{verbatim}     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).\end{verbatim}
    
\begin{verbatim}     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.\end{verbatim}
    \begin{par}
GP July 2008
\end{par} \vspace{1em}
\begin{par}
part of DYNARE, copyright Dynare Team (1996-2008) Gnu Public License.
\end{par} \vspace{1em}



\end{document}
    
