Part 1

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

# TODO
# import numpy

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

# TODO
#eps = ...

Using ε0, generate z0 from the stationary distribution of z

Hint: see here

Using a for loop, generate the remaining 3 realizations of z

# TODO
#for ....

As discussed in a lecture (see again here) there is a linear relationship between z and ε, In particular, there is a (T+1)×(T+1) matrix A such that

[z0z1z2z3z4zT]z=[11α2000000α1α2100000α21α2α10000αT1α2αT1αT2αT3α2α1]A[ε0ε1ε2ε3εT1εT]ε

Build the 4x4 matrix A, and confirm that the equality z=Aε holds

# TODO
#A =

#np.testing.assert_array_almost_equal(z, A @ eps)

An alternative (and perhaps simpler) way to represent the linear relationship between z and ε, is with a matrix B, such that

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

Using pen and paper, confirm for yourself that this relationship indeed holds. Then, build the matrix B and check programmatically if it is invertible (the matrix rank is equal to the number of columns/rows, i.e. it is full rank)

Hint: check the documentation of Numpy for a function that returns the rank of a matrix. Use an assertion to confirm that B is full rank.

# TODO
#B =

# assert full rank...

Verify that the equality z=B1ε holds

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