In [ ]:
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 [ ]:
# 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)

In [ ]:
# 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 = 
I =

In [ ]:
# 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

    
    # Exogenous tfp

    
    # Euler equation

    
    # Production function

    
    # Capital evolution

    
    
    # Stack equilibrium conditions into a numpy array
    return np.array([
        ])

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

In [ ]:
# 5. Set the steady state of the model directly. Input vars in same order as varNames above 
model.set_ss([])

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

In [ ]:
# 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))

In [ ]:
# 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 [ ]:
# 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))

In [ ]:
# 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)

Evaluation

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


In [ ]:
# Compute the standard deviations of Y, C, and I in model.simulated

In [ ]:
# Compute the coefficients of correlation for Y, C, and I