Monday, March 21, 2016

Sunday, March 20, 2016

Japan Philips Curve Regression 2005.02 to 2015.02

This is me trying to recreate either Jason's or John's results from this post, and in particular, this comment.

The data I do the regression on is copied up to the top (yellow cells) under the right side of the chart in columns H and I (starting at row 30) labeled ΔEMP and ΔCPI. The ΔEMP represents a 12 month difference. These cells were copied from the big table to the left, down at the bottom (stopping at row 380) and also colored yellow. My results don't seem to match either Jason or John. Not a surprise since I'm probably doing it wrong.

Instructions for repeating what I did:

First download the data from FRED (following John's link) in Excel format. Or just download my spreadsheet (icon in lower right corner of sheet). From here on I'll assume you've downloaded my sheet (so the differences have been computed and data copied to look like mine). Select the "Data Analysis" option on the "Data" tab and then the "Regression" sub-option. You may need to download and install a Data Analysis  plug-in first. For the y values select the column of yellow cells including the  ΔCPI label at the top starting at I30. For  the x values select the column of yellow cells immediately to the left of that including the ΔEMP label at the top (starting at H30). I selected the option check-box to output the analysis on a new tab (which I called "Regression"). That's all.

For the plot (which I did separately) I used the linear regression ("show trend?") built directly into the scatter plot options. Another option there lets you display the the equation for the linear trend and the R squared value. I found that after making the plot and then looking at the options associated with the data series. The answers should match the Data Analysis results!






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]

Sunday, March 13, 2016

SIM5: summary and to-do

This post is meant to be a stand-in for an eventual fully fleshed out post tying my previous posts on this subject together: namely SIM, SIM2, Answer for Henry #1, SIM3 and SIM4. A brief summary follows:

SIM: 1st attempt to code up G&L's SIM in a spreadsheet in a discrete time state space format. It worked the 1st time with the sample period (Ts) set to 1. H is the sole state variable producing the system dynamics, and at first I interpreted the exogenous input G and the outputs (system "measurements") all as rates in dollars/original-period (and I named the original period (Ts1) a "year" for convenience). The outputs are Y, T, YD and C. Ramanan, commenting on Jason's blog, suggested scaling the parameter alpha2 by Ts2/Ts1 to change sample periods, where Ts1 = 1 and Ts2 is the new desired sample period. This didn't work for me at first because I was interpreting G, Y, T, YD and C as rates and I wasn't changing their units to match the new sample period. Naturally Ramanan assumed I would think of these as quantities, not rates, so that their values would scale with the sample period (which amounts to keeping them as rates and changing their units to dollars per Ts2). Once I sorted that out, I redid the spreadsheet and found that scaling alpha2 by Ts2/Ts1 was an OK approximation, but not perfect: the system time constant (Tc) does change, and the reason is G&L are doing one of the following:
  1. Assuming the "compounding times" always precisely coincide with the sample times, so Tc does change when the sample period changes (because it means a different compounding rate).
  2. Approximating continuous compounding by approximating exp(-t/Tc) as 1 - t/Tc
Another problem with SIM the way G&L formulate it is that you cannot select a Ts2 >= Ts1*alpha1/alpha2_orig (where alpha2_orig is the the original value of alpha2 before scaling it by Ts2/Ts1). You can set it to what you like of course, but they specify in their text that 0 < theta < 1 and that 0 < alpha2 < alpha1 < 1. This means starting with their default values for the parameters, Ts2 must be < 1.5*Ts1 = 1.5 periods. You can actually make it bigger (of course) and it works OK up until about Ts2 = 6.5... then the resulting A parameter in the difference equation goes 0 and then it goes negative as Ts2 > 6.5. This results in wild oscillations in the curves as Ts2 gets up to values like 10 or 20. But following G&L's restrictions, then varying Ts2 over (0,1.5) brings a variation in time constant (Tc) of about 14% (from a low of about  5.7 at Ts2 = 1.5 to a high of 6.5 as Ts2 -> 0). The default value of Tc with Ts = 1 is about 6 "periods."

SIM2: I started this one when I 1st apparently failed to get SIM to be sample period invariant by using Ramanan's method of scaling alpha2 by Ts2/Ts1. Essentially what I did here was find the equivalent continuous time system and use the time constant from that to find the discrete time state space parameters A and B for Ts2. This amounted to replacing the approximation for exp(-t/Tc) with the exact value. This version did not require changing my interpretation of G, Y, T, YD and C as rates expressed in dollars/(period=Ts1), so naturally I was excited to see that the curves were indeed invariant to the sample period. However, looking at it later and calculating Jason's Γ  = ΔH/(G - T) I realized that Γ = 1 only when Ts=1. So essentially, SIM2 violates stock-flow consistency (SFC), even though H, G, Y, T, YD and C are all sample period invariant. However, I did add an alternative means of calculating the constants CT and DT which are used to produce T: namely T[n] = CT*H[n-1] + DT*G[n]. Using these alternative expressions produces a different T curve, which I added to the plot. It is precisely the same as the original T curve when Ts=1, but differs slightly when Ts ≠ 1. In addition SIM2 has no upper bound on Ts2 (no oscillation problem as in SIM1).

Answer for Henry #1: Not much to say here, except that this is where I introduce  block diagrams of both the discrete and continuous time system equivalents. Note that my naming convention for G and T (and I suppose for the other outputs Y, YD and C) are a bit confusing on the plots up through this one, and in my block diagram as well. That's because of the confusion about G being dollars, or dollars per period=Ts1 or dollars per period=Ts2, etc.

SIM3: Here I was determined to get the best of both SIM and SIM2: Namely match G&L's SIM with Ts=1, have sample period invariance and satisfy all of G&L's equations over any sample period (or more generally, between any two arbitrary sample times). I accomplished that goal with some qualifications: 1st I restrict Gdot (Gdot a rate of government spending measured in constant units of dollars/(period=Ts1) to be a scaled unit step function: 0 for t < 0, and constant for all t >= 0. Then H takes the form of Hss*(1 - exp(-t/Tc)), where Hss = steady state H = Gdot*B/(1-A). G (now interpreted as the sum from -inf to t = sum from 0 to t of all government spending) is 0 for t < 0 and Gdot*t for t >= 0. Thus I define T (the sum from 0 to t of all taxes collected) as T = G - H. This has the effect of both making the system sample period invariant and forcing it to satisfy G&L's accounting equation (i.e. Γ = 1, once you  use the right version of G and T (the confusion with symbols in this post continues)), and (of course) forcing it to agree with G&L when Ts=1. However, I didn't check Y, YD or C, only H, G and T.

SIM4: This post does not include a spreadsheet, but it does document the math required to extend SIM3 to accept more general G functions and to turn it back into an iterative state space discrete time difference equation. In this post I explicitly show the connection between the continuous time formulas and discrete time formulas for a broad class of G functions (really g functions). Also, I make an attempt to provide consistent variable names: both internally consistent and consistent with G&L. Namely, G and T become quantities again, measured in dollars, and thus dependent on the sample period length. The math is mostly done in relation to g = sum total of all dollars spent by the government, and it's derivative gdot (or g') (and a lower and upper case gamma (γ and Γ respectively), and some Dirac delta components of g', which I refer to by gm, giving us the ability to introduce step functions into g). Like SIM3, this model does not attempt to sort out or check what Y, YD or C are or ensure I have the correct expressions for them so that they always satisfy G&L's accounting equations.

---------------------------------------------------------------------------------------------------------

SIM5: Which brings us to the point of this post. The bit I'm missing in all but the non-sample-period-invariant SIM above is ensuring that ALL of G&L's accounting equations are always satisfied between any arbitrary sample times. I can get ΔH = G - T to be satisfied in all of them (using T-alt in SIM2), but not necessarily the rest. This got me thinking about a couple of strategies:
  1.  Starting with SIM 1, which guarantees that all G&L's accounting equations will always be satisfied, it occurred to me that I can adjust alpha2 for a new sample period (Ts2) from the original sample period (Ts1=1) in a way other than scaling it by Ts2/Ts1: Given that A1 is the original feedback parameter (see SIM1), I can calculate a new alpha2 like this: alpha2 = (1 - A1^(T1/T2))*(1 - alpha1*(1 - theta))/theta (where alpha1 and theta are the original values). This preserves the time constant (Tc), but probably messes up the steady state value, so I'd need to adjust B1 as well (this change to alpha2 will produce a new A, which I'll call A2). But this may lead to having to change all the "C" and "D" parameters (the former used to scale H[n-1] and the latter used to scale G[n] such that their sum produce the set of outputs Y, T, YD and C). Thus really, this will probably lead to having to adjust alpha1 and theta as well, so that all the accounting equations are always satisfied. [Update 2016.04.22: Just alpha1 actually. See the update this date in SIM6]
  2. Starting with the alternate variables I added to the SIM2 spreadsheet (alpha2alt, T-alt, CTalt and DTalt), I can actually solve for an alpha1alt and theta1alt [Update 2016.04.22: No, this doesn't actually work for solving for alpha1alt and theta1alt]. I have a feeling doing so will result in the same solution as for strategy 1 above. Note that when Ts=1 these alternative values are the same as the regular values. The original intent was to see if I could find a new CT and a new DT when Ts = Ts2 ≠ 1 that would always satisfy ΔH/(G - T) := Jason's Γ = 1. (Note that Jason's Γ Γ in SIM4). I could by starting with T = G - ΔH and solving for CTalt and DTalt. Then I can use the fact that CTalt = alpha2*DTalt when Ts=1 (since when Ts=1, CT = alpha2*DT) to find a new alpha2alt = CTalt/DTalt when Ts ≠ 1. I can then use other expressions in the table of expressions for coefficients in the lower left of the spreadsheet in SIM to solve for thetaalt in terms of alpha1alt, and then to solve for alpha1alt, and back-substitute to find a value for thetaalt. Essentially I'll be finding a new set of parameters to go with the new sample period (Ts2), and thus all G&L's accounting formulas should continue to be satisfied.
  3. It occurred to me that I could adjust theta, alpha1 and alpha2 for a new sample period Ts2 by assuming they are currently representing the effective rate for continuously compounding over the default sample periods Ts1 = 1. G&L's (Ramanan's) procedure of only scaling alpha2 by Ts2/Ts1 is an approximation to this, assuming continuous compounding. They only scale alpha2 because it's the only one multiplying the total accumulated cash (H) in the economy, while both alpha1 and theta scale quantities which only apply that particular sampler period. Thus for example, if Ts2  = 1/4, then they scale alpha2 by (1/4)/1 = 1/4. But if we assume that exp(x*Ts1) = 1+alpha2, then x = log(1+alpha2)/Ts1, and scaling to Ts2 would give alpha2_new = alpha2(Ts2) = alpha2^(Ts2/Ts1)-1. Scaling theta and alpha1 would be slightly different (they'd maintain values much closer to their starting values), but I'm not sure what that would be yet. I don't have a lot of hope that this strategy (strategy 3) will actually work. [Update 2016.04.22: a lack of hope for this strategy is probably a good thing. See SIM6, SIM7, SIM9 and SIM10]
[Update: it's strategy 1. that actually worked. See Update #1 below for more details and a new post demonstrating this]

I did a little more preliminary work on Strategy 2 above and came up with the following:

Using the equation for the original B, I can put thetaalt in terms of alpha1alt:
thetaalt = [(1-Balt) + alpha1alt*(1-Balt)]/(1 + alpha1alt*(1-Balt))

Also this is useful:
1-thetaalt = Balt/(1 + alpha1alt*(1-Balt))

Then using the equation for the original A, I already have alpha2alt (see Strategy 2 above), and replacing thetaalt with the above expression, I get an expression only in alpha1alt, which looks like a quadratic, which I can then solve for alpha1alt and back-substitute into the above to find thetaalt:

(1-Aalt)*(1+alpha1alt)*(1+alpha1alt*(1-Balt)) = alpha2alt*(1-Balt+alpha1alt*(1-Balt))*(1+alpha1alt*(1-Balt))

Then I should have a complete new set of parameters which give me the same time constant Tc (and thus sample period invariance) and because they are a complete new set, simultaneously cause all variables (H, ΔH, G, Y, T, YD and C) to satisfy all G&L's equations. [Update 2016.04.22: Nope]

I'll leave that for another day! 

Note that Brian Romanchuk has been doing some posts on related issues, here and here.

UPDATE #1: March 15, 2016 10:17 PM
Another day has arrived!
Note that what I crossed out above I think had an error in it (or at least it didn't reduce to a quadratic or any other equation that would uniquely determine the parameters, as I'd anticipated). Also I found that theta and alpha1 were not uniquely determined by the equations. But leaving theta as the original value seemed to work best, so I just adjust alpha1 and alpha2 now [Update 2016.04.22: See the SIM6 update of this date about  why "leaving theta as the original" seemed to work best]. The resulting spreadsheet is a direct modification of SIM called SIM6 and it seems to be successful in being sample period invariant and satisfying all G&L's expressions (which I verified by calculated integrated values for Y, T, YD and C for an arbitrary Ts and comparing those with integrated values for Ts=1).
END UPDATE #1

------------------------------------------------------------------------------------------------------------

UPDATE #2: March 17, 2016:

SIM6: A modified version of my SIM post which adjusts alpha1 and alpha2 to keep the time constant fixed when the sample period (Ts) changes. Because  SIM obeys all G&L's expressions by it's construction, then so does SIM6. Also it matches G&L's results with their default parameters (alpha1=0.6, alpha2=0.4, theta=0.2, Ts=1). Tables (that you must scroll all the way to the right to see, using the scroll bar along the bottom of the embedded spreadsheet) integrate Y, T, YD and C so that you can compare these integrated (accumulated) values with a static table for which this was done with G&L's default parameters. This allows you to see that indeed all of G&L's expressions must be satisfied.


To-do: I list some things that could be on a to-do list (for SIM7?) in this comment on Brian Romanchuk's blog: (repeated here for convenience):

"Or you could just keep the continuous time model without any extra terms in b. Then you can do an observability and controllability analysis (easy in this case), do pole and zero placement with a fixed feedback law, add noise to the analysis, design a Kalman filter, design a time varying optimal feedback control law for various objective functions or design a robust control law to achieve a minimum performance level over a whole set of plants that could exist due to our uncertainty about the plant. These things could be done in either discrete or continuous time, but the model is simpler in continuous time"


Saturday, March 12, 2016

SIM4: the math for an updated SIM3 for a broader class of government spending functions.

The below model fleshes out a pair of comments made to Henry here as well as one made to Bill here. If it looks fuzzy, zoom in with your browser (CTRL+) and then refresh the page (it worked for me). It's essentially an update of SIM3.

To do: I'm positive this will match G&L's SIM at Ts = 1 with dg/dt = a constant = G per period. And I'm sure that it will be time invariant if we calculate A and B as shown, while we continue to satisfy ΔH = G - T over any pair of sample times. (I know, because I can force T = G - ΔH). What I don't know is if the other accounting formulas for Y, YD and C will continue to hold at different sample periods (given the way they are all expressed now as a linear combination of H and G with coefficients which are only functions of theta, alpha1 and alpha2) [Update: see new post here]. See here for a listing of what these coefficients are at Ts=1. I suspect I may need to change theta, alpha1 alpha2, or the whole expressions to match different sample periods. This would be akin to interpreting their current values as the result of continuous compounding over Ts=1.


Note that incorporating steps in g(t) (equivalent to scaled and shifted Dirac deltas in g'(t)) in the discrete time version is a bit of a pain in the ass because you have to keep track of when those steps are in time, and constantly check to see if the last sample period (i*Ts to (i+1)*Ts) included any... and then you have to adjust the state transition function (exp(a*((i+1)*Ts-tm)) for each one in the interval (assuming they can happen anywhere (t=tm) withing the sample period). The corresponding element of row vector B for the mth step in g (called gm) would be b*exp(a*((i+1)*Ts-tm)). So if there were a finite number (M) of such steps, you could augment B and Γ each with M more entries. The M extra entries in Γ would always be 0 except when a step occurred over the sample period, in which case the entries corresponding to the steps happening in that sample period would take a value of gm, as per the expressions above (m being the index to gm and tm, ranging from 0 to M-1). So it's not impossible, but messy. At least it's a linear system and the effects from all that stuff just adds together. Allowing a single step at t=0 might be a good compromise (for simulations restricted to t >= 0): it'd be easy to accommodate, and it would allow for easily maintaining sample period invariance. (You could fairly easily allow them at each sample time, but then it wouldn't be so fun if you changed to a new arbitrary sample period).

Also note that I've used a confusing array of notation for variables related to G&L's G (and T) over the past few posts. I think the above document is my most consistent take on it. But just to be explicit:

G[i] = integral of g'(t) over one sample period = g((i+1)*Ts) - g(i*Ts)

T will have a similar definition, and unfortunately lower case t is going to be a mess. So instead I'll define  (ΔH)[i] = H[i] - H[i-1], and from that set T[i] = G[i] - (ΔH)[i]. I didn't do any of that above, but based on SIM3, I know that doing so will satisfy ΔH = G - T (obviously) for all sample periods, but also match G&L's T at Ts=1. I have everything I need above and in the expressions for Y, T, YD and C here to find an expression for T and see if theta, alpha1 and alpha2 need adjustment when Ts changes. I'll leave that as an exercise for another day (SIM5?). Ultimately I want to be able to say what G&L should do to preserve sample period invariance while still satisfying all their equations. If that means the parameters have to be adjusted somehow, then so be it.

If you spot an error, do me a favor and let me know in the comments. Or better yet, download the document (in the bar at the bottom), correct it and email it back to me at brown.tom5@gmail.com. Or if you see a way to improve my notation, let me know. I struggled with allowing step functions in g(t) while  also doing a Taylor expansion of g'(t)... thus I introduced big and little gamma. Perhaps there's a much cleaner way to state the whole thing, while preserving G as G&L define it.

UPDATE 1:
Jason Smith put a post up with an electrical circuit analogy. I solve it with particular values for R and L. Also Brian Romanchuk has another post specifically on G&L's SIM model.
END UPDATE 1.

Note to self: The embedded document above has height set to 1370 and width at 1060 (in case accidentally erase it again!) 

Wednesday, March 9, 2016

SIM3: 1) Matches G&L's SIM @ Ts=1; 2) Invariant to Ts; 3) Always satisfies ΔH = G - T

1. Matches G&L's SIM with the sample period Ts = 1 (year)

2. Sample period (Ts) invariant

3. Satisfies ΔH = ΔG - ΔT over all intervals [1]

To do: calculate Y, YD and C and check that they also satisfy G&L's equations over any pair of sample times.

Limitations: Gdot := dG/dt restricted to scaled step function with step at t=0. Note that this is not a fundamental limitation of the approach, it just represents more work to add generality, and this was just a quick and easy check to make sure I could do numbers 1, 2 and 3 above.

UPDATE 1: March 12, 2016, 4:54 PM
I generalized the approach below in a new post called SIM4 to handle a much broader class of government spending functions. I just did the math at this point. If you find an error, let me know (see the note under the document of equations).
END UPDATE 1

Notes:
[1] My ΔG here is called G in G&L, and my ΔT is called T in G&L. I reserve G for the integrated total of all government spending since t=-inf, and T as the integrated total taxes collected since t=-inf.








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:

ΔH
[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



NOTES:

[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.