Part 2
Contents
Part 2¶
In this part you will simulate a sample of T = 100 observations from a stationary AR(1) process with , ¶
# TODO
# import numpy
Generate a gen = np.random.default_rng(100)
# TODO
#eps = ...
Using for
loop, generate the remaining 99 realizations of
# TODO
#for ....
It would be nice if we could more easily build matrices with simple structure like that of
Fortunately, we can. Ignoring the the (0,0) element for a moment, the rest of 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
# 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
# TODO
#np.testing.assert_array_almost_equal(...)
Using
#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