Advanced Macro: Numerical Methods
2024-04-11
The unconditional distribution of an AR1 is a normal law \(\mathcal{N}(0,\frac{\sigma}{\sqrt{1-\rho^2}})\)
Choose \(m>0\), typically \(m=3\)
Bound the process: \(\underline{x} = -m \frac{\sigma}{\sqrt{1-\rho^2}}\) and \(\overline{x} = m \frac{\sigma}{\sqrt{1-\rho^2}}\)
Define the \(N\) discretized points (\(i\in[1,n]\)): \(y_i = \underline{x} + \frac{i-1}{N-1}(\overline{x}-\underline{x})\)
Define the transitions:
\[\begin{eqnarray} \pi_{ij} & = & prob \left( y_{t+1}=y_j|y_t=y_i\right)\\ & = & prob \left( |y_{t+1}-x_j| = \inf_k |y_{t+1}-x_k| \left| y_t=y_i \right. \right) \end{eqnarray}\]
Formulas \(\delta=\frac{\overline{x}-\underline{x}}{N}\):
if \(1<k<N-1\)
\[\pi_{jk} = F(\frac{y_k + \delta/2-\rho y_j}{\sigma_{\epsilon}}) - F(y_k + \delta/2-\rho y_j)\]
if \(k=1\)
\[\pi_{j} = F(\frac{y_k + \delta/2-\rho y_j}{\sigma_{\epsilon}}) \]
if \(k=N\)
\[\pi_{j} = 1- F(\frac{y_k - \delta/2-\rho y_j}{\sigma_{\epsilon}}) \]
compare generated stationary moments between discretized process and true AR1:
by looking at the exact ergodic distribution or by doing some simulations
not very precise when then process is very persistent \(\rho\approx 1\)
Procedure converges to Bernouilli distribution.
Moments can be computed in closed form:
Rouwenhorst method performs better for highly correlated processes
Given \(f\), and an iid process \(\epsilon \sim N(0,\sigma^2)\), how to approximate \(E_{\epsilon} f(\epsilon)\) ?
Ideas:
\[\frac{1}{N} \sum_n w_n f(\epsilon_n)\]
Let’s take an exemple:
Let’s compute \(E_{\epsilon}(C(\epsilon))\) precisely.
Discuss value of \(\gamma\): is it crazy? (risk return)
Compute expectation
[graph]
Same logic can be applied to compute integration with weight function \(w(x)\): \[\int_a^b f(x) w(x)\]
Gauss-Hermite:
Gauss-Legendre:
Gauss-Chebychev:
Beware that weight is not the density of the normal law:
\[\frac{1}{\sqrt{2 \pi \sigma^2}}\int f(x) e^{-\frac{x^2}{2\sigma^2}}dx = {\frac{1}{\sqrt{\pi}}}\int f(u {\sigma \sqrt{2}}) e^{-{u^2}}du \] \[{\frac{1}{\sqrt{\pi}}}\sum_n w_n f(\epsilon_n {\sigma \sqrt{2}})\]
using FastGaussQuadrature
x, w = gausslegendre( 10 );
x = x.*σ*sqrt(2) # renormalize nodes
s = sum( w_*U(exp(x_)) for (w_,x_) in zip(x,w))
s /= sqrt(\pi) # renormalize output