
\documentclass{slides}

\begin{document}

\textbf{EC316a:\ Advanced Scientific Computation, Fall 2003}

\bigskip \textit{Notes Section 5 }

\textbf{Rational expectations modelling with DYNARE}

We now turn to discussion of rational expectations models, and the DYNARE software used to solve and simulate them. As the text's authors describe, rational expectations (RE) models are characteristically applied to examine arbitrage--free equilibria enforced through the collective, decentralized actions of atomistic dynamically optimizing agents. Those agents exhibit rational expectations: that is, their expectations are consistent with the implications of the model as a whole. We consider models in which at time period $t$, the economic system is in state $s_t$. Agents observe the state of the system and pursue their individual objectives. In doing so, they produce a systematic response $x_t$ governed by an equilibrium condition that depends on expectations of the following period's state and action:
\[
f(s_t,x_t,E_t h(s_{t+1},x_{t+1}))=0
\]
The economic system then evolves to a new state $s_{t+1}$ that depends on the current state $s_t$, the response $x_t$, and an exogenous random shock $\epsilon_{t+1}$ that is realized only after the agents respond at time $t$:
\[
s_{t+1} = g(s_t,x_t,\epsilon_{t+1})
\]
In many applications, the equilibrium condition $f=0$ has a natural arbitrage interpretation: for instance, $f_i>0$ may imply that at the margin activity $i$ generated a profit, so that agents have an incentive to increase $x_i$, or vice versa. An arbitrage--free equilibrium will be characterized by $f=0$. 

Although the equilibrium condition only appears to allow dependence on the immediately following period, in reality dependence on any number of future periods may be specified by generating additional variables that take on future values: e.g., one variable in the state vector may be defined as next period's value of a contemporaneous variable, so that the lead of the variable is actually dated two periods hence, and so on. Models of this nature are said to be ``forward--looking'', since decisions today depend on (expectations of) future values of the state and action variables. 

Except in special cases, a rational expectations model poses an infinite--dimensional problem that cannot be solved analytically. It may be solved by approximation methods, such as collocation, in which the function to be approximated is either the response function $x(s)$ or the expectations function $h(s,x(s)$. The two approaches are equivalent, in that one of these functions may be expressed in terms of the other. Approximation of the response function may be difficult in cases where that function exhibits kinks resulting from binding constraints. Alternatively, the expectations function is likely to be smoother than the response function, and may itself be approximated. 

Rather than proceeding with the textbook's discussion of solution methods for these models---which require a significant amount of coding of the functions and their derivatives---we will discuss a higher--level implementation of the rational expectations solution algorithm, Michel Juillard's DYNARE system.

DYNARE is a preprocessor, written in C, and a collection of MATLAB functions which solve nonlinear models with forward--looking variables. The preprocessor allows the model to be coded in natural language (essentially the algebraic form in which one would describe the model's workings) and translates the coded model into a form usable by the MATLAB solution routines. The models analyzed may be deterministic or stochastic. Deterministic models may be used to examine rational expectations schemes under the assumption of perfect foresight: that is, expectations are not only rationally formed, but are correct. Typically this sort of exercise will involve examining the nonlinear dynamics of a system following a shock that perturbs the system away from the prior equilibrium. The simulation describes the reaction to the shock and the restoration of an equilibrium state. Deterministic simulations in DYNARE are computed with a Newton--type algorithm.

For stochastic simulations, the assumption of perfect foresight is relaxed, and the (joint) distribution of the shock processes is described. DYNARE uses a second--order Taylor approximation of the expectation functions to generate the expected response to a realization of the shock process, which may then be simulated many times and the results averaged over realizations. 

DYNARE takes a ".mod" file, prepared by the user, and generates three files when the preprocessor is invoked: \texttt{<filename>.m}, containing the instructions for the simulations; \texttt{<filename>\_ff.m}, containing the dynamic model equations; and \texttt{<filename>\_fff.m}, containing the long run static model equations. 

\textbf{Example: use of DYNARE}

The example is drawn from Fabrice Collard's ``Stochastic simulations with DYNARE: A practical guide''. Consider an economy consisting of a large number of infinitely--lived households and firms. Firms produce a homogeneous final product that may be either consumed or invested by means of capital and labor services. Firms own their capital stock and hire households' labor; in turn, firms are owned by the households. In each period three perfectly competitive markets open: the market for consumption goods, labor services, and financial capital (firms' shares). Household preferences are characterized by a lifetime utility function: 
\[
E_t \sum_{\tau=t}^\infty \beta^{* \tau-t} \left( log(c_t) - \theta \frac{h_t^{1+\psi}}{1+\psi} \right)
\]
where $0 < \beta^* < 1$ is the constant discount factor, $c_t$ is consumption in period $t$, $h_t$ is the fraction of total time devoted to productive activity in period $t$, $\theta > 0$ and $\psi \geq 0$. A central planner determines hours, consumption and capital accumulation which maximize this objective function subject to the budget constraint 
\[ 
c_t + i_t = y_t
\]
where $i_t$ is investment and $y_t$ is output. This is a ``real--sector" model, in which there is no money, government, taxation, or financial sector. Investment is used to form physical capital, which accumulates according to the law of motion
\[
k_{t+1} = \exp(b_t) i_t + (1-\delta) k_t,~~0 < \delta < 1
\]
where $\delta$ is the constant physical depreciation rate, and $b_t$ is a shock affecting incorporated technological progress. Output is produced by a constant--returns--to--scale technology represented by the Cobb--Douglas production function
\[
y_t = \exp(a_t) k_t^\alpha h_t^{1-\alpha},~~0 < \alpha < 1
\]
$a_t$ represents a stochastic shock to technology (the so--called ``Solow residual''). The shocks to technology are distributed with a zero mean vector, but are both persistent over time and contemporaneously correlated. Their joint stochastic process is 
\[ \left(
\begin{array}{l}
  a_t      \\
  b_t     
\end{array}
\right) = 
 \left(
\begin{array}{cc}
 \rho & \tau     \\
 \tau & \rho    
\end{array}
\right)  +
 \left(
\begin{array}{l}
  a_{t-1}      \\
  b_{t-1}     
\end{array}
\right) +
 \left(
\begin{array}{l}
  \epsilon_t      \\
  \nu_t     
\end{array}
\right)
\]
where $| \rho + \tau | < 1$ and $| \rho - \tau | < 1$ to ensure stationarity. Both shocks are distributed with mean zero, variances $\sigma^2_\epsilon$ and $\sigma^2_\nu$ respectively, and are nonautocorrelated. The shocks are contemporaneously correlated with covariance $\varphi \sigma_\epsilon \sigma_\nu$.

The first order conditions for optimality define the dynamic equilibrium of this economy, leading to the following six dynamic equations:
\begin{eqnarray*}
c_t \theta h^{1+\psi}_t = (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} + \epsilon_t \\ \\ 
b_t = \tau a_{t-1} + \rho b_{t-1} + \nu_t
\end{eqnarray*}

Note that while the first and third equations, linking consumption, labor supply and production relate only contemporaneous variables, the second equation involves the expectations of future consumption levels and future technology shocks. 

This model is coded for DYNARE as \texttt{example1.mod}. The variables of the model are \texttt{y, c, k, h, a, b}, given that investment has been substituted out of the model given the income identity. The parameters of the model include \texttt{beta}, the discount factor; \texttt{alpha}, the capital elasticity in production; \texttt{delta}, the capital depreciation rate; \texttt{psi}, the elasticity of labor supply; and \texttt{rho} and \texttt{tau}, the persistence parameters for the shock processes. DYNARE requires that initial values (conditional on the numerical parameter values) be provided for the deterministic steady state. These may be given in approximate form, in which DYNARE will solve for the deterministic steady state. 

Let us now examine the coding of the \texttt{.mod} file and the resulting MATLAB files generated by the preprocessor, along with the solution to the model as computed by DYNARE.

 \end{document}
