Thursday, April 7, 2016

SIM8: discrete time and continuous time state space system matrices

The discrete time and continuous time system matrices of G&L's SIM model written as composite arrays: first the discrete time:
$$

\left[

\begin{array}{c|c}

A_d & B_d \\

\hline

C_d & D_d

\end{array}

\right]_{SIM_d} =

\left[

\begin{array}{c|c}

1-\frac{\alpha_2 \theta}{1 - \alpha_1 (1 - \theta)} & 1-\frac{\theta}{1 - \alpha_1 (1 - \theta)} \\[1.5ex]

\hline

\frac{\alpha_2}{1 - \alpha_1 (1 - \theta)} & \frac{1}{1 - \alpha_1 (1 - \theta)} \\[1.5ex]

\frac{\alpha_2 \theta}{1 - \alpha_1 (1 - \theta)} & \frac{\theta}{1 - \alpha_1 (1 - \theta)} \\[1.5ex]

\frac{\alpha_2 (1-\theta)}{1 - \alpha_1 (1 - \theta)} & \frac{1-\theta}{1 - \alpha_1 (1 - \theta)} \\[1.5ex]

\frac{\alpha_2}{1 - \alpha_1 (1 - \theta)} & \frac{\alpha_1 (1-\theta)}{1 - \alpha_1 (1 - \theta)}

\end{array}

\right] \tag 1

$$
and now the continuous time assuming the input $\dot{g}$ is held constant over each period corresponding to the sample periods of the discrete time case (if that's not the case, or to see why I call the input $\dot{g}$ rather than $G$ see my posts SIM4 and SIM7):
$$

\left[

\begin{array}{c|c}

A_m & B_m \\

\hline

C_m & D_m

\end{array}

\right]_{SIM_m} =

\left[

\begin{array}{c|c}

\frac{1}{T_s} \log\left(1-\frac{\alpha_2 \theta}{1 - \alpha_1 (1 - \theta)}\right) & \frac{\theta + \alpha_1 (1-\theta) - 1}{T_s \alpha_2 \theta} \log\left(1-\frac{\alpha_2 \theta}{1 - \alpha_1 (1 - \theta)}\right)   \\[1.5ex]

\hline

\frac{\alpha_2}{1 - \alpha_1 (1 - \theta)} & \frac{1}{1 - \alpha_1 (1 - \theta)} \\[1.5ex]

\frac{\alpha_2 \theta}{1 - \alpha_1 (1 - \theta)} & \frac{\theta}{1 - \alpha_1 (1 - \theta)} \\[1.5ex]

\frac{\alpha_2 (1-\theta)}{1 - \alpha_1 (1 - \theta)} & \frac{1-\theta}{1 - \alpha_1 (1 - \theta)} \\[1.5ex]

\frac{\alpha_2}{1 - \alpha_1 (1 - \theta)} & \frac{\alpha_1 (1-\theta)}{1 - \alpha_1 (1 - \theta)}

\end{array}

\right] \tag 2

$$
where $T_s$ is the sample period of the discrete time model. Writing the system equations in such a format allows you to easily interface with a rich set of MATLAB or Octave (open source) tools, for example the MATLAB ss() function (Octave version here). You'll be writing $H_{\infty}$ or $\mu$-sythesis robust interest rules for your central bank in no time!

Update 2016.04.23: Note that the $m$ subscripts (which I just changed: they used to be $c$ for "continuous") in the continuous time case here stands for "mean" as this particular set of continuous time equations produces as outputs values that actually represent average (or mean) rates over the discrete time sample period. This is because of a peculiarity of stock-flow consistent (SFC) models in their discrete time format. The "flows" (corresponding to the input and measurements (AKA outputs) in SIM) are dollar value accumulated over a sample period. Thus if the sample period goes to 0, so do these flow values. You can think of it as expressing an average rate in terms of dollars per current sample period. State space representations in other contexts (such as many engineering uses) do not have this peculiarity. In those cases we're not interested in having our input and output values scale with the sample period (essentially being expressed in varying units which scale with the sample period): we usually want their units to be independent of the sample period. But this isn't a problem with SFC models, it's more of a fact that someone like me has to contend with if they wish to use a state space representation with SFC models.

So there's nothing wrong with using this variety of a continuous time model, as long as you're aware of these facts. However, there is another way of going about constructing a continuous time counterpart to a discrete time SFC model which doesn't attempt to match the values from the discrete time case directly, but instead provide sample period independent continuous time curves, which when integrated over each sample period, match the flow outputs from the discrete time SFC model. Thus you can think of the variables corresponding to discrete time flows in this alternate approach continuous time modeling approach as being instantaneous rates (or "instantaneous flows"). IMO this latter instantaneous rate approach is a better way to construct a continuous time "equivalent" to a discrete time case: it's a bit more difficult to compare with its discrete time counterpart, but it's truly independent of any sample period, and it should obey the SFC accounting identities over any arbitrary interval of time. The former "mean" approach does not have this property, and if you translate to a new sample period, you must change the $C_m$ and $D_m$ measurement matrices as well if you want the values at the sample times to obey the SFC accounting identities. See SIM6 for an imperfect means of doing this (imperfect because it does it through adjusting SIM parameters, but there are some restrictions on the values of those parameters). As for the instantaneous method, refer to SIM9 and SIM10, although I'll probably be providing the equations for that here in the case of SIM when I have time.

The "stock" variables (as opposed to the flow variables) do not suffer from this complexity because they are not integrated over each sample period. They just represent dollars (for example), at a particular time, not dollars accumulated over a sample period. In SIM there's only one stock: the total cash circulating in the economy (H), which is also the only state variable (in both the continuous and discrete cases). End Update.

The operation of the system described in such a manner can be expressed with a single matrix-vector multiply equation in both cases:
$$
\left[
\begin{array}{c}
x_{n+1} \\
\hline
y_{n}
\end{array}
\right] =
\left[
\begin{array}{c|c}
A_d & B_d \\
\hline
C_d & D_d
\end{array}
\right]_{n}
\left[
\begin{array}{c}
x_{n} \\
\hline
u_{n}
\end{array}
\right] \tag 3
$$
$$
\left[
\begin{array}{c}
\dot{x}(t) \\
\hline
y_m(t)
\end{array}
\right] =
\left[
\begin{array}{c|c}
A_m & B_m \\
\hline
C_m & D_m
\end{array}
\right]_t
\left[
\begin{array}{c}
x(t) \\
\hline
u(t)
\end{array}
\right] \tag 4
$$
where the subscripts on the discrete and continuous time composite system matrices, $n$ and $t$ respectively, indicate a possible time dependence (which is not the case with SIM). I guess I should mention that in discrete time:
$$x_n = H_n \tag 5$$
$$u_n = G_{n+1} \tag 6$$
$$y_n =
\left[
\begin{array}{c}
Y_{n+1} \\
T_{n+1} \\
Y_{Dn+1} \\
C_{n+1}
\end{array}
\right] \tag7
$$
where $y$ and $u$ are offset by one index relative to the associated SIM parameters so that $(3)$ can be in canonical state space form. For continuous time we have:
$$x(t) = h(t) \tag 8$$
$$u(t) = \dot{g}(t) \tag 9$$
$$y_m(t) =
\left[
\begin{array}{c}
\dot{y}(t) \\
\dot{t}(t) \\
\dot{y}_D(t) \\
\dot{c}(t)
\end{array}
\right] \tag {10}
$$
2016.4.10: 4:49 AM: NOTE: The following section will change because it's not quite right: $\dot{g}, \dot{y}$, etc represent the average rates over the preceding sample periods. However it's approximately correct as it stands (see SIM10 and SIM9 for  more information).

2016.04.23: 3:00 AM: I went ahead and removed the last bit of this post until I have time to fix it. See the update above at this same date and time.

6 comments :

  1. Your results and presentation are absolutely beautiful. I am making progress, still putting the pieces together in my mind.

    I must take my wife to the doctor out of town. Will do a lot of thinking on the way.

    ReplyDelete
    Replies
    1. I've already made a small but important update to $(6)$ and $(7)$ which I explain in the text immediately below $(7)$ regarding the indices and canonical state space form.

      There are more updates to come because I realize that the continuous time equations have different possible realizations... depending on whether you want to match the average rate over the associated discrete time sample period at the sample times, or if you want to report the instantaneous rate at a particular sample period. Most people who work with state space representations are interested in the instantaneous rate, however, SIM is geared toward the average rate over an associated discrete time sample period... thus I'm afraid some things will change. But if you stick with the discrete time equations for now you should be OK, and if nothing else the continuous time equations are approximately true (depending on what you want to do with them). More to come!

      Delete
    2. ack from the doctor's trip for my wife. All is well, and she is better!

      "depending on whether you want to match the average rate over the associated discrete time sample period at the sample times,"

      OK, So far, I am intellectually following your idea that the only state we are updating is the wealth state. G just adds an increment to that state. My Master Equation starts from zero plus memory plus G. $$0 + G + \alpha 2 H_{-1} $$ It integrates those based on
      $$\frac{1}{ \theta - \theta \alpha 1 + \alpha 1} $$

      Now, I am going to read these beautiful matrices and try to place my Master Equation into matrix form. I am a long way from that goal.

      Delete
    3. Hi Roger,
      I'm glad your wife is OK!

      My matrices: if you undertake that project, I'd suggest you start with the discrete time case. For the continuous time case, I have an idea of what I need to change in mine to make the story more complete, but I haven't worked it all out yet. The discrete time case doesn't require any further thought... it's good as it stands.

      Also you'll note I could have introduced my old notation for X and saved a lot of repetition in those matrices. X is not the best name for it... especially now that I have a canonical $x$ in there... but it could do with some simplification.

      Good luck!

      Delete
    4. Hi Tom,

      I edited my http://mechanicalmoney.blogspot.com/p/mathjax.html

      I will try to understand Octave and write a matrix. That is next.

      Your equations for SIM as-is look pretty good to me! I keep referencing them as I try to translate my Equation. 10. Time for dinner.

      Delete