Let us assume we observe data over a 6-month horizon on a monthly basis (k = 6). Let us also assume the following recursive structure (example below).
I wonder, how this structure can be programmed most efficiently considering the following aspects (Efficiency will be absolutely necessary):
- The period of 6 months is for simplicity and is not generally fixed to this value. Accordingly, this value needs to be redefined;
- The monthly calculations have to be stored because I need it for further calculations.
beta = sym("beta", [1 2]).';
phi = sym("phi", [2 2]);
In k1 we calculate a matrix of the following form:
In k2 we have a similar expression, but now it also depends on phi times the previous period.
K2 = beta * beta.' + phi * K1
In period k3 it is the same as in k2, only that K1 changes to K2. So from here on it is recursive and repeats itself. So for the last observation (k6) it is the same formula with K5.