예제 #1
0
파일: SS.py 프로젝트: isaacswift/dynamic
def Euler_equation_solver(guesses, r, w, T_H, factor, j, params, chi_b, chi_n, tau_bq, rho, lambdas, weights, e):
    J, S, T, beta, sigma, alpha, Z, delta, ltilde, nu, g_y, tau_payroll, retire, mean_income_data, a_tax_income, b_tax_income, c_tax_income, d_tax_income, h_wealth, p_wealth, m_wealth, b_ellipse, upsilon = params
    b_guess = np.array(guesses[:S])
    n_guess = np.array(guesses[S:])
    b_s = np.array([0] + list(b_guess[:-1]))
    b_splus1 = b_guess
    b_splus2 = np.array(list(b_guess[1:]) + [0])

    BQ = (1+r) * (b_guess * weights[:, j] * rho).sum()
    theta = tax.replacement_rate_vals(n_guess, w, factor, e[:,j], J, weights[:, j])

    error1 = house.euler_savings_func(w, r, e[:, j], n_guess, b_s, b_splus1, b_splus2, BQ, factor, T_H, chi_b[j], params, theta, tau_bq[j], rho, lambdas[j])
    error2 = house.euler_labor_leisure_func(w, r, e[:, j], n_guess, b_s, b_splus1, BQ, factor, T_H, chi_n, params, theta, tau_bq[j], lambdas[j])
    # Put in constraints for consumption and savings.  According to the euler equations, they can be negative.  When
    # Chi_b is large, they will be.  This prevents that from happening.
    # I'm not sure if the constraints are needed for labor.  But we might as well put them in for now.
    mask1 = n_guess < 0
    mask2 = n_guess > ltilde
    mask3 = b_guess <= 0
    error2[mask1] += 1e14
    error2[mask2] += 1e14
    error1[mask3] += 1e14
    tax1 = tax.total_taxes(r, b_s, w, e[:, j], n_guess, BQ, lambdas[j], factor, T_H, None, 'SS', False, params, theta, tau_bq[j])
    cons = house.get_cons(r, b_s, w, e[:, j], n_guess, BQ, lambdas[j], b_splus1, params, tax1)
    mask4 = cons < 0
    error1[mask4] += 1e14
    # print np.append(error1.flatten(), error2.flatten()).max()
    return list(error1.flatten()) + list(error2.flatten())
예제 #2
0
파일: SS.py 프로젝트: lnsongxf/wealthtax
def Euler_equation_solver(guesses, r, w, T_H, factor, j, params, chi_b, chi_n, tau_bq, rho, lambdas, weights, e):
    '''
    Finds the euler error for certain b and n, one ability type at a time.
    Inputs:
        guesses = guesses for b and n (2Sx1 list)
        r = rental rate (scalar)
        w = wage rate (scalar)
        T_H = lump sum tax (scalar)
        factor = scaling factor to dollars (scalar)
        j = which ability group is being solved for (scalar)
        params = list of parameters (list)
        chi_b = chi^b_j (scalar)
        chi_n = chi^n_s (Sx1 array)
        tau_bq = bequest tax rate (scalar)
        rho = mortality rates (Sx1 array)
        lambdas = ability weights (scalar)
        weights = population weights (Sx1 array)
        e = ability levels (Sx1 array)
    Outputs:
        2Sx1 list of euler errors
    '''
    J, S, T, beta, sigma, alpha, Z, delta, ltilde, nu, g_y, g_n_ss, tau_payroll, retire, mean_income_data, a_tax_income, b_tax_income, c_tax_income, d_tax_income, h_wealth, p_wealth, m_wealth, b_ellipse, upsilon = params
    b_guess = np.array(guesses[:S])
    n_guess = np.array(guesses[S:])
    b_s = np.array([0] + list(b_guess[:-1]))
    b_splus1 = b_guess
    b_splus2 = np.array(list(b_guess[1:]) + [0])

    BQ = house.get_BQ(r, b_splus1, weights, lambdas[j], rho, g_n_ss)
    theta = tax.replacement_rate_vals(n_guess, w, factor, e[:,j], J, weights, lambdas[j])

    error1 = house.euler_savings_func(w, r, e[:, j], n_guess, b_s, b_splus1, b_splus2, BQ, factor, T_H, chi_b[j], params, theta, tau_bq[j], rho, lambdas[j])
    error2 = house.euler_labor_leisure_func(w, r, e[:, j], n_guess, b_s, b_splus1, BQ, factor, T_H, chi_n, params, theta, tau_bq[j], lambdas[j])
    # Put in constraints for consumption and savings.  According to the euler equations, they can be negative.  When
    # Chi_b is large, they will be.  This prevents that from happening.
    # I'm not sure if the constraints are needed for labor.  But we might as well put them in for now.
    mask1 = n_guess < 0
    mask2 = n_guess > ltilde
    mask3 = b_guess <= 0
    error2[mask1] += 1e14
    error2[mask2] += 1e14
    error1[mask3] += 1e14
    tax1 = tax.total_taxes(r, b_s, w, e[:, j], n_guess, BQ, lambdas[j], factor, T_H, None, 'SS', False, params, theta, tau_bq[j])
    cons = house.get_cons(r, b_s, w, e[:, j], n_guess, BQ, lambdas[j], b_splus1, params, tax1)
    mask4 = cons < 0
    error1[mask4] += 1e14
    return list(error1.flatten()) + list(error2.flatten())
예제 #3
0
파일: SS.py 프로젝트: talumbau/dynamic
def Steady_State_SS(guesses, chi_params, params, weights_SS, rho_vec, lambdas, theta, tau_bq, e):
    '''
    Parameters: Steady state distribution of capital guess as array
                size 2*S*J

    Returns:    Array of 2*S*J Euler equation errors
    '''
    J, S, T, beta, sigma, alpha, Z, delta, ltilde, nu, g_y, tau_payroll, retire, mean_income_data, a_tax_income, b_tax_income, c_tax_income, d_tax_income, h_wealth, p_wealth, m_wealth, b_ellipse, upsilon = params
    chi_b = np.tile(np.array(chi_params[:J]).reshape(1, J), (S, 1))
    chi_n = np.array(chi_params[J:])
    b_guess = guesses[0: S * J].reshape((S, J))
    K = house.get_K(b_guess, weights_SS)
    n_guess = guesses[S * J:-1].reshape((S, J))
    L = firm.get_L(e, n_guess, weights_SS)
    Y = firm.get_Y(K, L, params)
    w = firm.get_w(Y, L, params)
    r = firm.get_r(Y, K, params)
    BQ = (1 + r) * (b_guess * weights_SS * rho_vec.reshape(S, 1)).sum(0)
    b_s = np.array(list(np.zeros(J).reshape(1, J)) + list(b_guess[:-1, :]))
    b_splus1 = b_guess
    b_splus2 = np.array(list(b_guess[1:]) + list(np.zeros(J).reshape(1, J)))
    factor = guesses[-1]
    T_H = tax.get_lump_sum(r, b_s, w, e, n_guess, BQ, lambdas, factor, weights_SS, 'SS', params, theta, tau_bq)
    error1 = house.euler_savings_func(w, r, e, n_guess, b_s, b_splus1, b_splus2, BQ.reshape(1, J), factor, T_H, chi_b, params, theta, tau_bq, rho_vec, lambdas)
    error2 = house.euler_labor_leisure_func(w, r, e, n_guess, b_s, b_splus1, BQ.reshape(1, J), factor, T_H, chi_n, params, theta, tau_bq, lambdas)
    average_income_model = ((r * b_s + w * e * n_guess) * weights_SS).sum()
    error3 = [mean_income_data - factor * average_income_model]
    # Check and punish constraint violations
    mask1 = n_guess < 0
    error2[mask1] += 1e9
    mask2 = n_guess > ltilde
    error2[mask2] += 1e9
    if b_guess.sum() <= 0:
        error1 += 1e9
    tax1 = tax.total_taxes(r, b_s, w, e, n_guess, BQ, lambdas, factor, T_H, None, 'SS', False, params, theta, tau_bq)
    cons = house.get_cons(r, b_s, w, e, n_guess, BQ.reshape(1, J), lambdas, b_splus1, params, tax1)
    mask3 = cons < 0
    error2[mask3] += 1e9
    mask4 = b_guess[:-1] <= 0
    error1[mask4] += 1e9
    # print np.abs(np.array(list(error1.flatten()) + list(
    #     error2.flatten()) + error3)).max()
    return list(error1.flatten()) + list(
        error2.flatten()) + error3
예제 #4
0
파일: SS.py 프로젝트: talumbau/dynamic
def Euler_equation_solver(guesses, r, w, T_H, factor, j, params, chi_b, chi_n, theta, tau_bq, rho, lambdas, weights):
    b_guess = np.array(guesses[:S])
    n_guess = np.array(guesses[S:])
    b_s = np.array([0] + list(b_guess[:-1]))
    b_splus1 = b_guess
    b_splus2 = np.array(list(b_guess[1:]) + [0])

    BQ = (1+r) * (b_guess * weights[:, j] * rho).sum()

    error1 = house.euler_savings_func(w, r, e[:, j], n_guess, b_s, b_splus1, b_splus2, BQ, factor, T_H, chi_b[j], params, theta[j], tau_bq[j], rho, lambdas[j])
    error2 = house.euler_labor_leisure_func(w, r, e[:, j], n_guess, b_s, b_splus1, BQ, factor, T_H, chi_n, params, theta[j], tau_bq[j], lambdas[j])
    # Put in constraints
    mask1 = n_guess < 0
    mask2 = n_guess > ltilde
    mask3 = b_guess <= 0
    error2[mask1] += 1e9
    error2[mask2] += 1e9
    error1[mask3] += 1e9
    tax1 = tax.total_taxes(r, b_s, w, e[:, j], n_guess, BQ, lambdas[j], factor, T_H, None, 'SS', False, params, theta[j], tau_bq[j])
    cons = house.get_cons(r, b_s, w, e[:, j], n_guess, BQ, lambdas[j], b_splus1, params, tax1)
    mask4 = cons < 0
    error1[mask4] += 1e9
    return list(error1.flatten()) + list(error2.flatten())
예제 #5
0
파일: SS.py 프로젝트: isaacswift/dynamic
b_splus1        = SxJ array of bssmat in period t+1
b_splus2        = SxJ array of bssmat in period t+2
euler_savings      = euler errors from savings euler equation
euler_labor_leisure      = euler errors from labor leisure euler equation
------------------------------------------------------------------------
'''
b_s = np.array(list(np.zeros(J).reshape((1, J))) + list(bssmat))
b_splus1 = bssmat_splus1
b_splus2 = np.array(list(bssmat_splus1[1:]) + list(np.zeros(J).reshape((1, J))))

chi_b = np.tile(chi_params[:J].reshape(1, J), (S, 1))
chi_n = np.array(chi_params[J:])
euler_savings = np.zeros((S, J))
euler_labor_leisure = np.zeros((S, J))
for j in xrange(J):
    euler_savings[:, j] = house.euler_savings_func(wss, rss, e[:, j], nssmat[:, j], b_s[:, j], b_splus1[:, j], b_splus2[:, j], BQss[j], factor_ss, T_Hss, chi_b[:, j], parameters, theta[j], tau_bq[j], rho, lambdas[j])
    euler_labor_leisure[:, j] = house.euler_labor_leisure_func(wss, rss, e[:, j], nssmat[:, j], b_s[:, j], b_splus1[:, j], BQss[j], factor_ss, T_Hss, chi_n, parameters, theta[j], tau_bq[j], lambdas[j])
'''
------------------------------------------------------------------------
    Save the values in various ways, depending on the stage of
        the simulation, to be used in TPI or graphing functions
------------------------------------------------------------------------
'''

# Pickle variables
var_names = ['Kss', 'bssmat', 'Lss', 'nssmat', 'Yss', 'wss', 'rss', 'theta',
             'BQss', 'factor_ss', 'bssmat_s', 'cssmat', 'bssmat_splus1',
             'T_Hss', 'euler_savings', 'euler_labor_leisure', 'chi_n', 'chi_b']
dictionary1 = {}
for key in var_names:
    dictionary1[key] = globals()[key]
예제 #6
0
파일: SS.py 프로젝트: talumbau/dynamic
    ------------------------------------------------------------------------
    b_s        = SxJ array of bssmat in period t
    b_splus1        = SxJ array of bssmat in period t+1
    b_splus2        = SxJ array of bssmat in period t+2
    euler_savings_1      = euler errors from first euler equation
    euler_labor_leisure      = euler errors from second euler equation
    euler_savings_2      = euler errors from third euler equation
    ------------------------------------------------------------------------
    '''
    b_s = np.array(list(np.zeros(J).reshape((1, J))) + list(bssmat))
    b_splus1 = bssmat_splus1
    b_splus2 = np.array(list(bssmat_splus1[1:]) + list(np.zeros(J).reshape((1, J))))

    chi_b = np.tile(final_chi_params[:J].reshape(1, J), (S, 1))
    chi_n = np.array(final_chi_params[J:])
    euler_savings = house.euler_savings_func(wss, rss, e, nssmat, b_s, b_splus1, b_splus2, BQss.reshape(1, J), factor_ss, T_Hss, chi_b, parameters, theta, tau_bq, rho, lambdas)
    euler_labor_leisure = house.euler_labor_leisure_func(wss, rss, e, nssmat, b_s, b_splus1, BQss.reshape(1, J), factor_ss, T_Hss, chi_n, parameters, theta, tau_bq, lambdas)
'''
------------------------------------------------------------------------
    Save the values in various ways, depending on the stage of
        the simulation, to be used in TPI or graphing functions
------------------------------------------------------------------------
'''
if SS_stage == 'constrained_minimization':
    bssmat_init = bssmat_splus1
    nssmat_init = nssmat
    var_names = ['retire', 'nssmat_init', 'wss', 'factor_ss', 'e',
                 'J', 'omega_SS']
    dictionary = {}
    for key in var_names:
        dictionary[key] = globals()[key]
예제 #7
0
파일: SS.py 프로젝트: lnsongxf/wealthtax
resource_constraint = Yss - (Css + Iss)

print 'Resource Constraint Difference:', resource_constraint

house.constraint_checker_SS(bssmat, nssmat, cssmat, parameters)

b_s = np.array(list(np.zeros(J).reshape((1, J))) + list(bssmat))
b_splus1 = bssmat_splus1
b_splus2 = np.array(list(bssmat_splus1[1:]) + list(np.zeros(J).reshape((1, J))))

chi_b = np.tile(chi_params[:J].reshape(1, J), (S, 1))
chi_n = np.array(chi_params[J:])
euler_savings = np.zeros((S, J))
euler_labor_leisure = np.zeros((S, J))
for j in xrange(J):
    euler_savings[:, j] = house.euler_savings_func(wss, rss, e[:, j], nssmat[:, j], b_s[:, j], b_splus1[:, j], b_splus2[:, j], BQss[j], factor_ss, T_Hss, chi_b[:, j], parameters, theta[j], tau_bq[j], rho, lambdas[j])
    euler_labor_leisure[:, j] = house.euler_labor_leisure_func(wss, rss, e[:, j], nssmat[:, j], b_s[:, j], b_splus1[:, j], BQss[j], factor_ss, T_Hss, chi_n, parameters, theta[j], tau_bq[j], lambdas[j])
'''
------------------------------------------------------------------------
    Save the values in various ways, depending on the stage of
        the simulation, to be used in TPI or graphing functions
------------------------------------------------------------------------
'''

# Pickle variables
var_names = ['Kss', 'bssmat', 'Lss', 'nssmat', 'Yss', 'wss', 'rss', 'theta',
             'BQss', 'factor_ss', 'bssmat_s', 'cssmat', 'bssmat_splus1',
             'T_Hss', 'euler_savings', 'euler_labor_leisure', 'chi_n', 'chi_b']
dictionary1 = {}
for key in var_names:
    dictionary1[key] = globals()[key]