Part 1
Contents
Part 1¶
In this part you will simulate a sample of 4 observations from a stationary AR(1) process with \(\alpha=0.8\), \(\sigma^2 = 1\)¶
# TODO
# import numpy
Generate a \(4D\) vector of innovations using gen = np.random.default_rng(100)
# TODO
#eps = ...
Using \(\varepsilon_0\), generate \(z_0\) from the stationary distribution of \(\mathbf{z}\)
Hint: see here
Using a for
loop, generate the remaining 3 realizations of \(\mathbf{z}\)
# TODO
#for ....
As discussed in a lecture (see again here) there is a linear relationship between \(\mathbf{z}\) and \(\boldsymbol \varepsilon\), In particular, there is a \((T+1)\times(T+1)\) matrix \(\boldsymbol A\) such that
Build the \(4x4\) matrix \(\boldsymbol A\), and confirm that the equality \(\mathbf{z} = \boldsymbol A \boldsymbol\varepsilon\) holds
# TODO
#A =
#np.testing.assert_array_almost_equal(z, A @ eps)
An alternative (and perhaps simpler) way to represent the linear relationship between \(\mathbf{z}\) and \(\boldsymbol\varepsilon\), is with a matrix \(\boldsymbol B\), such that
Using pen and paper, confirm for yourself that this relationship indeed holds. Then, build the matrix \(\boldsymbol 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 \(\boldsymbol B\) is full rank.
# TODO
#B =
# assert full rank...
Verify that the equality \(\mathbf{z} = \boldsymbol B^{-1} \boldsymbol\varepsilon\) holds
# TODO
#np.testing.assert_array_almost_equal(...)