Part 2

In this part you will simulate a sample of T = 100 observations from a stationary AR(1) process with α=0.8, σ2=1

# TODO
# import numpy

Generate a T vector of innovations using gen = np.random.default_rng(100)

# TODO
#eps = ...

Using ε0, generate z0 from the stationary distribution of z. Then, using a for loop, generate the remaining 99 realizations of z

# TODO
#for ....

It would be nice if we could more easily build matrices with simple structure like that of B without having the specify each element individually.

[1α2000000α1000000α1000000000α1]B[z0z1z2zT]z=[ε0ε1ε2εT]ε

Fortunately, we can. Ignoring the the (0,0) element for a moment, the rest of B can be created using np.eye(), np.diag() and np.tile() functions. After that, the (0,0) element can be added manually. Check these functions’ documentation and create the T×T matrix B.

# TODO
#B =

Note

There are other ways to quickly build such matrices. If you are interested, check the documentation of the toeplitz() function from the scipy.linalg package

Verify that the equality z=B1ε holds

# TODO
#np.testing.assert_array_almost_equal(...)

Using B, compute the first T theoretical autocovariances of zt

#TODO
#ar1_acov1 = ...
#assert len(ar1_acov1) == T

Using statsmodels, define an AR(1) object with the same parameters as given above, and compute the T theoretical autocovariances

#TODO
#from statsmodels....
#ar1_process = ...
#ar1_acov2 = ar1_process....

Confirm that ar1_acov1 and ar1_acov2 are the same (or numerically very close)

#TODO