Exemple #1
0
def Euler_Error_firstgroup(guesses, winit, rinit, Binit, Tinit):
    K2 = float(guesses[0])
    l1 = float(guesses[1])
    K1 = float(initial_K[-2, j])
    # Euler 1 equations
    tax11 = tax.total_taxes_eul3_TPI(rinit, K1, winit, e[-1, j], l1, Binit,
                                     bin_weights[j], factor_ss, Tinit, j)
    cons11 = get_cons(rinit, K1, winit, e[-1, j], l1, (1 + rinit) * Binit,
                      bin_weights[j], K2, g_y, tax11)
    bequest_ut = (1 - surv_rate[-1]) * np.exp(
        -sigma * g_y) * chi_b[-1, j] * K2**(-sigma)
    error1 = MUc(cons11) - bequest_ut
    # Euler 2 equations
    tax2 = tax.total_taxes_eul3_TPI(rinit, K1, winit, e[-1, j], l1, Binit,
                                    bin_weights[j], factor_ss, Tinit, j)
    cons2 = get_cons(rinit, K1, winit, e[-1, j], l1, (1 + rinit) * Binit,
                     bin_weights[j], K2, g_y, tax2)
    wealth2 = (rinit * K1 + winit * e[-1, j] * l1) * factor_ss
    deriv2 = 1 - tau_payroll - tax.tau_income(
        rinit, K1, winit, e[-1, j], l1, factor_ss) - tax.tau_income_deriv(
            rinit, K1, winit, e[-1, j], l1, factor_ss) * wealth2
    error2 = MUc(cons2) * winit * e[-1, j] * deriv2 - MUl2(l1, chi_n[-1])
    if l1 <= 0:
        error2 += 1e12
    return [error1] + [error2]
Exemple #2
0
def Euler_Error_firstgroup(guesses, winit, rinit, Binit, Tinit):
    K2 = float(guesses[0])
    l1 = float(guesses[1])
    K1 = float(initial_K[-2, j])
    # Euler 1 equations
    tax11 = tax.total_taxes_eul3_TPI(rinit, K1, winit, e[-1, j], l1, Binit, bin_weights[j], factor_ss, Tinit, j)
    cons11 = get_cons(rinit, K1, winit, e[-1, j], l1, (1+rinit)*Binit, bin_weights[j], K2, g_y, tax11)
    bequest_ut = (1-surv_rate[-1]) * np.exp(-sigma * g_y) * chi_b[-1, j] * K2 ** (-sigma)
    error1 = MUc(cons11) - bequest_ut
    # Euler 2 equations
    tax2 = tax.total_taxes_eul3_TPI(rinit, K1, winit, e[-1, j], l1, Binit, bin_weights[j], factor_ss, Tinit, j)
    cons2 = get_cons(rinit, K1, winit, e[-1, j], l1, (1+rinit)*Binit, bin_weights[j], K2, g_y, tax2)
    wealth2 = (rinit * K1 + winit * e[-1, j] * l1) * factor_ss
    deriv2 = 1 - tau_payroll - tax.tau_income(rinit, K1, winit, e[
        -1, j], l1, factor_ss) - tax.tau_income_deriv(
        rinit, K1, winit, e[-1, j], l1, factor_ss) * wealth2
    error2 = MUc(cons2) * winit * e[-1, j] * deriv2 - MUl2(l1, chi_n[-1])
    if l1 <= 0:
        error2 += 1e12
    return [error1] + [error2]
Exemple #3
0
def SS_TPI_firstdoughnutring(guesses, winit, rinit, BQinit, T_H_init):
    # This function does not work.  The tax functions need to be changed.
    b2 = float(guesses[0])
    n1 = float(guesses[1])
    b1 = float(initial_b[-2, j])
    # Euler 1 equations
    tax11 = tax.total_taxes_eul3_TPI(rinit, b1, winit, e[-1, j], n1, BQinit, lambdas[j], factor_ss, T_H_init, j)
    cons11 = house.get_cons(rinit, b1, winit, e[-1, j], n1, BQinit, lambdas[j], b2, g_y, tax11)
    bequest_ut = rho * np.exp(-sigma * g_y) * chi_b[-1, j] * b2 ** (-sigma)
    error1 = house.marg_ut_cons(cons11) - bequest_ut
    # Euler 2 equations
    tax2 = tax.total_taxes_eul3_TPI(rinit, b1, winit, e[-1, j], n1, BQinit, lambdas[j], factor_ss, T_H_init, j)
    cons2 = house.get_cons(rinit, b1, winit, e[-1, j], n1, BQinit, lambdas[j], b2, g_y, tax2)
    income2 = (rinit * b1 + winit * e[-1, j] * n1) * factor_ss
    deriv2 = 1 - tau_payroll - tax.tau_income(rinit, b1, winit, e[
        -1, j], n1, factor_ss) - tax.tau_income_deriv(
        rinit, b1, winit, e[-1, j], n1, factor_ss) * income2
    error2 = house.marg_ut_cons(cons2) * winit * e[-1, j] * deriv2 - house.marg_ut_labor(n1, chi_n[-1])
    if n1 <= 0:
        error2 += 1e12
    return [error1] + [error2]
Exemple #4
0
def Euler_Error(guesses, winit, rinit, Binit, Tinit, t):
    '''
    Parameters:
        guesses = distribution of capital and labor in period t
                  ((S-1)*S*J x 1 list)
        winit   = wage rate (scalar)
        rinit   = rental rate (scalar)
        t       = time period

    Returns:
        Value of Euler error. (as an 2*S*J x 1 list)
    '''
    length = len(guesses) / 2
    K_guess = np.array(guesses[:length])
    L_guess = np.array(guesses[length:])

    if length == S:
        K1 = np.array([0] + list(K_guess[:-2]))
    else:
        K1 = np.array([(initial_K[-(s + 2), j])] + list(K_guess[:-2]))
    K2 = K_guess[:-1]
    K3 = K_guess[1:]
    w1 = winit[t:t + length - 1]
    w2 = winit[t + 1:t + length]
    r1 = rinit[t:t + length - 1]
    r2 = rinit[t + 1:t + length]
    l1 = L_guess[:-1]
    l2 = L_guess[1:]
    e1 = e[-length:-1, j]
    e2 = e[-length + 1:, j]
    B1 = Binit[t:t + length - 1]
    B2 = Binit[t + 1:t + length]
    T1 = Tinit[t:t + length - 1]
    T2 = Tinit[t + 1:t + length]
    # Euler 1 equations
    tax11 = tax.total_taxes_TPI1(r1, K1, w1, e1, l1, B1, bin_weights[j],
                                 factor_ss, T1, j)
    tax12 = tax.total_taxes_TPI1_2(r2, K2, w2, e2, l2, B2, bin_weights[j],
                                   factor_ss, T2, j)
    cons11 = get_cons(r1, K1, w1, e1, l1, B1, bin_weights[j], K2, g_y, tax11)
    cons12 = get_cons(r2, K2, w2, e2, l2, B2, bin_weights[j], K3, g_y, tax12)
    wealth1 = (r2 * K2 + w2 * e2 * l2) * factor_ss
    bequest_ut = (1 - surv_rate[-(length):-1]) * np.exp(
        -sigma * g_y) * chi_b[-(length):-1, j] * K2**(-sigma)
    deriv1 = 1 + r2 * (1 - tax.tau_income(r2, K2, w2, e2, l2, factor_ss) -
                       tax.tau_income_deriv(r2, K2, w2, e2, l2, factor_ss) *
                       wealth1) - tax.tau_w_prime(K2) * K2 - tax.tau_wealth(K2)
    error1 = MUc(cons11) - beta * surv_rate[-(length):-1] * np.exp(
        -sigma * g_y) * deriv1 * MUc(cons12) - bequest_ut
    # Euler 2 equations
    if length == S:
        K1_2 = np.array([0] + list(K_guess[:-1]))
    else:
        K1_2 = np.array([(initial_K[-(s + 2), j])] + list(K_guess[:-1]))

    K2_2 = K_guess
    w = winit[t:t + length]
    r = rinit[t:t + length]
    B = Binit[t:t + length]
    Tl = Tinit[t:t + length]
    tax2 = tax.total_taxes_TPI2(r, K1_2, w, e[-(length):, j], L_guess, B,
                                bin_weights[j], factor_ss, Tl, j)
    cons2 = get_cons(r, K1_2, w, e[-(length):, j], L_guess, B, bin_weights[j],
                     K2_2, g_y, tax2)
    wealth2 = (r * K1_2 + w * e[-(length):, j] * L_guess) * factor_ss
    deriv2 = 1 - tau_payroll - tax.tau_income(
        r, K1_2, w,
        e[-(length):, j], L_guess, factor_ss) - tax.tau_income_deriv(
            r, K1_2, w, e[-(length):, j], L_guess, factor_ss) * wealth2
    error2 = MUc(cons2) * w * e[-(length):, j] * deriv2 - MUl2(
        L_guess, chi_n[-length:])
    # Euler 3 equations
    tax3 = tax.total_taxes_eul3_TPI(r[-1], K_guess[-2], w[-1], e[-1, j],
                                    L_guess[-1], B[-1], bin_weights[j],
                                    factor_ss, Tl[-1], j)
    cons3 = get_cons(r[-1], K_guess[-2], w[-1], e[-1, j], L_guess[-1], B[-1],
                     bin_weights[j], K_guess[-1], g_y, tax3)
    error3 = MUc(cons3) - np.exp(-sigma * g_y) * MUb2(K_guess[-1], chi_b[:, j])
    # Check and punish constraint violations
    mask1 = L_guess < 0
    error2[mask1] += 1e12
    mask2 = L_guess > ltilde
    error2[mask2] += 1e12
    mask3 = cons2 < 0
    error2[mask3] += 1e12
    mask4 = K_guess <= 0
    error2[mask4] += 1e12
    return list(error1.flatten()) + list(error2.flatten()) + list(
        error3.flatten())
Exemple #5
0
def Euler_Error(guesses, winit, rinit, Binit, Tinit, t):
    """
    Parameters:
        guesses = distribution of capital and labor in period t
                  ((S-1)*S*J x 1 list)
        winit   = wage rate (scalar)
        rinit   = rental rate (scalar)
        t       = time period

    Returns:
        Value of Euler error. (as an 2*S*J x 1 list)
    """
    length = len(guesses) / 2
    K_guess = np.array(guesses[:length])
    L_guess = np.array(guesses[length:])

    if length == S:
        K1 = np.array([0] + list(K_guess[:-2]))
    else:
        K1 = np.array([(initial_K[-(s + 2), j])] + list(K_guess[:-2]))
    K2 = K_guess[:-1]
    K3 = K_guess[1:]
    w1 = winit[t : t + length - 1]
    w2 = winit[t + 1 : t + length]
    r1 = rinit[t : t + length - 1]
    r2 = rinit[t + 1 : t + length]
    l1 = L_guess[:-1]
    l2 = L_guess[1:]
    e1 = e[-length:-1, j]
    e2 = e[-length + 1 :, j]
    B1 = Binit[t : t + length - 1]
    B2 = Binit[t + 1 : t + length]
    T1 = Tinit[t : t + length - 1]
    T2 = Tinit[t + 1 : t + length]
    # Euler 1 equations
    tax11 = tax.total_taxes_TPI1(r1, K1, w1, e1, l1, B1, bin_weights[j], factor_ss, T1, j)
    tax12 = tax.total_taxes_TPI1_2(r2, K2, w2, e2, l2, B2, bin_weights[j], factor_ss, T2, j)
    cons11 = get_cons(r1, K1, w1, e1, l1, B1, bin_weights[j], K2, g_y, tax11)
    cons12 = get_cons(r2, K2, w2, e2, l2, B2, bin_weights[j], K3, g_y, tax12)
    wealth1 = (r2 * K2 + w2 * e2 * l2) * factor_ss
    bequest_ut = (1 - surv_rate[-(length):-1]) * np.exp(-sigma * g_y) * chi_b[-(length):-1, j] * K2 ** (-sigma)
    deriv1 = (
        1
        + r2
        * (
            1
            - tax.tau_income(r2, K2, w2, e2, l2, factor_ss)
            - tax.tau_income_deriv(r2, K2, w2, e2, l2, factor_ss) * wealth1
        )
        - tax.tau_w_prime(K2) * K2
        - tax.tau_wealth(K2)
    )
    error1 = MUc(cons11) - beta * surv_rate[-(length):-1] * np.exp(-sigma * g_y) * deriv1 * MUc(cons12) - bequest_ut
    # Euler 2 equations
    if length == S:
        K1_2 = np.array([0] + list(K_guess[:-1]))
    else:
        K1_2 = np.array([(initial_K[-(s + 2), j])] + list(K_guess[:-1]))

    K2_2 = K_guess
    w = winit[t : t + length]
    r = rinit[t : t + length]
    B = Binit[t : t + length]
    Tl = Tinit[t : t + length]
    tax2 = tax.total_taxes_TPI2(r, K1_2, w, e[-(length):, j], L_guess, B, bin_weights[j], factor_ss, Tl, j)
    cons2 = get_cons(r, K1_2, w, e[-(length):, j], L_guess, B, bin_weights[j], K2_2, g_y, tax2)
    wealth2 = (r * K1_2 + w * e[-(length):, j] * L_guess) * factor_ss
    deriv2 = (
        1
        - tau_payroll
        - tax.tau_income(r, K1_2, w, e[-(length):, j], L_guess, factor_ss)
        - tax.tau_income_deriv(r, K1_2, w, e[-(length):, j], L_guess, factor_ss) * wealth2
    )
    error2 = MUc(cons2) * w * e[-(length):, j] * deriv2 - MUl2(L_guess, chi_n[-length:])
    # Euler 3 equations
    tax3 = tax.total_taxes_eul3_TPI(
        r[-1], K_guess[-2], w[-1], e[-1, j], L_guess[-1], B[-1], bin_weights[j], factor_ss, Tl[-1], j
    )
    cons3 = get_cons(r[-1], K_guess[-2], w[-1], e[-1, j], L_guess[-1], B[-1], bin_weights[j], K_guess[-1], g_y, tax3)
    error3 = MUc(cons3) - np.exp(-sigma * g_y) * MUb2(K_guess[-1], chi_b[:, j])
    # Check and punish constraint violations
    mask1 = L_guess < 0
    error2[mask1] += 1e12
    mask2 = L_guess > ltilde
    error2[mask2] += 1e12
    mask3 = cons2 < 0
    error2[mask3] += 1e12
    mask4 = K_guess <= 0
    error2[mask4] += 1e12
    return list(error1.flatten()) + list(error2.flatten()) + list(error3.flatten())