-
Notifications
You must be signed in to change notification settings - Fork 6
/
tauchen.m
58 lines (49 loc) · 1.53 KB
/
tauchen.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
function [Z,Zprob] = tauchen(N,mu,rho,sigma,m)
%Function TAUCHEN
%
%Purpose: Finds a Markov chain whose sample paths
% approximate those of the AR(1) process
% z(t+1) = (1-rho)*mu + rho * z(t) + eps(t+1)
% where eps are normal with stddev sigma
%
%Format: {Z, Zprob} = Tauchen(N,mu,rho,sigma,m)
%
%Input: N scalar, number of nodes for Z
% mu scalar, unconditional mean of process
% rho scalar
% sigma scalar, std. dev. of epsilons
% m max +- std. devs.
%
%Output: Z N*1 vector, nodes for Z
% Zprob N*N matrix, transition probabilities
%
% Martin Floden
% Fall 1996
%
% This procedure is an implementation of George Tauchen's algorithm
% described in Ec. Letters 20 (1986) 177-181.
%
Z = zeros(N,1);
Zprob = zeros(N,N);
a = (1-rho)*mu;
Z(N) = m * sqrt(sigma^2 / (1 - rho^2));
Z(1) = -Z(N);
zstep = (Z(N) - Z(1)) / (N - 1);
for i=2:(N-1)
Z(i) = Z(1) + zstep * (i - 1);
end
Z = Z + a / (1-rho);
for j = 1:N
for k = 1:N
if k == 1
Zprob(j,k) = cdf_normal((Z(1) - a - rho * Z(j) + zstep / 2) / sigma);
elseif k == N
Zprob(j,k) = 1 - cdf_normal((Z(N) - a - rho * Z(j) - zstep / 2) / sigma);
else
Zprob(j,k) = cdf_normal((Z(k) - a - rho * Z(j) + zstep / 2) / sigma) - ...
cdf_normal((Z(k) - a - rho * Z(j) - zstep / 2) / sigma);
end
end
end
function c = cdf_normal(x)
c = 0.5 * erfc(-x/sqrt(2));