Tuesday, March 15, 2016

SIM6: updated SIM to preserve time constant (Tc) and G&L's accounting equations

This post updates SIM to preserve the system time constant (thus making the dynamics invariant to the sample period). And like SIM, all G&L's expressions are satisfied. This is accomplished by using the same mechanism as was used in SIM, but replacing not just alpha2 when Ts is changed, but alpha1 as well.

I updated the sheet so that as an option you can edit the "master" green cells under the results table to set Ky, Tc and Kh, which in turn determine the green cells in the upper left (alpha1_0, alpha2_0 and theta). This is to demonstrate the equations in SIM7. Or you can just edit the cells in the upper left directly (thus breaking their link to the lower "master" green cells -- to reestablish the link, reload the page).

Scroll to the right to see the columns which do the calculations. The columns immediately under the chart are what's plotted.  Note that Γ is the Γ that Jason defined as ΔH/(G - T) :=  Γ, not the Γ I define in SIM4. The goal is to keep Γ = 1 here (to satisfy G&L's expression). As T approaches G as t -> inf, this ratio becomes numerically unstable (0/0), so it's really only valid before that happens (at the early times).

The only curve that truly represents an accumulated value is the single state variable H (money supply or cash in the economy). The curves G, Y, T, YD and C are all scaled by 1/T_ratio when plotted. You may notice the curve C and some of the others seem to change slightly (other than just the interpolation between more widely separated sample points). I'm not sure why that is [Update: see paragraph below], but it may be because there's one more degree of freedom I haven't yet tried to adjust: namely the balance between alpha1 and theta. [Update: I don't think so because it works with theta the way it is now (see below)]. But the main dynamics captured by curve H are truly invariant [Update: as are the others, it's just that they represent average rates over each interval, so they are fundamentally different than H and dependent on the sample times: see below] to the sample period: the points sampled are always from the same underlying (and unchanging) continuous curve, with only the linear interpolation between them (on the plot) showing any difference (which is entirely an artifact of the plotting procedure).

"I'm not sure why that is,..." At least part of the reason is Y, T, YD and C are still plotted at rates (so is G, but it won't have this problem as explained above): rates effectively estimated from differencing underlying and uncalculated integrals of each of them between sample times. Thus even if those underlying integrated curves were exactly the same for different sample periods, estimated rates calculated in that manner would still differ from one another if Y, T, YD and C are anything except constants (G is a constant, and thus does not have this problem) for t >= 0, assuming they are all 0 for t < 0. As an example, consider the function y(t) = t^2. If sampled with period = 2 at t=0 and t=2, the answers would be y(0) = 0 and y(2) = 4. If I calculated a rate based on differencing and plotted that at the end of the sample period I'd have at t=2, ydot(2) = 4/2 = 2. Now imagine the sample period is 1. Then I'd get y(1) = 1, y(2) = 4. An estimated rate based on those samples plotted at t=2 gives me ydot(2) = (4-1)/1 = 3. The only fair way to compare them is in terms of y, not ydot. The ydot's represent accurate average rates over each sample period. So if I just had access to the ydots from each set of samples, I could use them to reconstruct y in both cases, and those should match (assuming ydot(0) = 0 in both cases).

Sample period = 2:
y(2) = ydot(2)*2 = 4

Sample period = 1:
y(2) = ydot(2)*1 + ydot(1)*1 = 3 + 1 = 4

I need to do that exercise (calculate integrated Y, T, YD and C curves) for two different sample periods, one an integral multiple of the other, and see if they match at those sample times that they have in common. I still suspect that there may be a problem with my extra degree of freedom (I mention above), but we'll see. [UPDATE: 2016.04.22: I don't think there's a problem with this so-called "extra" degree of freedom: see equations 4, 4A, 6, 6A and 9 in SIM7. They demonstrate that theta, and theta alone determines the steady state gain of Y, YD and C (at a fixed sample period). Scaling the sample period should scale those steady state gains by the same value, thus there's no room for us to fool with theta, else it would change the steady state gain for Y, YD and C to a wrong value if we did. So the answer is there is no extra degree of freedom! In fact, one way to think about what's going on in this post (SIM6) is in terms of  SIM7: here in SIM6, we're effectively using equation 10 from SIM7 to set alpha1 (given we don't want to change any steady state gains, and thus we can't change theta). We do that by changing the time constant Tc in equation 10. You might object saying "I thought the goal of this post was to keep the time constant fixed!" Yes, that's true, but you can think of changing Tc in eq. 10 such that it's the value of the old (fixed) time constant but expressed in terms of our new sample period. For example, say originally Tc = 6 original sample periods, and we want to change the sample period from 1 to 2, then in terms of the NEW sample period, Tc looks like just 3 (3 new sample periods, which are twice as big as the old sample periods). So after figuring out what Tc will be expressed in new sample periods (our goal sample period), then use SIM7 equation 10 to find alpha1, and then use SIM7 equation 11 to find alpha2. I *think* that's the same as what I'm doing here (but I haven't actually done the math to verify it)].

UPDATE: Just did that exercise. You can find the results by scrolling out further to the extreme right on the spreadsheet, where I compare Y, T, YD and C integrated and then sampled with sample period Ts against the next table to its left showing a copy of  the values integrated with default Ts = Ts_0 = 1 (the yellow cells in both tables). They are the same at identical sample times (chose Ts as an integral multiple or fraction of Ts_0 so some sample times will coincide), so my underlying integrated versions of Y, T, YD and C are invariant with sample period. 

Also note that G_Rate in fixed units of dollars/(Ts_0=1 year) can be edited in the green User Input cells in the upper left of the spreadsheet, but you can also just overwrite the values in the green cells in the 2nd table (the results calculation table) immediately to the right of the table of plotted values under the chart. More information about how to do that in a sample period invariant way in this comment on Brian Romanchuk's blog repeated here for convenience:

I did not attempt to make this work with any other functions for G other than a scaled unit step. You can choose G&L's $20/period to match theirs, or any other. More general G functions addressed here. But even with the spread sheet above, you could make it work for G at a constant rate per period, by typing over the G values in the calculation table: so long as you matched the function precisely: for example originally you may have G be $20/period for period 1 and then $40/period for period 2. If you halved the sample rate to 0.5 periods, then you'd leave G at $20/period (=$10/half-period in the spreadsheet) for the 1st 2 sample periods, and then switch it to $40/period (=$20/half-period in the spreadsheet) for the next two, etc.


Note in a comment here by me about Jason's formulation of ΔH = Γ*(G - T) and how Γ is equivalent to the approximate adjustment for a new sample period (Ts2) in my original SIM formulation, except without  changing the sample times on the plot (thus approximately scaling the time constant). In this case Γ plays the role of the alpha2 and B scalar Ts2/Ts1 = T_ratio. 


Expressions from the spreadsheet's table repeated below for convenience:

Matrix Element Name Expression
A (1,1) A_0  1-theta*alpha2_0/(1-alpha1_0*(1-theta))
B (1,1) B_0  1-theta/(1-alpha1_0*(1-theta))
Cm (1,1) CY  alpha2/(1-alpha1*(1-theta))
(2,1) CT  theta*alpha2/(1-alpha1*(1-theta))
(3,1) CYD  (1-theta)*alpha2/(1-alpha1*(1-theta))
(4,1) CC  alpha2/(1-alpha1*(1-theta))
D (1,1) DY  1/(1-alpha1*(1-theta))
(2,1) DT  theta/(1-alpha1*(1-theta))
(3,1) DYD  (1-theta)/(1-alpha1*(1-theta))
(4,1) DC  1/(1-alpha1*(1-theta)) - 1

Description Name Expression
sample prd ratio T_ratio Ts/Ts_0
A(T_ratio) A A_0^T_ratio
B(T_ratio) B (B_0*(A-1)/(A_0-1))/T_ratio
alpha1(T_ratio) alpha1 ((1-B)-theta)/((1-B)*(1-theta))
alpha2(T_ratio) alpha2 (1-A)*(1-alpha1*(1-theta))/theta
orig. time const. Tc_0 -Ts_0/LN(A_0)
Tc(T_ratio) Tc -Ts/LN(A)  [note: you should have Tc = Tc_0]

No comments :

Post a Comment