@@ -180,10 +180,10 @@ def make_markov_approx_to_normal_by_monte_carlo(x_grid, mu, sigma, N_draws=10000
180
180
return p_vec
181
181
182
182
183
- def make_tauchen_ar1 (N , sigma = 1.0 , ar_1 = 0.9 , bound = 3.0 ):
183
+ def make_tauchen_ar1 (N , sigma = 1.0 , ar_1 = 0.9 , bound = 3.0 , inflendpoint = True ):
184
184
"""
185
185
Function to return a discretized version of an AR1 process.
186
- See https ://www.fperri.net/TEACHING/macrotheory08/numerical.pdf for details
186
+ See http ://www.fperri.net/TEACHING/macrotheory08/numerical.pdf for details
187
187
188
188
Parameters
189
189
----------
@@ -196,6 +196,12 @@ def make_tauchen_ar1(N, sigma=1.0, ar_1=0.9, bound=3.0):
196
196
bound: float
197
197
The highest (lowest) grid point will be bound (-bound) multiplied by the unconditional
198
198
standard deviation of the process
199
+ inflendpoint: Bool
200
+ If True: implement the standard method as in Tauchen (1986):
201
+ assign the probability of jumping to a point outside the grid to the closest endpoint
202
+ If False: implement an alternative method:
203
+ discard the probability of jumping to a point outside the grid, effectively
204
+ reassigning it to the remaining points in proportion to their probability of being reached
199
205
200
206
Returns
201
207
-------
@@ -208,16 +214,25 @@ def make_tauchen_ar1(N, sigma=1.0, ar_1=0.9, bound=3.0):
208
214
y = np .linspace (- yN , yN , N )
209
215
d = y [1 ] - y [0 ]
210
216
trans_matrix = np .ones ((N , N ))
211
- for j in range (N ):
212
- for k_1 in range (N - 2 ):
213
- k = k_1 + 1
214
- trans_matrix [j , k ] = stats .norm .cdf (
215
- (y [k ] + d / 2.0 - ar_1 * y [j ]) / sigma
216
- ) - stats .norm .cdf ((y [k ] - d / 2.0 - ar_1 * y [j ]) / sigma )
217
- trans_matrix [j , 0 ] = stats .norm .cdf ((y [0 ] + d / 2.0 - ar_1 * y [j ]) / sigma )
218
- trans_matrix [j , N - 1 ] = 1.0 - stats .norm .cdf (
219
- (y [N - 1 ] - d / 2.0 - ar_1 * y [j ]) / sigma
220
- )
217
+ if inflendpoint :
218
+ for j in range (N ):
219
+ for k_1 in range (N - 2 ):
220
+ k = k_1 + 1
221
+ trans_matrix [j , k ] = stats .norm .cdf (
222
+ (y [k ] + d / 2.0 - ar_1 * y [j ]) / sigma
223
+ ) - stats .norm .cdf ((y [k ] - d / 2.0 - ar_1 * y [j ]) / sigma )
224
+ trans_matrix [j , 0 ] = stats .norm .cdf ((y [0 ] + d / 2.0 - ar_1 * y [j ]) / sigma )
225
+ trans_matrix [j , N - 1 ] = 1.0 - stats .norm .cdf (
226
+ (y [N - 1 ] - d / 2.0 - ar_1 * y [j ]) / sigma
227
+ )
228
+ else :
229
+ for j in range (N ):
230
+ for k in range (N ):
231
+ trans_matrix [j , k ] = stats .norm .cdf (
232
+ (y [k ] + d / 2.0 - ar_1 * y [j ]) / sigma
233
+ ) - stats .norm .cdf ((y [k ] - d / 2.0 - ar_1 * y [j ]) / sigma )
234
+ ## normalize: each row sums to 1
235
+ trans_matrix = trans_matrix / trans_matrix .sum (axis = 1 )[:, np .newaxis ]
221
236
222
237
return y , trans_matrix
223
238
0 commit comments