Stochastic dynamic programming III.

In this final post on dynamic programming I will simulate the model that was developed in the previous post. The simulation is done in Python and then plotted in Excel, but basically any program can be used to do it.

We will see which actual economic patterns the model is able to match and which ones it isn’t.

As it has been established in the previous post, basically these three equations are of interest to us:

c_t = (1 - \alpha \beta) z_t k_t^{\alpha},

k_{t+1} = \alpha \beta z_t k_t^{\alpha},

y_t = z_t f(k_t) = z_t k_t^{\alpha}.

After specifying an initial capital level and the constants alpha and beta, all is left is generating the data. The z’s can be obtained by any random number generator.

I will take alpha (capital’s share in output) to be 1/3 (this is the value assumed in Romer’s Advanced Macroeconomics for numerical calculations) and I will take the interest rate to be 3%, therefore beta will be 1/(1 + .03) = 0.97. Playing a little bit around with the model I find that the best is to let z be a random number between 0.97 and 1.03.

The heart of the simulation is a simple while loop, which in my case looked like this:

while t < 50:
    z_t = random.randrange(97, 103) / 10
    c_t = (1 - alpha * beta) * z_t * k_t ** alpha

    y_t = z_t * k_t ** alpha

    k_t = alpha * beta * z_t * k_t ** alpha
    t += 1

You would of course have to initialize the variables and print the data at the end. You can find my program here, and can modify it and run your own simulations if you wish.

For output the simulated data looks like this when plotted against actual data:


It can be clearly seen that both actual and simulated GDP growth rate exhibit similar patterns: they’re quite choppy, there’s a lot of variance from year to year. When you look at GDP level, you can see the same thing. The shapes of the two graphs are quite similar. Of course, they don’t coincide but that’s not the point of a simulation like this. The point is to show that the pattern/movement of GDP in the model is quite similar to that of actual GDP. And this is precisely what we can see.

Let us now look at consumption:


What we can see here is that actual consumption growth rates are much smoother than the simulated ones. Matter of fact, the simulated consumption growth rates resemble the simulated GDP growth rates in their choppiness.  This is no coincidence as it can be mathematically shown that their variance is the same. However, clearly actual consumption data doesn’t exhibit this pattern. The consumption levels coincide much more but even there you can clearly see that the red line looks it was drawn by a “shakier” hand than the blue one. Thus the model’s predictions for consumption patterns do not seem to hold in the real world.

Our model therefore fits post-war U.S. output (GDP) data, but it fails to fit consumption data. If GDP growth continues to exhibit a similar pattern in the next decades, then this simple model could in principle be used to forecast where GDP will be in 2050 or 2100. Obviously, no one uses this model for economic forecasts though, as this is pretty much one of the simplest models you’ll learn of in a graduate or advanced undergraduate macro course. But in any case, it is a nice example to show how macroeconomists may go about modeling the economy and to show how dynamic programming works in a simple setting.

This post thus concludes my series on dynamic programming, which was largely based on secton 5.2 of Williamson’s (2006) notes on macro theory. So you know, a big shout out to the professor.

Other posts in my series on dynamic programming: Stochastic dynamic programming I., Stochastic dynamic programming II..

Sources for data: GDP (real) from, real personal consumption expenditures from the Bureau of Economic Analysis.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s