Sunday, March 6, 2016

Answer for Henry #1

Below is my answer to a question posed by Henry on Jason's blog.

"My question is do these terms make sense"

Examining those terms in isolation is misleading. I'm NOT saying the whole expression makes sense (as per Jason's point, I think), but looking at those terms in isolation and examining their sensical-ness (new word) is the wrong approach. For example, what if I told you that x(t) -> inf as t -> 0 and y(t) -> inf as t->0, is it possible that x(t) - y(t) could approach something meaningful as t -> 0? Of course it is, because I'm interested in their difference, not the individual terms.

Allow me to take a stab at explaining the issue in a way that perhaps isn't as general as Jason's approach, but which I nonetheless find to be clearer. Going back to his definition:

γ := rate of government spending, in dollars/year (say)

But instead of making ξ := rate of taxation in dollars/year, let's leave that out of it. Now say

ΔH[n+1,n] = H[n+1] - H[n] = γ*Δt - T (abandoning your <> notation in favor of [] because of technical difficulties)

Now lets say (as is the case in the SIM model if you do the algebra) T = r*H, with r a fraction (a constant fraction to make it simple, say on (0,1), defined as a rate per unit of time τ, which initially happens to be τ = Δt, but of course will not hold if Δt changes), or putting indices on it:

T[n+1,n] = r*H[n]

Now we have:

[n+1,n] = H[n+1] - H[n] = γ*Δt - T = γ*Δt - r*H[n]

To simplify further, set γ = 0 for now, so we have:

H[n+1] = (1-r)*H[n] = A*H[n] where A = 1-r

This has a well known solution:

H[k] = H0*(A^k), for all k >= 0, and where H0 = H[0] (i.e. H0 is the initial allotment of money in the economy).

And because r is on (0,1) then so is A, so this will be an exponentially decaying function (a sampled exponential).

Now what happens if we change our sample period Δt? Well r doesn't change, nor does τ it's defined over, but

(1) H[n+1] =
A*H[n] = (1-r)*H[n] 

No longer holds. Why? Imagine that it did hold, and that say r = A = 0.5. So in one time step Δt, half the money disappears from the economy through taxation. If Δt = τ = 1 year to start out, then in 1 year half the money is gone. Now say Δt is reduced to 1 day... then if equation (1) still held, then in one day half the money is gone. Thus (1) would NOT be describing the same system. We're sampling an underlying continuous time system, so we have to account for that. The real rate of decay (time constant) of the system should be independent of the sample period. The answer is we need to adjust A as Δt changes, because A was always an implicit function of Δt (i.e. A in (1) is A(
τ), and so is only valid when Δt = τ). We can write a valid version of (1) if we adjust A for when Δt τ as follows:
(2) A(Δt) = A(τ)^(Δt/τ)

So then using (2) our valid version of (1) for any Δt is as follows:

(3) H[n+1] = A(Δt)*H[n]

Now in this simple case, it turns out that 1-r*Δt/τ
A(Δt), but it's not exact. Also, in the limit as Δt -> 0 we have A(Δt) -> 1, so our difference equation (1) breaks down. We need to replace it with a differential equation:

dh/dt = (ln(A)/τ)*h = a*h, where ln() is natural log

and where a = ln(A)/τ, and H[n] = h(n*Δt). Note that a < 0 in this example because A is on (0,1)

The solution to this equation is:

h(t) = exp(a*t)*H0

That's the underlying continuous time system. Since a < 0, it's a decaying exponential, as before. We can sample it at any Δt we choose:

H[n] = (exp(a*Δt)^n)*H0

or in difference formula form:

H[n+1] = exp(a*Δt)*H[n]

Which suggests an alternative formulation of equation (2) when the continuous-time time constant -1/a is known [1]:

(4) A(Δt) = exp(a*Δt)

I leave as an exercise to the reader the case where γ > 0. :D

[Hint, try this]

Or if you want to see it worked out for the SIM example, look at how I calculate B here at the bottom.

What G&L are doing amounts to assuming that (2) below (the first two terms of (1) (also below)) is a  good approximation, and I think they try to restrict alpha1, apha2 and theta to accomplish that. But even with those restrictions, (2) can sometimes be a terrible approximation for (1). Either that or they are assuming the rate of compounding always matches the sample rate. Note that in the more general case where we substitute square matrix A for  a, (1) and (2) still hold, provided we take A raised to n to represent A matrix multiplied by itself n times in (1), and substitute the identity matrix I for 1 in (2).

Discrete and continuous time system equivalents, where H[n] = h(n*Ts), etc. Ts being the sample period


[1]  -1/a is defined as the time constant of the decaying exponential. It's the time t  > 0 by which the exponential has decreased from it's value at t=0 (unity) by 63%, or equivalently, decreased down to 37% of 1: since if t = -1/a, then exp(a*t) = exp(-1) 0.37.


  1. Tom,

    I stopped reading when you introduced your definition of T, making it a function of the money stock.

    In the G&L model T = rY. It's a function of income given by the fixed proportion r.

    You have also given r a time dimension.

    Can you explain why you have done this?


    1. 1) if you do all the algebra in SIM you'll end up with

      H[n+1] = A*H[n] + B*G[n+1]

      Where G = γ is the rate. I have all the expressions written out in my SIM2 post (navigate there on the right). So it really does reduce to basically the same thing. A and B are ONLY functions of alpha1, alpha2 and theta.

      2) Rather than get into all that I was trying to build on Jason's simplified example which leads to the same functionality form as the actual SIM model but without as much algebra involving those three SIM parameters.

      3) The way Jason does it doesn't go far enough to allow him to construct a differential equation. He tried, but he made a mistake and erased that part of his update #5, remember? I'm completing that thought for him in a way that actually matches the function form for what's going on in SIM.

      4) Why construct a differential equation? I think it's the clearest way to understand where the implicit time scale parameter comes in. In my example above I call that parameter τ, but you can also use -1/a as a time scale parameter, which I discuss in the post, explaining why I call that the system's "time constant" in footnote [1]. That's a standard definition of time constant BTW, that you'll find in any text. I needed to get to a differential equation to get there, which is why I take this route. Jason had the same before erasing it in update #5.

    2. 5) In my post above, had you kept reading, you'd have seen I make the connection to a differential equation by at first simplifying still further by assuming γ = 0, so essentially you have just:

      H[n+1] = A*H[n]

      Which is all you need to find the system's time constant. Putting gamma (γ) back in doesn't change the system's time constant.

    3. Just for completeness, in SIM the expression above works out to have A and B defined like this:

      A = 1 - θ*α2/(1 - α1 + θ*α1)
      B = 1 - θ/(1 - α1 + θ*α1)

      Where the α are SIM alpha parameters, not the "a" related to the system's time constant I discuss above. Implicit in those definitions though is Δt = τ, where τ = 1 "period" (as G&L say in their book), which I just call 1 year in my SIM2 post, to give it a name. G&L don't explicitly make the point that Δt = τ. They don't even acknowledge there being a separate τ or a time constant, which was Jason's point, I think.

      If you were to change Δt do that it was no longer equal to τ, then those expressions above for A and B would no longer be valid.

    4. Last paragraph, should read:

      "If you were to change Δt so that it was no longer equal to τ..."

    5. Tom,

      Still can't see how you have T = rH.


    6. If you do the algebra you get:

      T[n+1] = CT*H[n] + DT*G[n+1]

      Where the values of CT and DT are *ONLY* functions of alpha1, alpha2 and theta. The expressions for them can be found written out in the table I provided in this spreadsheet (lower left corner).

      Check my math if you like, but I'm pretty sure those are correct.

  2. OK Tom, I'll go back recheck my algebra.

    1. Keep in mind that I treat G, Y, T, YD and C as rates, and I don't change the units (I keep them in dollars/year). Thus they are the same as quantities when the sample period = 1 year. I did that because that's just how I'm used to dealing with difference equations... and I must say it did lead to some confusion (on my part) about what Ramanan was suggesting I do to change the sample period (i.e. scale alpha ... in my case I needed to scale alpha AND convert my rates into quantities over each sample period, which he naturally assumed I was already doing). In my defense, keeping them in constant units is typical in the engineering world: you don't change from amperes to electrons per February, or to coulombs just because you change the sample period or change from continuous time to discrete time (analog to digital). Also doing it that way does not change the system dynamics of the assumed continuous time system you're sampling.

      The trouble with the "scale alpha" approach is it actually changes the system dynamics. In the case of SIM with default parameters, not much (a total of 14% difference in time constant from Ts=1.5 (the max it can be if alpha1 is kept < alpha 2 as G&L specify), down to lim as Ts -> 0). With other parameters, however, the time constant can change by as much as 690%. Also "scale alpha" restricts Ts < alpha1/alpha2. There's no such restriction in my version of the time scaling (my SIM2 post): you can make it as large as you want. Making Ts above 6.5 in the scale-alpha approach (my SIM post), causes the system to start to oscillate.

      Today I make a 3rd version (SIM3) which restricts G to be a scaled step function (actually Gdot = dG/dt using my names in that post), but it gets the best of both worlds from SIM and SIM2:

      1. Matches G&L's SIM at Ts=1 (as both SIM and SIM2 do)
      2. Is completely invariant to selection of Ts (as SIM2 is)
      3. Satisfies ΔH = G - T (ΔH = ΔG - ΔT given my definitions for G and T in that post) for any pair of sample times (as SIM is).

      How did I do it? I constructed G and T as the integrals from t=-inf of total gov spending and total taxes collected, respectively. So G is a ramp, and T is asymptotic to the ramp as t -> inf.

    2. Treating G, Y, T, YD and C as rates should make no difference to you if you keep the default sample period = 1 when doing your algebra.

    3. Haven't gotten around to doing the algebra - too many other priorities at the moment, one of them being sleep.

      Anyway, I'll catch you soon.


    4. If you look at the plots (Jason's, G&L's or mine), you can see that T has the form constant*(1 - exp(a*t)) with a < 0; in other words the same form as H. That in itself should make my formula for T look plausible, without any algebra at all.

    5. ... and actually, that's the same form the other output variables have, all with the same time constant Tc = -1/a that H has (Tc = 6 years with the default parameters), which is an indication that they're all just scaled versions of the same underlying state variable. You have to do the algebra to realize that state variable is H, or just notice that in G&L's equations, H is the only variable that appears with indices of both n and n-1: all the others only have index = n. That's an indication right there that there's just one state producing the "dynamics" (i.e. 1-e^at) for the whole system. Typically the dynamic producing state variables (x) are written with that feedback notation: x[n] = A*x[n-1], where more generally x is an N vector (N states), and A is an NxN matrix: thus more generally there'll be different "time constants" involved, some stable (diminishing) some unstable (growing) and some oscillating. On a block diagram, the only loop would be to generate x, or in this case H.

    6. Looking just at the loop part, replace H[n+1] with dh/dt, the "Delay by one" with integrate over t, H[n] by h(t), and A with a = log(A)/Ts, and the same diagram works for the continuous time case:

      dh/dt = a*h

      with H[n] = h(n*t). Furthermore replace B with b, where B = (A - 1)*b/a, replace G[n+1] with g(t) such that G[n] = g(n*t), and restrict g to be a step function (held constant over each interval Ts), and that same diagram works for the continuous time case with an input:

      dh/dt = a*h + b*g

      The rest of the diagram doesn't change.

    7. ... you may wonder about the restriction on g (a step function). We can avoid that restriction if we have more Bs: for example, if g(t) is completely defined over a sample interval by G[n] = g(n*Ts) + g's first m time derivatives evaluated at n*Ts then a row vector B = [B0 B1 ... Bm] will work to do the equivalent of b, provided we also have access to g, g', g'' ... etc, out to the mth time derivative, all evaluated at t = n*Ts.

      Also, above I meant to write H[n] = h(n*Ts) and G[n] = g(n*Ts)

    8. Henry, OK, I fleshed out the case where g' = can be expressed as a Taylor series + Dirac deltas, where g represents the integral of all government spending. I called it SIM4, and it's just the math. I think it's right. ... as if you care! Lol

  3. Hi Tom,

    'as if you care!"

    I could ask whether you care whether I care - I know this is an exercise that you would have done for yourself, I'm sure. :-)

    I've been away to a music festival for four days while you've toiled away with the math.

    I have to get my head around the techniques and concepts you've used.


    1. Hi Henry,
      Hope you had fun!
      Yes, for myself. It's true. ;D Brian Romanchuk has done a couple of related posts as well:

    2. BTW, how do you like my side-by-side continuous vs discrete time block diagrams above (you can click on it to get a bigger picture)? Well, it's not quite right... or rather my nomenclature is inconsistent. The government spending exogenous input on the continuous time model should really be dg/dt (or g' or gdot) instead of g() to be consistent with my expressions I later wrote here (SIM4). In fact I originally had g', but erased all the ' marks after I turned it into a .pgn. Oh well.

      Or, if no steps in g() occur (equivalent to Dirac delta's in g'()), then lower case gamma (γ) would work too (which is consistent with Jason's use of γ as well, BTW). However my use of upper case gamma (Γ) in SIM4 is not consistent with Jason's usage: he uses it for a multiplier on G - T (which honestly, I still don't get the point of: I think I'll work out what that means in terms of a difference equation in the style I have above, and I'll bet you it just works out to be a scalar (or modifier) on the time constant of the system).

    3. ... maybe I'll refer to Jason's Γ as Γj.

    4. ... one last thing: I tried to write up a summary of all these posts in yet another post (SIM5), and also to explain my last bit of effort (unfinished): namely that I think I can write theta, alpha1 and alpha2 as functions of Ts1 and Ts2, where Ts1 is the original sample period of "1 period." It looks like I just need to solve a quadratic... hopefully one solution will be easy to identify as wrong (like it's negative, for example).

      Then that combined with SIM4 should give me:

      1. Sampler period invariance (theta, alpha1 & alpha2 ajusted to keep Tc constant)
      2. Match G&L's SIM at Ts=1 (with Ts=Ts1, theta, alpha1 and alpha2 will be the default values)
      3. Satisfy all G&L's accounting expressions for any Ts (since theta, alpha1 & alpha2 all change together)
      4. Be able to accept a wide class of exogenous input government spending functions g'() (results of SIM4)

      Who cares? Probably just me at this point. Lol.

    5. Also DT in those block diagrams is too complicated: a little algebra reveals that

      DT = CT/alpha2 = theta/(1 - alpha1*(1-theta))

      I changed all the posts where all those parameters are listed to simplify any I'd left unsimplified before.