v4: branching out /doc

git-svn-id: https://www.dynare.org/svn/dynare/dynare_v4@630 ac1d8469-bf42-47a9-8791-bf33cf982152
time-shift
michel 2006-02-14 14:45:14 +00:00
parent 0d6ed7782f
commit 74b566d355
13 changed files with 5047 additions and 0 deletions

196
doc/DynareKalman.TeX Normal file
View File

@ -0,0 +1,196 @@
% ----------------------------------------------------------------
% AMS-LaTeX Paper ************************************************
% **** -----------------------------------------------------------
\documentclass{amsart}
\usepackage{graphicx}
% ----------------------------------------------------------------
\vfuzz2pt % Don't report over-full v-boxes if over-edge is small
\hfuzz2pt % Don't report over-full h-boxes if over-edge is small
% THEOREMS -------------------------------------------------------
\newtheorem{thm}{Theorem}[section]
\newtheorem{cor}[thm]{Corollary}
\newtheorem{lem}[thm]{Lemma}
\newtheorem{prop}[thm]{Proposition}
\theoremstyle{definition}
\newtheorem{defn}[thm]{Definition}
\theoremstyle{remark}
\newtheorem{rem}[thm]{Remark}
\numberwithin{equation}{section}
% MATH -----------------------------------------------------------
\newcommand{\norm}[1]{\left\Vert#1\right\Vert}
\newcommand{\abs}[1]{\left\vert#1\right\vert}
\newcommand{\set}[1]{\left\{#1\right\}}
\newcommand{\Real}{\mathbb R}
\newcommand{\eps}{\varepsilon}
\newcommand{\To}{\longrightarrow}
\newcommand{\BX}{\mathbf{B}(X)}
\newcommand{\A}{\mathcal{A}}
% ----------------------------------------------------------------
\begin{document}
\title{Kalman filtering and smoothing in Dynare}%
% ----------------------------------------------------------------
\maketitle
% ----------------------------------------------------------------
\section*{Introduction}
\noindent \textbf{``Filtering and Smoothing of State Vector for
Diffuse State Space Models''}, S.J. Koopman and J. Durbin (2003,
in \textit{Journal of Time Series Analysis}, vol. 24(1), pp.
85-98).\newline
\noindent \textbf{``Fast Filtering and Smoothing for Multivariate
State Space Models''}, S.J. Koopman and J. Durbin (2000, in
\textit{Journal of Time Series Analysis}, vol. 21(3), pp.
282-296).\newline
\bigskip
\noindent \textsc{The State-Space Model}\footnote{Note that in
Dynare, matrices $T$, $Z$, $R$, $H$ and $Q$ are assumed to be time
invariant.}:
\[y_t = Z\alpha_t + \varepsilon_t\]
\[\alpha_{t+1} = T \alpha_t + R\eta_t\]
with:
\[\alpha_1 = a + A\delta + R_0\eta_0\]
\noindent $m\times q$ matrix $A$ and $m\times(m-q)$ matrix $R_0$
are selection matrices (their columns constitue all the columns of
the $m\times m$ identity matrix) so that $A'R_0 = 0$ and
$A'\alpha_1 = \delta$. We assume that the vector $\delta$ is
distributed as a $\mathcal{N}(0,\kappa I_q)$ for a given $\kappa
> 0$. So that the expectation of $\alpha_1$ is a and its variance
is $P$, with
\[ P = \kappa P_{\infty} + P_{\star}\]
\[ P_{\infty} = A A'\]
\[ P_{\star} = R_0 Q_0 R_0'\]
\noindent $P_{\infty}$ is a $m\times m$ diagonal matrix with $q$
ones and $m-q$ zeros. and where: $y_t$ is a $pp\times 1$ vector,
$\alpha_t$ is a $mm\times 1$ vector, $\varepsilon_t$ is a
$pp\times 1$ multivariate random variable (iid
$\mathcal{N}(0,H)$), $\eta_t$ is a $rr\times 1$ multivariate
random variable (iid $\mathcal{N}(0,Q)$), $a_1$ is a $mm\times 1$
vector, $Z_t$ is a $pp\times mm$ matrix, $T$ is a $mm \times mm$
matrix, $H$ is a $pp\times pp$ matrix, $R$ is a $mm\times rr$
matrix, $Q$ is a $rr\times rr$ matrix and $P_1$ is a $mm\times mm$
matrix. \newline
\section{Filtering}
\noindent The filtering equations are given by:
\begin{equation}
\begin{split}
v_t &= y_t - Z a_t\\
F_t &= Z P_t Z' + H\\
K_t &= P_t Z' F_t^{-1}\\
a_{t+1} &= T (a_t + K_t v_t)\\
P_{t+1} &= T (P_t - P_tZ'K') T' + R Q R'\\
\end{split}
\end{equation}
$\{F_t\}$ and $\{v_t\}$ are used to evaluate the likelihood. A
potentially faster algorithm (unfortunately not with matlab) is to
consider a univariate approach to the multivariate Kalman filter
(the covariance matrix associated to the measurement errors has to
be diagonal: $H=diag(\sigma_1^2,\dots,\sigma_{pp}^2)$). Let $Z_i$
be line $i$ of the selection matrix $Z$. The univariate algorithm
is as follows :
\begin{equation}
\begin{split}
v_{t,i} &= y_{t,i} - Z_i a_t^{(i)}\\
F_t^{(i)} &= Z_i P_t^{(i)} Z_i' + \sigma_{i}^2\\
K_t^{(i)} &= P_t^{(i)} Z_i'\\
a_{t}^{(i+1)} &= a_t^{(i)} + K_t^{(i)} v_{t,i} / F_t^{(i)}\\
P_{t}^{(i+1)} &= P_{t}^{(i)} - K_{t}^{(i)} \left.K_t^{(i)}\right.' / F_t^{(i)}\\
a_{t+1}^{(1)} &= T a_t^{(pp)}\\
P_{t+1}^{(1)} &= T P_t^{(pp)} T' + R Q R'\\
\end{split}
\end{equation}
when $F_t^{(i)}$ is equal to zero we simply have
$a_{t}^{(i+1)}=a_{t}^{(i)}$ and $P_{t}^{(i+1)}=P_{t}^{(i)}$. The
log-likelihood is evaluated as follows:
\begin{equation}
\mathcal{L}_T = const -\frac{1}{2}\sum_{i=1}^{pp}\sum_{t=1}^n \log
F_{t}^{(i)} + v_{t,i}^2 / F_{t}^{(i)}
\end{equation}
\bigskip
\noindent The diffuse filtering equations are given by:
\begin{equation}
\begin{split}
v_t &= y_t - Z a_t\\
F_{\infty,t} &= Z P_{\infty,t} Z' + H\\
K_{\infty,t} &= P_{\infty,t} Z' F_{\infty,t}^{-1}\\
F_{\ast,t} &= Z P_{\ast,t} Z' + H\\
K_{\ast,t} &= \left(P_{\ast,t} Z' - K_{\infty,t}F_{\ast,t}\right)F_{\infty,t}^{-1}\\
P_{\ast,t+1} &= T (P_{\ast,t}-P_{\ast,t}Z'K_{\infty,t}' - P_{\infty,t}Z'K_{\ast,t}') T' + R Q R'\\
P_{\infty,t+1} &= T(P_{\infty,t}-P_{\infty,t}Z'K_{\infty,t}')T'\\
a_{t+1} &= T (a_t + K_{\infty,t} v_t)\\
\end{split}
\end{equation}
When the condition $rank(P_{\infty,t+1})=0$ is satisfied we set
$d=t$ and go back to the standard Kalman filtering equations. Here
$F_{\infty,t}$ is assumed to be a full rank matrix. If this is not
the case we switch to another algorithm. If $F_{\infty,t}=0$:
\begin{equation}
\begin{split}
v_t &= y_t - Z a_t\\
F_{\ast,t} &= Z P_{\ast,t} Z' + H\\
K_{\ast,t} &= P_{\ast,t} Z'F_{\infty,t}^{-1}\\
P_{\ast,t+1} &= T (P_{\ast,t}-P_{\ast,t}Z'K_{\ast,t}') T' + R Q R'\\
P_{\infty,t+1} &= TP_{\infty,t}T'\\
a_{t+1} &= T (a_t + K_{\ast,t} v_t)\\
L_t &= T(I - K_t Z)\\
\end{split}
\end{equation}
otherwise, we consider a diffuse version of the univariate
approach described above.
\section{Smoothing}
\noindent The smoothing equations are given by:
\begin{equation}
\begin{split}
r_{t-1} &= Z' F_t^{-1}v_t + L_t' r_t\\
\widehat{\alpha}_t &= a_t + P_t r_{t-1} \\
\widehat{\eta}_t &= Q R r_t\\
\widehat{\varepsilon}_t &= H \left(F_t^{-1}v_t-K_t'r_t\right)\\
\end{split}
\end{equation}
initializing with $r_n = 0$ and with $L_t = T-K_tZ$. The diffuse
smoothing equations are given by :
\begin{equation}
\begin{split}
r_{t-1}^{(0)} &= L_{\infty,t}r_{t}^{(0)}\\
r_{t-1}^{(1)} &= Z' F_{\infty,t}^{-1}v_t - K_{\ast,t}'r_{t}^{(0)}+ L_{\infty,t}' r_t^{(1)}\\
\widehat{\alpha}_t &= a_t + P_{\ast,t} r_{t-1}^{(0)} + P_{\infty,t}r_{t-1}^{(1)}\\
\widehat{\eta}_t &= Q R r_t^{(0)}\\
\widehat{\varepsilon}_t &= -H K_{\infty,t}'r_t^{(0)}\\
\end{split}
\end{equation}
for $t = d,d-1,...,1$, where $d$ is such that $P_{\infty,d+1}=0$.
This backward recurrence is initialized with $r_{d}^{(0)}=r_{d}$,
obtained from the non diffuse Kalman smoother, and
$r_{d}^{(1)}=0$. $L_{\infty,t} = T-K_{\infty,t}Z$.\newline
\noindent A univariate smoothing algorithm has to be coded... In
the smoothing part the matrix $F_t$ (or $F_{\infty,t}$) is assumed
to be full rank...
% ----------------------------------------------------------------
%\bibliographystyle{amsplain}
%\bibliography{}
\end{document}
% ----------------------------------------------------------------

105
doc/bibmad.sty Normal file
View File

@ -0,0 +1,105 @@
\message{harvard bibliography,}
\def\@hiteml[#1]#2#3#4{\item[]\if@filesw%
{ \def\protect##1{\string ##1\space}\immediate%
\write\@auxout{\string\harvardcite{#4}{#2}{#1}{#3}}}\fi%
\protect\hspace*{-\labelwidth}\protect\hspace*{-\labelsep}\ignorespaces}
\def\@hitem#1#2#3{\item[]\if@filesw%
{ \def\protect##1{\string ##1\space}\immediate%
\write\@auxout{\string\harvardcite{#3}{#1}{#1}{#2}}}\fi%
\protect\hspace*{-\labelwidth}\protect\hspace*{-\labelsep}\ignorespaces}
\def\harvarditem{\@ifnextchar [{\@hiteml}{\@hitem}}
\def\harvardcite#1#2#3#4{
\global\@namedef{bhf@#1}{#2}
\global\@namedef{bha@#1}{#3}
\global\@namedef{bhy@#1}{#4}\global\@namedef{b@#1}{\csname bhf@#1\endcsname}
}
\def\citeasnoun{\@ifnextchar [{\@tempswatrue\@citex}{\@tempswafalse\@citex[]}}
\def\cite{\@ifnextchar [{\@tempswatrue\@citexasnoun}
{\@tempswafalse\@citexasnoun[]}
}
\def\citeyear{\@ifnextchar [{\@tempswatrue\@citexyear}
{\@tempswafalse\@citexyear[]}
}
\def\citename{\@ifnextchar [{\@tempswatrue\@citexname}
{\@tempswafalse\@citexname[]}
}
% \def\@enamedef#1{\expandafter\edef\csname #1\endcsname}
% Previous line should be replaced by the following to prevent
% problems with the NFSS. Solution by Bernd Raichle.
\def\@enamedef#1{\expandafter\def\csname #1\expandafter\endcsname\expandafter}
\def\@citex[#1]#2{\if@filesw\immediate\write\@auxout{\string\citation{#2}}\fi
\def\@citea{}\@cite{\@for\@citeb:=#2\do
{\@citea\def\@citea{\@hisep\penalty\@m\ }\@ifundefined
{b@\@citeb}{{\bf ?}\@warning
{Citation `\@citeb' on page \thepage \space undefined}}%
{{\csname b@\@citeb\endcsname\@hysep\csname bhy@\@citeb\endcsname}%
\global\@enamedef{b@\@citeb}{\csname bha@\@citeb\endcsname}}%
}}{#1}}
\def\@citexasnoun[#1]#2{%
\if@filesw\immediate\write\@auxout{\string\citation{#2}}\fi%
\@citeasnoun{{\@ifundefined%
{b@#2}%
{[{\bf ?}\@warning{Citation `#2' on page \thepage \space undefined}}%
{{\csname b@#2\endcsname\ [\csname bhy@#2\endcsname}%
\global\@namedef{b@#2}{\csname bha@#2\endcsname}}%
}}{#1}}
\def\@citexname[#1]#2{%
\if@filesw\immediate\write\@auxout{\string\citation{#2}}\fi%
\@citename{{\@ifundefined%
{b@#2}%
{{\bf ?}\@warning{Citation `#2' on page \thepage \space undefined}}%
{{\csname bhf@#2\endcsname}}%
}}{#1}}
\def\@citexyear[#1]#2{\if@filesw\immediate\write\@auxout{\string\citation{#2}}\fi
\def\@citeayear{}\@cite{\@for\@citebyear:=#2\do
{\@citeayear\def\@citeayear{\@hisep\penalty\@m\ }\@ifundefined
{b@\@citebyear}{{\bf ?}\@warning
{Citation `\@citebyear' on page \thepage \space undefined}}%
{{\csname bhy@\@citebyear\endcsname}%
}%
}}{#1}}
\gdef\hysep@agsm{\ }\gdef\hisep@agsm{,}%
\gdef\hysep@dcu{, }\gdef\hisep@dcu{;}%
\let\@hysep\hysep@agsm \let\@hisep\hisep@agsm
\def\citationstyle#1{%
\global\@namedef{@hysep}{\csname hysep@#1\endcsname}%
\global\@namedef{@hisep}{\csname hisep@#1\endcsname}}
%DEFAULT DEFINITIONS
\def\@cite#1#2{({#1\if@tempswa , #2\fi})}
\def\@citeasnoun#1#2{{#1\if@tempswa , #2\fi]}}
\def\@citename#1#2{{#1\if@tempswa \ (#2)\fi}}
% CHANGE \end{document} - to handle double definitions
\def\enddocument{\@checkend{document}\clearpage\begingroup
\if@filesw \immediate\closeout\@mainaux
\def\global\@namedef##1##2{}\def\newlabel{\@testdef r}%
\def\bibcite{\@testdef b}%
\def\harvardcite{\@testbibh}\@tempswafalse \makeatletter\input \jobname.aux
\if@tempswa \@warning{Label(s) may have changed. Rerun to get
cross-references right}\fi\fi\endgroup\deadcycles\z@\@@end}
\def\@testbibh #1#2#3{
\def\@tempa{#2}\expandafter
\ifx \csname bhf@#1\endcsname \@tempa
\def\@tempa{#3}\expandafter
\ifx \csname bha@#1\endcsname \@tempa
\else \@tempswatrue
\fi
\else
\@tempswatrue
\fi
}
%

23
doc/dynare.xsl Normal file
View File

@ -0,0 +1,23 @@
<?xml version='1.0'?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fo="http://www.w3.org/1999/XSL/Format"
xmlns:doc="http://nwalsh.com/xsl/documentation/1.0"
exclude-result-prefixes="doc"
version='1.0'>
<!-- It is important to use indent="no" here, otherwise verbatim -->
<!-- environments get broken by indented tags...at least when the -->
<!-- callout extension is used...at least with some processors -->
<xsl:param name="generate.index">1</xsl:param>
<xsl:param name="refentry.generate.name">0</xsl:param>
<xsl:param name="refentry.generate.title">1</xsl:param>
<xsl:param name="section.autolabel" select="1"></xsl:param>
<xsl:param name="biblioentry.item.separator">, </xsl:param>
<xsl:attribute-set name="section.level1.properties">
<xsl:attribute name="break-before">page</xsl:attribute>
</xsl:attribute-set>
</xsl:stylesheet>

28
doc/dynare_fo.xsl Normal file
View File

@ -0,0 +1,28 @@
<?xml version='1.0'?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fo="http://www.w3.org/1999/XSL/Format"
xmlns:doc="http://nwalsh.com/xsl/documentation/1.0"
exclude-result-prefixes="doc"
version='1.0'>
<!-- It is important to use indent="no" here, otherwise verbatim -->
<!-- environments get broken by indented tags...at least when the -->
<!-- callout extension is used...at least with some processors -->
<xsl:import href="e:/docbook-xsl-1.66.1/fo/docbook.xsl"/>
<xsl:import href="dynare.xsl"/>
<xsl:import href="dynare_lists.xsl"/>
<xsl:param name="passivetex.extensions">1</xsl:param>
<xsl:attribute-set name="list.item.spacing">
<xsl:attribute name="line-height">0em</xsl:attribute>
</xsl:attribute-set>
<xsl:attribute-set name="compact.list.item.spacing">
<xsl:attribute name="space-before.optimum">0em</xsl:attribute>
<xsl:attribute name="space-before.minimum">0em</xsl:attribute>
<xsl:attribute name="space-before.maximum">0em</xsl:attribute>
<xsl:attribute name="line-height">0em</xsl:attribute>
</xsl:attribute-set>
</xsl:stylesheet>

115
doc/dynare_fo_fop.xsl Normal file
View File

@ -0,0 +1,115 @@
<?xml version='1.0'?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fo="http://www.w3.org/1999/XSL/Format"
xmlns:doc="http://nwalsh.com/xsl/documentation/1.0"
exclude-result-prefixes="doc"
version='1.0'>
<!-- It is important to use indent="no" here, otherwise verbatim -->
<!-- environments get broken by indented tags...at least when the -->
<!-- callout extension is used...at least with some processors -->
<!-- <xsl:import href="c:/cygwin/usr/share/docbook-xsl/fo/docbook.xsl"/> -->
<xsl:import href="e:/docbook-xsl-1.65.1/fo/docbook.xsl"/>
<xsl:param name="use.extensions">1</xsl:param>
<xsl:param name="fop.extensions">1</xsl:param>
<xsl:param name="refentry.generate.name">0</xsl:param>
<xsl:param name="refentry.generate.title">1</xsl:param>
<xsl:template match="refsynopsisdiv">
<fo:block font-weight="bold" font-size="16pt" font-family="sans-serif">
<xsl:call-template name="gentext">
<xsl:with-param name="key" select="'RefSynopsisDiv'"/>
</xsl:call-template>
</fo:block>
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="refnamediv">
<xsl:variable name="section.level">
<xsl:call-template name="refentry.level">
<xsl:with-param name="node" select="ancestor::refentry"/>
</xsl:call-template>
</xsl:variable>
<xsl:variable name="reftitle">
<xsl:choose>
<xsl:when test="$refentry.generate.name != 0">
<xsl:call-template name="gentext">
<xsl:with-param name="key" select="'RefName'"/>
</xsl:call-template>
</xsl:when>
<xsl:when test="$refentry.generate.title != 0">
<xsl:choose>
<xsl:when test="../refmeta/refentrytitle">
<xsl:apply-templates select="../refmeta/refentrytitle"/>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="refname[1]"/>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
</xsl:choose>
</xsl:variable>
<!-- xsl:use-attribute-sets takes only a Qname, not a variable -->
<fo:block>
<xsl:choose>
<xsl:when test="$section.level = 1">
<fo:block xsl:use-attribute-sets="refentry.title.properties">
<fo:block xsl:use-attribute-sets="section.title.level1.properties">
<xsl:value-of select="$reftitle"/>
</fo:block>
</fo:block>
</xsl:when>
<xsl:when test="$section.level = 2">
<fo:block xsl:use-attribute-sets="refentry.title.properties">
<fo:block xsl:use-attribute-sets="section.title.level2.properties">
<xsl:value-of select="$reftitle"/>
</fo:block>
</fo:block>
</xsl:when>
<xsl:when test="$section.level = 3">
<fo:block xsl:use-attribute-sets="refentry.title.properties">
<fo:block xsl:use-attribute-sets="section.title.level3.properties">
<xsl:value-of select="$reftitle"/>
</fo:block>
</fo:block>
</xsl:when>
<xsl:when test="$section.level = 4">
<fo:block xsl:use-attribute-sets="refentry.title.properties">
<fo:block xsl:use-attribute-sets="section.title.level4.properties">
<xsl:value-of select="$reftitle"/>
</fo:block>
</fo:block>
</xsl:when>
<xsl:when test="$section.level = 5">
<fo:block xsl:use-attribute-sets="refentry.title.properties">
<fo:block xsl:use-attribute-sets="section.title.level5.properties">
<xsl:value-of select="$reftitle"/>
</fo:block>
</fo:block>
</xsl:when>
<xsl:otherwise>
<fo:block xsl:use-attribute-sets="refentry.title.properties">
<fo:block xsl:use-attribute-sets="section.title.level6.properties">
<xsl:value-of select="$reftitle"/>
</fo:block>
</fo:block>
</xsl:otherwise>
</xsl:choose>
<fo:block space-after="1em">
<xsl:choose>
<xsl:when test="../refmeta/refentrytitle">
<xsl:apply-templates select="../refmeta/refentrytitle"/>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="refname[1]"/>
</xsl:otherwise>
</xsl:choose>
<xsl:apply-templates select="refpurpose"/>
</fo:block>
</fo:block>
</xsl:template>
</xsl:stylesheet>

15
doc/dynare_html.xsl Normal file
View File

@ -0,0 +1,15 @@
<?xml version='1.0'?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fo="http://www.w3.org/1999/XSL/Format"
xmlns:doc="http://nwalsh.com/xsl/documentation/1.0"
exclude-result-prefixes="doc"
version='1.0'>
<!-- It is important to use indent="no" here, otherwise verbatim -->
<!-- environments get broken by indented tags...at least when the -->
<!-- callout extension is used...at least with some processors -->
<xsl:import href="c:/cygwin/usr/share/docbook-xsl/html/chunk.xsl"/>
<xsl:import href="dynare.xsl"/>
</xsl:stylesheet>

1169
doc/dynare_lists.xsl Normal file

File diff suppressed because it is too large Load Diff

16
doc/guide.bbl Normal file
View File

@ -0,0 +1,16 @@
\ifx\undefined\bysame
\newcommand{\bysame}{\leavevmode\hbox to\leftmargin{\hrulefill\,\,}}
\fi
\begin{thebibliography}{xx}
\harvarditem[Collard and Juillard]{Collard and Juillard}{2001}{COLL/JUIL/01a}
{ Collard, F. and M.~Juillard}, Accuracy of stochastic perturbation methods:
The case of asset pricing models, {\it Journal of Economic Dynamics and
Control}, 2001, {\it 25}, 979--999.
\harvarditem[Schmitt-Grohe and Uribe]{Schmitt-Grohe and Uribe}{2002}{SGU/02}
{ Schmitt-Grohe, S. and M.~Uribe}, {\it Solving Dynamic General Equilibrium
Models Using a Second-Order Approximation to the Policy Function}, technical
working paper, Rutgers Univsersity 2002.
\end{thebibliography}

9
doc/guide.blg Normal file
View File

@ -0,0 +1,9 @@
This is BibTeX, Version 0.99cThe top-level auxiliary file: guide.aux
The style file: Usmad.bst
Database file #1: michel.bib
I was expecting a `,' or a `}'---line 248 of file michel.bib
:
: journal = "Computational Economics",
(Error may have been on previous line)
I'm skipping whatever remains of this entry
(There was 1 error message)

346
doc/guide.tex Normal file
View File

@ -0,0 +1,346 @@
\documentclass[11pt,a4paper]{article}
\usepackage{bibmad,graphicx,latexsym,amssymb,times}
\usepackage[cp850]{inputenc}
\begin{document}
\title{Stochastic simulations with {\sc Dynare}. A practical guide.}
\author{Fabrice Collard (GREMAQ, University of Toulouse)\\Adapted for Dynare 2.5.2\\ by Michel Juillard (CEPREMAP and University Paris 8)}
\date{First draft: February 2001\hspace{10mm}This draft: January 2003.}
\maketitle
This document describes a model involving both endogenous and exogenous state variable. We first describe the theoretical model, before showing how the perturbation method is implemented in {\sc Dynare} (MATLAB version).
\section{A theoretical model}
We consider an economy that consists of a large number of dynastic households and a large number of firms. Firms are producing a homogeneous final product that can be either consumed or invested by means of capital and labor services. Firms own their capital stock and hire labor supplied by the households. Households own the firms. In each and every period three perfectly competitive markets open --- the markets for consumption goods, labor services, and financial capital in the form of firms' shares.
Household preferences are characterized by the lifetime utility function:
\begin{equation}
E_t\sum_{\tau=t}^{\infty}{\beta^\star}^{\tau-t} \left(\log(c_t)-\theta\frac{h_t^{1+\psi}}{1+\psi}\right)
\label{eq:ut}
\end{equation}
\noindent where $0<\beta^\star<1$ is a constant discount factor, $c_t$ is consumption in period
$t$, $h_t$ is the fraction of total available time devoted to productive activity in period $t$, $\theta>0$ and $\psi\geqslant 0$. We assume that there exists a central planner that determines hours, consumption and capital accumulation maximizing the household's utility function subject to the following budget constraint
\begin{equation}
c_t+i_t=y_t
\label{eq:bud}
\end{equation}
\noindent where $i_t$ is investment and $y_t$ is output. Investment is used to form physical capital, which accumulates in the standard form as:
\begin{equation}
k_{t+1}=\exp(b_t) i_t+(1-\delta)k_t \mbox{ with } 0<\delta<1
\label{eq:acc}
\end{equation}
where $\delta$ is the constant physical depreciation rate. $b_t$ is a shock affecting incorporated technological progress, which properties will be defined later.
Output is produced by means of capital and labor services, relying on a constant returns to scale technology represented by the following Cobb--Douglas production function:
\begin{equation}
y_t=\exp(a_t) k_t^\alpha h_t^{1-\alpha} \mbox{ with }0<\alpha<1 \label{eq:prod}
\end{equation}
$a_t$ represents a stochastic shock to technology or Solow residual. We assume that the shocks to technology are distributed with zero mean, but display both persistence across time and correlation in the current period.
Let us consider the joint process $(a_t,b_t)$ defined as
\begin{equation}
\left(
\begin{array}{c}
a_t\\b_t
\end{array}
\right)=
\left(
\begin{array}{cc}
\rho&\tau\\
\tau&\rho\\
\end{array}
\right)\left(
\begin{array}{c}
a_{t-1}\\b_{t-1}
\end{array}
\right)
+\left(
\begin{array}{c}
\varepsilon_t\\ \nu_t
\end{array}
\right) \label{eq:process}
\end{equation}
where $|\rho+\tau|<1$ and $|\rho-\tau|<1 $ for sake of stationarity and
\begin{eqnarray*}
E(\varepsilon_t)&=& 0,\\
E(\nu_t)&=& 0,\\
E(\varepsilon_t\varepsilon_s)&=&\left\{
\begin{array}{lcl}
\sigma^2_\varepsilon & \mbox{ if } & t=s \\
0 & \mbox{ if } & t\neq s \\
\end{array}\right. \mbox{, }\\
E(\nu_t\nu_s)&=&\left\{
\begin{array}{lcl}
\sigma^2_\nu & \mbox{ if } & t=s \\
0 & \mbox{ if } & t\neq s \\
\end{array}\right. \mbox{, } \\
E(\varepsilon_t\nu_s)&=&\left\{
\begin{array}{lcl}
\varphi\sigma_\varepsilon\sigma_\nu & \mbox{ if } & t=s \\
0 & \mbox{ if } & t\neq s \\
\end{array}\right. \mbox{. }
\end{eqnarray*}
\section{Dynamic Equilibrium}
The dynamic equilibrium of this economy follows from the first order conditions for optimality:
\begin{eqnarray*}
&&c_t \theta h_t^{1+\psi}=(1-\alpha) y_t \\
&&\beta E_t\left[\left(\frac{\exp(b_t) c_t}{\exp(b_{t+1})c_{t+1}}\right)\left(\exp(b_{t+1})\alpha \frac{y_{t+1}}{k_{t+1}}+1-\delta\right)\right]=1\\
&&y_t=\exp(a_t) k_t^\alpha h_t^{1-\alpha} \\
&&k_{t+1}=\exp(b_t)(y_t-c_t)+(1-\delta)k_t \\
&&a_t=\rho a_{t-1}+\tau b_{t-1}+\varepsilon_t \\
&&b_t=\tau a_{t-1}+\rho b_{t-1}+\nu_t
\end{eqnarray*}
\section{The {\sc dynare} code}
The dynare code is straightforward to write, as the equilibrium is written in the natural way. The whole code is reported at the end of the section. Before that we proceed step by step.
\paragraph{Preamble}
The preamble consists of the some declarations to setup the number of periods the model should be simulated, the endogenous and exogenous variables, the parameters and assign values to these parameters.
\begin{enumerate}
\item {\tt periods 20100}; specifies that the model will be simulated over 20100 periods in order to compute the moments of the simulated variables.
\item {\tt var y, c, k, h, a, b;} specifies the endogenous variables in the model since we have output ({\tt y}), consumption ({\tt c}), capital ({\tt k}), hours ({\tt h}) and the two shocks ({\tt a, b}).
\item {\tt varexo e, u}; specifies the exogenous variables in the model --- namely the innovations of the shocks, since we have the innovation of the non--incorporated shock ({\tt e}), and the innovation of the incorporated shock ({\tt u}).
\item {\tt parameters list;} specifies the list of parameters of the model. In the case we are studying:
{\tt parameters beta, alpha, delta, theta, psi, rho, tau}
\begin{tabular}{ll}
\hline
\hline
{\tt beta} & discount factor \\
{\tt alpha} & capital elasticity in the production function \\
{\tt delta} & depreciation rate \\
{\tt theta} & disutility of labor parameter \\
{\tt psi} & labor supply elasticity \\
{\tt rho} & persistence \\
{\tt tau} & cross--persistence \\
\hline
\hline
\end{tabular}
\item Assignment of parameter values. This is done the standard way in MATLAB. For example, we write
\begin{verbatim}
alpha = 0.36;
rho = 0.95;
tau = 0.025;
beta = 0.99;
delta = 0.025;
psi = 0;
theta = 2.95;
\end{verbatim}
\item Note that $\varphi$, the conditional correlation of the shocks, is not, strickly speaking, a parameter of the recursive equations and doesn't need to be listed in the {\tt parameters} instruction. It may however be convenient to express it as a parameter in the expression of the variance--covariance matrix of the shocks (see below) and one may simply write:
{\tt phi = 0.1; }
\end{enumerate}
\paragraph{Declaration of the model:}
This step is done in a straightforward way. It starts with the instruction {\tt model;} and ends with {\tt end;}, in between all equilibrium conditions are written exactly the way we write it ``by hand''. However, there is a simple rule that should be kept in mind when the model is written. Let us consider a variable $x$:
\begin{itemize}
\item If $x$ is decided in period $t$ then we simply write ${\tt x}$.
\item When the variable is decided in $t-1$, such as the capital stock in our simple model, we write $x(-1)$. \item Finally, when a variable is decided in the next period, $t+1$, such as consumption in the Euler equation, we write $x(+1)$.
\end{itemize}
Hence the required code to declare our model in {\sc Dynare} will be:
\begin{verbatim}
model;
c*theta*h^(1+psi)=(1-alpha)*y;
k = beta*(((exp(b)*c)/(exp(b(+1))*c(+1)))*
(exp(b(+1))*alpha*y(+1)+(1-delta)*k));
y = exp(a)*(k(-1)^alpha)*(h^(1-alpha));
k = exp(b)*(y-c)+(1-delta)*k(-1);
a = rho*a(-1)+tau*b(-1) + e;
b = tau*a(-1)+rho*b(-1) + u;
end;
\end{verbatim}
Assume now that we want to take a Taylor series expansion in logs rather than in level, we just rewrite the model as
\begin{verbatim}
model;
exp(c)*theta*exp(h)^(1+psi)=(1-alpha)*exp(y);
exp(k) = beta*(((exp(b)*exp(c))/(exp(b(+1))*exp(c(+1))))
*(exp(b(+1))*alpha*exp(y(+1))+(1-delta)*exp(k)));
exp(y) = exp(a)*(exp(k(-1))^alpha)*(exp(h)^(1-alpha));
exp(k) = exp(b)*(exp(y)-exp(c))+(1-delta)*exp(k(-1));
a = rho*a(-1)+tau*b(-1) + e;
b = tau*a(-1)+rho*b(-1) + u;
end;
\end{verbatim}
so that the level of consumption is actually given by ${\tt exp(c)}$.
\paragraph{Solving the model}
\begin{enumerate}
\item Now we need to provide numerical initial conditions for the computation of the deterministic steady state. This is done with the sequence between {\tt initval;} and {\tt end;}. Each variable, endogenous or exogenous, should be initialized. In our example, we give the exact values of the deterministic equilibrium in absence of shocks. This takes the form
\begin{verbatim}
initval;
y = 1.08068253095672;
c = 0.80359242014163;
h = 0.29175631001732;
k = 11.08360443260358;
a = 0;
b = 0;
e = 0;
u = 0;
end;
\end{verbatim}
Alternatively, we could provide only approximated values. {\sc Dynare} would then automatically compute the exact values.
\item We then specify the innovations and their matrix of variance--covariance. This is done using the {\tt Sigma\_e} command. As the matrix is symmetrical, one enters onlys the upper (or lower) triangular part:
\begin{verbatim}
Sigma_e = [ 0.000081, (phi*0.009*0.009); ...
0.000081];
\end{verbatim}
where the variance of both innovations is set to {\tt 0.000081} and the correlation between them is equal to $\varphi$. Note that if an element is computed as an expression, this expression must be put in parenthese. In the {\tt Sigma\_e} command, the shock variables are ordered as in the {\tt varexo} declaration.
Alternatively, it is possible to use a {\tt shock;} and {\tt end;} block and declare only the nonzero elements of the covariance matrix:
\begin{verbatim}
shocks;
var e = 0.009^2;
var u = 0.009^2;
var e,u = phi*0.009*0.009;
end;
\end{verbatim}
Note that in the current version of {\sc Dynare}, it isn't possible to shut down of shock by assigning it a zero variance. To shut down a shock the variable must be removed from the {\tt varexo} and {\tt initval} list, added to the {\tt parameters} list and assigned a value of zero.
\item The model is then solved and simulated using the {\tt stoch\_simul;} command. By default, the coefficients of the approximated decision rules are reported as well as the moments of the simulated variables and impulse response functions for each exogenous shocks are ploted. In addition, the following options are aavailable:
\begin{itemize}
\item {\tt DR\_ALG0 = [0,1]}: Specify the algorithm used to compute the quadratic approximation of the decision rules. [0] (default) uses a ``pure'' perturbation method as in \cite{SGU/02}; [1] moves the point around which the Taylor approximation is computed toward the mean of the distribution as in \cite{COLL/JUIL/01a}.
\item AR = Integer
Order of autocorrelation coefficients to compute and to print (default = 5)
\item NOCORR
Doesn't print the correlation matrix (default = PRINT)
\item DROP = Integer
Number of points dropped at the beginning of simulation before computing the summary statistics (default = 100)
\item IRF = Integer
Number of periods on which to compute the IRFs (default = 40)
\item NOFUNCTIONS
Doesn't print the coefficients of the approximated solution
\item LINEAR
Indicates that the original model is linear
\item NOMOMENTS
Doesn't print moments of the endogenous variables
\item ORDER = [1,2]
Order of Taylor approximation (default = 2)
\item REPLIC = Integer
Number of simulated series used to compute the IRFs (default = 1, if order = 1, and 50 otherwise)
\end{itemize}
The simulated trajectories are returned in MATLAB vectors named as the variables (be careful not to use MATLAB reserved names such as INV for your variables \ldots). Note that the specification of the variance--covariance matrix of the shocks is enough to compute a second order approximation of the policy function. In addition, for the simulation and the computation of moments, {\sc Dynare} assumes that the shocks follow a normal distribution.
In our example, we use simply
\begin{verbatim}
stoch_simul;
\end{verbatim}
If one wants to use the algorithm in \cite{COLL/JUIL/01a} and to drop 200 initial values instead of 100, one would write
\begin{verbatim}
simul_stoch(dr_algo=1,drop=200);
\end{verbatim}
\end{enumerate}
\clearpage
\begin{center}
{\sc Dynare code for the model in level}
\end{center}
Here is the model file for the model in level. The last instructions are regular MATLAB commands for graphics. It can be found in file {\tt example1.mod}.
\begin{verbatim}
periods 20100;
var y, c, k, a, h, b;
varexo e,u;
parameters beta, rho, beta, alpha, delta, theta, psi, tau;
alpha = 0.36;
rho = 0.95;
tau = 0.025;
beta = 0.99;
delta = 0.025;
psi = 0;
theta = 2.95;
phi = 0.1;
model;
c*theta*h^(1+psi)=(1-alpha)*y;
k = beta*(((exp(b)*c)/(exp(b(+1))*c(+1)))
*(exp(b(+1))*alpha*y(+1)+(1-delta)*k));
y = exp(a)*(k(-1)^alpha)*(h^(1-alpha));
k = exp(b)*(y-c)+(1-delta)*k(-1);
a = rho*a(-1)+tau*b(-1) + e;
b = tau*a(-1)+rho*b(-1) + u;
end;
initval;
y = 1.08068253095672;
c = 0.80359242014163;
h = 0.29175631001732;
k = 11.08360443260358;
a = 0;
b = 0;
e = 0;
u = 0;
end;
Sigma_e = [ 0.000081, phi*0.009*0.009; 0.000081 ];
stoch_simul;
\end{verbatim}
\newpage
\begin{center}
{\sc Dynare code for the model in logs}
\end{center}
Here is the model file for the model in logs. In this case, {\tt initval} only contains guessed values and {\tt steady} is used to compute and display the exact value of the deterministic equilibrium. The shocks are supposed to be uncorrelated. Also, Collard \& Juillard (2001) algorithm is used. The model file can be found in {\tt example2.mod}.
\begin{verbatim}
periods 20100;
var y, c, k, a, h, b;
varexo e,u;
parameters beta, rho, beta, alpha, delta, theta, psi, tau;
alpha = 0.36;
rho = 0.95;
tau = 0.025;
beta = 0.99;
delta = 0.025;
psi = 0;
theta = 2.95;
model;
exp(c)*theta*exp(h)^(1+psi)=(1-alpha)*exp(y);
exp(k) = beta*(((exp(b)*exp(c))/(exp(b(+1))*exp(c(+1))))
*(exp(b(+1))*alpha*exp(y(+1))+(1-delta)*exp(k)));
exp(y) = exp(a)*(exp(k(-1))^alpha)*(exp(h)^(1-alpha));
exp(k) = exp(b)*(exp(y)-exp(c))+(1-delta)*exp(k(-1));
a = rho*a(-1)+tau*b(-1) + e;
b = tau*a(-1)+rho*b(-1) + u;
end;
initval;
y = 0.1;
c = -0.2;
h = -1.2;
k = 2.4;
a = 0;
b = 0;
e = 0;
u = 0;
end;
steady;
shocks;
var e = 0.009^2;
var u = 0.009^2;
end;
stoch_simul(dr_algo=1,drop=200);
\end{verbatim}
\bibliographystyle{Usmad}
\bibliography{/papers/biblio/michel}
\end{document}

17
doc/makefile Normal file
View File

@ -0,0 +1,17 @@
all: guide.pdf manual/index.html #manual.pdf
guide.pdf: guide.tex
pdflatex guide
manual/index.html: manual.xml
xsltproc -stringparam base.dir ./manual/ dynare_html.xsl manual.xml
manual.pdf: manual.xml
xsltproc dynare_fo.xsl manual.xml >manual.fo
pdfxmltex manual.fo
pdfxmltex manual.fo
install: manual.pdf manual/index.html
scp manual.pdf pythie.cepremap.cnrs.fr:public_html/mambo/download/manual/
scp manual/* pythie.cepremap.cnrs.fr:public_html/mambo/download/manual/

2919
doc/manual.xml Normal file

File diff suppressed because it is too large Load Diff

89
doc/unit_roots.tex Normal file
View File

@ -0,0 +1,89 @@
\documentclass{article}
\usepackage{times}
\begin{document}
\title{Notes on estimating models with unit-roots}
\author{Michel Juillard}
\maketitle
It is now possible to estimate with DYNARE models with unit-roots. These models must satisfy the following restriction: the dynamics of stochastic trends must be (log)--linear and the dynamics of the stationary part around the stochastic trends may be non-linear.
\section{Steady state}
For stationay models, DYNARE linearizes around the steady state, using the internal function dynare\_solve.m. When the dynamics of the stochastic trends doesn't contain a deterministic trend (when it is a pure random walk without displacement), there is an infinity of value of $\bar y$ satisfying $f(\bar y)=0$ and it is possible to specify one of them in INITVAL.
When the stochastic trends contain a deterministic trend, there is no solution to the equation $f(\bar y)=0$. It is then necessary to provide DYNARE with a hand written function called \emph{fname\_steadystate.m} that returns the steady state values of the stationary variables and 0 for nonstationary variables when the model is linearized or 1 for nonstationary variables when the model is log--linearized. The variables must be ordered in alphabetical order. See /examples/fs2000a\_steadystate.m for an example. This procedure is cumbersome and we will be trying to automatize it in the future.
\section{Estimation}
For initializing the Kalman filter and for computing the smoother, DYNARE uses now the algorithm described in chapter 5 of J. Durbin and S.J. Koopman (2001) and in S.J. Koopman and J. Durbin (2003). Following the advice of these authors, we prefer it to the augmented filter advocated by De Jong. Note that the results are identical.
In DYNARE, it is necessary to declare the stochastic trends thru the following statement:
\begin{quote}
options\_.unit\_root\_vars = {'P\_obs'; 'Y\_obs'};
\end{quote}
This syntax is temporary and will be made more DYNARE-like.
It is also necessary to set the option lik\_init=2 in the estimation statement.
In the future, this should be triggered automatically from the declaration of a stochastic trend.
It is also necessary to declare the deterministic components of the stochastic trends with the OBSERVATION\_TREND instruction (see /examples/fs2000/fs2000a.mod)
The new functions are
\begin{itemize}
\item DgesLikelihood.m: replaces mj\_optmumlik for filtering
\item DiffuseLikelihood1.m
\item DiffuseLikelihood2.m
\item DiffuseLikelihoodH1.m
\item DiffuseLikelihoodH2.m
\item DiffuseLikelihoodH3.m
\item DgseSmoother.m: replaces mj\_optmumlik for smoothing
\item DiffuseKalmanSmoother.m
\item DiffuseKalmanSmootherH.m
\end{itemize}
They still need thorough testing.
\section{Examples}
DYNARE is now able to estimate purely backward models, in addition to forward--looking models. The first two examples are such to isolate the problematic of estimating nonstationary models from the difficulties of estimating forward--looking rational expectation models.
\subsection{Two unrelated random walks}
Artificial data (10000 observations) are generated by /examples/arima/mod1.mod for
\begin{eqnarray*}
dx_t = 0.5dx_{t-1}+{e_x}_t\\
dy_t = -0.3dy_{t-1}+{e_y}_t\\
x_t = x_{t-1}+dx_t\\
y_t = y_{t-1}+dy_t
\end{eqnarray*}
mod1a.mod estimates this model when $dx_t$ and $dy_t$ are observed, and
mod1b.mod when the level of the data, $x_t$ and $y_t$, are observed. As expected, the results are the same.
\subsection{A cointegrated system}
Artificial data (10000 observations) are generated by /examples/arima/mod2.mod for
\begin{eqnarray*}
dx_t = 0.5dx_{t-1}-0.1(x_{t-1}-y_{t-1})+{e_x}_t\\
dy_t = -0.3dy_{t-1}+0.2(x_{t-1}-y_{t-1})+{e_y}_t\\
x_t = x_{t-1}+dx_t\\
y_t = y_{t-1}+dy_t
\end{eqnarray*}
mod2a.mod estimates this model when $dx_t$ and $dy_t$ are observed, and $x$ and $y$ are treated as unobservable variables. The estimation procedure fails as the data is first difference don't contain any information about the initial level of $x$ and $y$.
mod2c.mod again estimates this model when $dx_t$ and $dy_t$ are observed, but the model is reparametrized so as to have the cointegration error as stationary unobservable variable.
mod2b.mod estimates the model with data in level: $x_t$ and $y_t$, are observed.In this case, and on moderate samples (100 observations), data in level provide additional information on the cointegrating relationship.
\subsection{Schorfheide, 2000}
fs2000.mod estimates the CIA model of Schorfheide (2000) with observation of the rate of growth of prices and output. fs2000a.mod estimates with data in level. The posterior mode of parameters is somewhat different.
\section*{References}
\begin{description}
\item J. Durbin and S.J. Koopman (2001) \emph{Time Series Analysis by State Space Methods}. Oxford: Oxford University Press.
\item S.J. Koopman and J. Durbin (2003) ``Filtering and Smoothing of State Vector for Diffuse State Space Models'' in \emph{Journal of Time Series Analysis}, \emph{24}, pp. 85-98.
\end{description}
\end{document}