In [1]:
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import linearsolve as ls
%matplotlib inline

Class 18: A Centralized Real Business Cycle Model without Labor (Continued)

The Model with Output and Investment

Setup

A representative household lives for an infinite number of periods. The expected present value of lifetime utility to the household from consuming $C_0, C_1, C_2, \ldots $ is denoted by $U_0$:

\begin{align} U_0 & = \log (C_0) + \beta E_0 \log (C_1) + \beta^2 E_0 \log (C_2) + \cdots\\ & = E_0\sum_{t = 0}^{\infty} \beta^t \log (C_t), \end{align}

where $0<\beta<1$ is the household's subjective discount factor. $E_0$ denotes the expectation with respect to all information available as of date 0.

The household enters period 0 with capital $K_0>0$. Production in period $t$:

\begin{align} F(A_t,K_t) & = A_t K_t^{\alpha} \end{align}

where TFP $A_t$ is stochastic:

\begin{align} \log A_{t+1} & = \rho \log A_t + \epsilon_{t+1} \end{align}

Capital depreciates at the constant rate $\delta$ per period and so the household's resource constraint in each period $t$ is:

\begin{align} C_t + K_{t+1} & = A_t K_{t}^{\alpha} + (1-\delta)K_t \end{align}

Define output and investment:

\begin{align} Y_t & = A_t K_{t}^{\alpha} \\ I_t & = K_{t+1} - (1-\delta)K_t \end{align}

Optimization problem

In period 0, the household solves:

\begin{align} & \max_{C_0,K_1} \; E_0\sum_{t=0}^{\infty}\beta^t\log (C_t) \\ & \; \; \; \; \; \; \; \; \text{s.t.} \; \; \; \; C_t + K_{t+1} = A_t K_{t}^{\alpha} + (1-\delta)K_t \end{align}

which can be written as a choice of $K_1$ only:

\begin{align} \max_{K_1} \; E_0\sum_{t=0}^{\infty}\beta^t\log \left( A_t K_{t}^{\alpha} + (1-\delta)K_t - K_{t+1}\right) \end{align}

Equilibrium

So given $K_0>0$ and $A_0$, the equilibrium paths for consumption, capital, and TFP are described described by:

\begin{align} \frac{1}{C_t} & = \beta E_t \left[\frac{\alpha A_{t+1}K_{t+1}^{\alpha - 1} + 1 - \delta}{C_{t+1}}\right]\\ C_t + K_{t+1} & = A_{t} K_t^{\alpha} + (1-\delta) K_t\\ Y_t & = A_t K_{t}^{\alpha} \\ I_t & = K_{t+1} - (1-\delta)K_t\\ \log A_{t+1} & = \rho \log A_t + \epsilon_{t+1} \end{align}

Calibration

For computation purposes, assume the following values for the parameters of the model:

\begin{align} \beta & = 0.99\\ \rho & = .75\\ \sigma & = 0.006\\ \alpha & = 0.35\\ \delta & = 0.025 \end{align}

Steady State

The steady state:

\begin{align} A & = 1\\ K & = \left(\frac{\alpha A}{\beta^{-1} - 1 + \delta} \right)^{\frac{1}{1-\alpha}}\\ C & = AK^{\alpha} - \delta K\\ Y & = AK^{\alpha} \\ I & = \delta K \end{align}

In [2]:
# 1. Input model parameters and print
parameters = pd.Series()
parameters['rho'] = .75
parameters['sigma'] = 0.006
parameters['alpha'] = 0.35
parameters['delta'] = 0.025
parameters['beta'] = 0.99
print(parameters)


rho      0.750
sigma    0.006
alpha    0.350
delta    0.025
beta     0.990
dtype: float64

In [3]:
# 2. Compute the steady state of the model directly
A = 1
K = (parameters.alpha*A/(parameters.beta**-1+parameters.delta-1))**(1/(1-parameters.alpha))
C = A*K**parameters.alpha - parameters.delta
Y = A*K**parameters.alpha
I = parameters.delta*K

In [4]:
# 3. Define a function that evaluates the equilibrium conditions
def equilibrium_equations(variables_forward,variables_current,parameters):
    
    # Parameters 
    p = parameters
    
    # Variables
    fwd = variables_forward
    cur = variables_current
        
    # Resource constraint
    resource = cur.a*cur.k**p.alpha + (1-p.delta)* cur.k - fwd.k - cur.c
    
    # Exogenous tfp
    tfp_proc = p.rho*np.log(cur.a) - np.log(fwd.a)
    
    # Euler equation
    euler = p.beta*(p.alpha*fwd.a*fwd.k**(p.alpha-1) + 1 - p.delta)/fwd.c - 1/cur.c
    
    # Production function
    production = cur.a*cur.k**p.alpha - cur.y
    
    # Capital evolution
    capital_evolution = cur.i + (1-p.delta)*cur.k - fwd.k
    
    
    # Stack equilibrium conditions into a numpy array
    return np.array([
        resource,
        tfp_proc,
        euler,
        production,
        capital_evolution
        ])

In [5]:
# 4. Initialize the model
model = ls.model(equations = equilibrium_equations,
                 nstates=2,
                 varNames=['a','k','y','c','i'],                   # Any order as long as the state variables are named first
                 shockNames=['eA','eK'],                 # Name a shock for each state variable *even if there is no corresponding shock in the model*
                 parameters = parameters)

In [6]:
# 5. Set the steady state of the model directly. Input vars in same order as varNames above 
model.set_ss([A,K,Y,C,I])

In [7]:
# 6. Find the log-linear approximation around the non-stochastic steady state and solve
model.approximate_and_solve()

In [8]:
# 7(a) Compute impulse responses and print the computed impulse responses
model.impulse(T=41,t0=5,shock=None,percent=True)
print(model.irs['eA'].head(10))


          a         c   eA         i         k         y
0  0.000000  0.000000  0.0  0.000000  0.000000  0.000000
1  0.000000  0.000000  0.0  0.000000  0.000000  0.000000
2  0.000000  0.000000  0.0  0.000000  0.000000  0.000000
3  0.000000  0.000000  0.0  0.000000  0.000000  0.000000
4  0.000000  0.000000  0.0  0.000000  0.000000  0.000000
5  1.000000  0.093188  1.0  3.640424  0.000000  1.000000
6  0.750000  0.117195  0.0  2.669714  0.091011  0.781854
7  0.562500  0.133230  0.0  1.944206  0.155478  0.616917
8  0.421875  0.143368  0.0  1.402493  0.200196  0.491944
9  0.316406  0.149163  0.0  0.998527  0.230254  0.396995

In [9]:
# 8(b) Plot the computed impulse responses to a TFP shock
fig = plt.figure(figsize=(12,12))

ax1 = fig.add_subplot(3,2,1)
model.irs['eA'][['y','i','k']].plot(lw=5,alpha=0.5,grid=True,ax = ax1).legend(loc='upper right',ncol=4)
ax1.set_title('Output, investment, capital')
ax1.set_ylabel('% dev')
ax1.set_xlabel('quarters')

ax2 = fig.add_subplot(3,2,2)
model.irs['eA'][['a','eA']].plot(lw=5,alpha=0.5,grid=True,ax = ax2).legend(loc='upper right',ncol=2)
ax2.set_title('TFP and TFP shock')
ax2.set_ylabel('% dev')
ax2.set_xlabel('quarters')

ax3 = fig.add_subplot(3,2,3)
model.irs['eA'][['y','c']].plot(lw=5,alpha=0.5,grid=True,ax = ax3).legend(loc='upper right',ncol=4)
ax3.set_title('Output and consumption')
ax3.set_ylabel('% dev')
ax3.set_xlabel('quarters')

plt.tight_layout()



In [10]:
# 9(a) Compute stochastic simulation and print the simulated values
model.stoch_sim(seed=192,covMat= [[parameters['sigma']**2,0],[0,0]])
print(model.simulated.head(10))


          a         c        eA   eK         i         k         y
0  0.005779 -0.005655  0.000843  0.0  0.028973 -0.011916  0.001609
1  0.003489 -0.005337 -0.000845  0.0  0.019957 -0.010894 -0.000323
2  0.000161 -0.005246 -0.002456  0.0  0.007327 -0.010122 -0.003382
3 -0.003394 -0.005351 -0.003515  0.0 -0.005905 -0.009686 -0.006784
4 -0.006195 -0.005563 -0.003650  0.0 -0.016167 -0.009592 -0.009553
5 -0.007545 -0.005774 -0.002899  0.0 -0.020971 -0.009756 -0.010960
6 -0.006517 -0.005824 -0.000858  0.0 -0.017042 -0.010036 -0.010030
7  0.000981 -0.005216  0.005869  0.0  0.010370 -0.010212 -0.002593
8  0.001545 -0.004896  0.000809  0.0  0.012080 -0.009697 -0.001849
9 -0.006102 -0.005326 -0.007261  0.0 -0.016120 -0.009153 -0.009306

In [11]:
# 9(b) Plot the computed stochastic simulation
fig = plt.figure(figsize=(12,4))

ax1 = fig.add_subplot(1,2,1)
model.simulated[['k','c','y','i']].plot(lw=5,alpha=0.5,grid=True,ax = ax1).legend(loc='upper right',ncol=4)

ax2 = fig.add_subplot(1,2,2)
model.simulated[['eA','a']].plot(lw=5,alpha=0.5,grid=True,ax = ax2).legend(loc='upper right',ncol=2)


Out[11]:
<matplotlib.legend.Legend at 0x11c4dc0b8>

Evaluation

Now we want to examine the statistical properties of the simulated model


In [12]:
# Compute the standard deviations of Y, C, and I in model.simulated
print(model.simulated[['y','c','i']].std())


y    0.007205
c    0.001475
i    0.026080
dtype: float64

In [13]:
# Compute the coefficients of correlation for Y, C, and I
print(model.simulated[['y','c','i']].corr())


          y         c         i
y  1.000000  0.558537  0.982386
c  0.558537  1.000000  0.393699
i  0.982386  0.393699  1.000000