Exemple #1
0
def discrete_z(rho, mu, sigma_eps, num_sigma, sizez):
    '''
    -------------------------------------------------------------------------
    Discretizing state space for productivity shocks
    -------------------------------------------------------------------------
    sigma_z   = scalar, standard deviation of ln(z)
    num_sigma = scalar, number of standard deviations around mean to include in
                grid space for z
    step      = scalar, distance between grid points in the productivity state
                space
    Pi        = (sizez, sizez) matrix, transition probabilities between points in
                the productivity state space
    z         = (sizez,) vector, grid points in the productivity state space
    -------------------------------------------------------------------------
    '''
    # We will use the Rouwenhorst (1995) method to approximate a continuous
    # distribution of shocks to the AR1 process with a Markov process.
    sigma_z = sigma_eps / ((1 - rho**2)**(1 / 2))
    step = (num_sigma * sigma_z) / (sizez / 2)
    Pi, z = ar1.rouwen(rho, mu, step, sizez)
    # wgt = 0.5 + rho / 4
    # baseSigma = wgt * sigma_eps + (1 - wgt) * sigma_z
    # z, Pi = ar1.tauchenhussey(sizez, mu, rho, sigma_eps, baseSigma)
    Pi = np.transpose(Pi)  # make so rows are where start, columns where go
    z = np.exp(z)  # because the AR(1) process was for the log of productivity

    return Pi, z
Exemple #2
0
def z_func(theta):
    # We will use the Rouwenhorst (1995) method to approximate a continuous
    # distribution of shocks to the AR1 process with a Markov process.

    alpha_k, rho, psi, sigma_z = theta
    num_sigma = 3
    step = (num_sigma * sigma_z) / (sizez / 2)
    Pi, z = ar1.rouwen(rho, mu, step, sizez)
    Pi = np.transpose(Pi)  # make so rows are where start, columns where go
    z = np.exp(z)  # because the AR(1) process was for the log of productivity
    return z, Pi
Exemple #3
0
def z_fun(theta):
    # Setting grid for z and the transition matrix
    # Rouwenhorst (1995) method is used to approximate the continuous distribution of shocks with a Markov process.

    alpha_k, rho, psi, sigma_z = theta  # Defining all the model parameters as theta.

    num_sigma = 3
    step = (num_sigma * sigma_z) / (sizez / 2)
    Pi, z = ar1.rouwen(rho, mu, step, sizez)
    Pi = np.transpose(Pi)
    z = np.exp(
        z)  # As AR(1) process is for the natural logarithm of productivity.
    return z, Pi
Exemple #4
0
sigma_z   = scalar, standard deviation of ln(z)
num_sigma = scalar, number of standard deviations around mean to include in
            grid space for z
step      = scalar, distance between grid points in the productivity state
            space
Pi        = (sizez, sizez) matrix, transition probabilities between points in
            the productivity state space
z         = (sizez,) vector, grid points in the productivity state space
-------------------------------------------------------------------------
'''
# We will use the Rouwenhorst (1995) method to approximate a continuous
# distribution of shocks to the AR1 process with a Markov process.
sigma_z = sigma_eps / ((1 - rho**2)**(1 / 2))
num_sigma = 3
step = (num_sigma * sigma_z) / (sizez / 2)
Pi, z = ar1.rouwen(rho, mu, step, sizez)
Pi = np.transpose(Pi)  # make so rows are where start, columns where go
z = np.exp(z)  # because the AR(1) process was for the log of productivity
'''
-------------------------------------------------------------------------
Discretizing state space for capital
-------------------------------------------------------------------------
dens   = integer, density of the grid: number of grid points between k and
         (1 - delta) * k
kstar  = scalar, capital stock choose w/o adjustment costs and mean
         productivity shock
kbar   = scalar, maximum capital stock the firm would ever accumulate
ub_k   = scalar, upper bound of capital stock space
lb_k   = scalar, lower bound of capital stock space
krat   = scalar, difference between upper and lower bound in log points
numb   = integer, the number of steps between the upper and lower bounds for
Exemple #5
0
sigma_eps = 0.2
N = 6
num_sigma = 4

# Create grid for m
lb_m = 0.4
ub_m = 2.0
size_m = 100
m_grid = np.linspace(lb_m, ub_m, size_m)

# Theoretical sigma of epsilon
sigma_P = sigma_eps / ((1 - rho**2)**(1 / 2))
step = (num_sigma * sigma_P) / (N / 2)

# Create grid for P'
pi, P_grid = ar1.rouwen(rho, alpha, step, N)
# P_discrete = sim_markov(P_grid, pi, num_draws)

VFtol = 1e-5  # tolerance for distance between V's
VFdist = 7.0  # initial distance for V
VFmaxiter = 2000  # maximum iterations allowed
V = np.zeros(size_m)
Vstore = np.zeros((size_m, VFmaxiter))  # initialize array for storing V's
VFiter = 1  # initialize iterations
V_params = (beta, sigma)

while (VFdist > VFtol) and (VFiter < VFmaxiter):
    Vstore[:, VFiter] = V
    TV, optM = functions.bellman_operator(V, m_grid, P_grid, V_params)
    VFdist = (np.absolute(V - TV)).max()
    print('Iteration: ', VFiter, ', distance: ', VFdist)