Skip to content

Commit 017d98a

Browse files
authored
Merge pull request #484 from shizejin/add_tauchen_drift_term
Add drift term keyword to `markov.tauchen`.
2 parents 26a66c5 + 526a891 commit 017d98a

File tree

2 files changed

+24
-8
lines changed

2 files changed

+24
-8
lines changed

quantecon/markov/approximation.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -135,20 +135,22 @@ def row_build_mat(n, p, q):
135135
return MarkovChain(theta, bar)
136136

137137

138-
def tauchen(rho, sigma_u, m=3, n=7):
138+
def tauchen(rho, sigma_u, b=0., m=3, n=7):
139139
r"""
140140
Computes a Markov chain associated with a discretized version of
141141
the linear Gaussian AR(1) process
142142
143143
.. math::
144144
145-
y_{t+1} = \rho y_t + u_{t+1}
145+
y_{t+1} = b + \rho y_t + u_{t+1}
146146
147147
using Tauchen's method. Here :math:`{u_t}` is an i.i.d. Gaussian process
148148
with zero mean.
149149
150150
Parameters
151151
----------
152+
b : scalar(float)
153+
The constant term of {y_t}
152154
rho : scalar(float)
153155
The autocorrelation coefficient
154156
sigma_u : scalar(float)
@@ -167,25 +169,31 @@ def tauchen(rho, sigma_u, m=3, n=7):
167169
168170
"""
169171

170-
# standard deviation of y_t
172+
# standard deviation of demeaned y_t
171173
std_y = np.sqrt(sigma_u**2 / (1 - rho**2))
172174

173-
# top of discrete state space
175+
# top of discrete state space for demeaned y_t
174176
x_max = m * std_y
175177

176-
# bottom of discrete state space
178+
# bottom of discrete state space for demeaned y_t
177179
x_min = -x_max
178180

179-
# discretized state space
181+
# discretized state space for demeaned y_t
180182
x = np.linspace(x_min, x_max, n)
181183

182184
step = (x_max - x_min) / (n - 1)
183185
half_step = 0.5 * step
184186
P = np.empty((n, n))
185187

188+
# approximate Markov transition matrix for
189+
# demeaned y_t
186190
_fill_tauchen(x, P, n, rho, sigma_u, half_step)
187191

188-
mc = MarkovChain(P, state_values=x)
192+
# shifts the state values by the long run mean of y_t
193+
mu = b / (1 - rho)
194+
195+
mc = MarkovChain(P, state_values=x+mu)
196+
189197
return mc
190198

191199

quantecon/markov/tests/test_approximation.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,22 @@ def setUp(self):
1616
self.n = np.random.random_integers(3, 25)
1717
self.m = np.random.random_integers(4)
1818
self.tol = 1e-12
19+
self.b = 0.
1920

20-
mc = tauchen(self.rho, self.sigma_u, self.m, self.n)
21+
mc = tauchen(self.rho, self.sigma_u, self.b, self.m, self.n)
2122
self.x, self.P = mc.state_values, mc.P
2223

2324
def tearDown(self):
2425
del self.x
2526
del self.P
2627

28+
def testStateCenter(self):
29+
for b in [0., 1., -1.]:
30+
mu = b / (1 - self.rho)
31+
mc = tauchen(self.rho, self.sigma_u, b, self.m, self.n)
32+
self.assertTrue(np.allclose(mu, np.mean(mc.state_values),
33+
atol=self.tol))
34+
2735
def testShape(self):
2836
i, j = self.P.shape
2937

0 commit comments

Comments
 (0)