Author: Nayha M
Hi there,
This is my code that I am setting up:
Implements iteration on the Bellman equations to solve the McCall growth model
import numpy as np
from numba import jit
A default utility function
@jit
def u(c, sigma):
if c > 0:
return (c**(1 - sigma) - 1) / (1 - sigma)
else:
return -10e6
class MyModel:
Stores the parameters and functions associated with a given model.
def __init__(self,beta=0.997, # discount factor
deltaC=0.05, # job separation rate for construction workers
b=0.4, # uemployed benefits
c=1, # cost of posting a vacancy
N=1000, #grid points
gammaC=0.592, #match efficiency for construction
g=0.5, #matching function elasticity
tauC=0.07, #sector demand shares
eta=2.00, #elasticity of substitution
wageC=2.956, #wages C
VC=0.0182, #vacancy C
UC=0.106, #Unemploymwnt C
fc=0.2453, # job finding probability C
sigma = 1):
self.beta = beta
self.deltaC = deltaC
self.b = b
self.c = c
self.gammaC = gammaC
self.g = g
self.tauC = tauC
self.eta = eta
self.wageC = wageC
self.VC = VC
self.UC = UC
self.fc = fc
self.sigma = sigma
def compute_derived_values(self):
self.EmpC=fc/(fc+deltaC) #steady state level of employment C
self.Uc=deltaC/(fc+deltaC) #steady state level of unemployment C
self.EmpCgrid = linspace(0.9*self.EmpC,1.1*self.EmpC,1000).T #The grid, an N x 1 vector, is defined around the steady state.
self.EmpCmatrix = repmat(self.EmpCgrid,1,1000) # An, N x N, matrix with kgrid as columns, N times.
self.EmpCmatrixprime = self.EmpCmatrix.T #The same but transposed.
self.OmegaC=[self.EmpC,self.Uc]
self.OmegaCgrid=[self.EmpCgrid,self.Ucgrid]
self.OmegaCmatrix=repmat(self.OmegaCgrid,1,1000)
self.OmegaCmatrixprime=self.OmegaCmatrix.T
@jit
def _update_bellman(beta, deltaC, b, fc, wagesC, OmegaC, V, V_new, U, U_new):
for OmegaC_idx, OmegaC in enumerate(self.OmegaCgrid):
# w_idx indexes the vector of possible wages
V_new[OmegaC_idx] = wageC + beta*((1 - deltaC)*(np.maximum(V[OmegaC_idx])) + deltaC*(np.maximum(U[OmegaC_idx])))
U_new[OmegaC_idx] = b + beta*(((fc)*np.maximum(V[OmegaC_idx])) + (1-fc)*(np.maximum(U[OmegaC_idx])))
return U_new
def solve_mymodel(mcm, tol=1e-5, max_iter=2000):
"""
Iterates to convergence on the Bellman equations
Parameters
----------
mcm : an instance of McCallModel
tol : float
error tolerance
max_iter : int
the maximum number of iterations
"""
V = np.ones(len(mcm.w_vec)) # Initial guess of V
V_new = np.empty_like(V) # To store updates to V
U = 1 # Initial guess of U
i = 0
error = tol + 1
while error > tol and i < max_iter:
U_new = _update_bellman(mcm.beta, mcm.deltaC, mcm.b,
mcm.fc, mcm.wagesC, mcm.OmegaC, V, V_new, U)
error_1 = np.max(np.abs(V_new - V))
error_2 = np.abs(U_new - U)
error = max(error_1, error_2)
V[:] = V_new
U = U_new
i += 1
return V, U
But it is giving me this error:
File "<ipython-input-4-5f43475caa45>", line 76
for OmegaC_idx, OmegaC in enumerate(self.OmegaCgrid):
^
IndentationError: expected an indented block
Could anyone help me figure out how to correct this error.
Thanks.