示例#1
0
def test_get_y():
    '''
    Test of household.get_y() function.
    '''
    r_hh = np.array([0.05, 0.04, 0.09])
    w = np.array([1.2, 0.8, 2.5])
    b_s = np.array([0.5, 0.99, 9])
    n = np.array([0.8, 3.2, 0.2])
    expected_y = np.array([0.9754, 3.8796, 0.91])
    p = Specifications()
    # p.update_specifications({'S': 4, 'J': 1})
    p.S = 3
    p.e = np.array([0.99, 1.5, 0.2])

    test_y = household.get_y(r_hh, w, b_s, n, p)

    assert np.allclose(test_y, expected_y)
示例#2
0
    top_share = ineq.top_share(0.05)
    assert np.allclose(top_share, 0.285714286)


def test_to_timepath_shape():
    '''
    Test of function that converts vector to time path conformable array
    '''
    in_array = np.ones(40)
    test_array = utils.to_timepath_shape(in_array)
    assert test_array.shape == (40, 1, 1)


p = Specifications()
p.T = 40
p.S = 3
p.J = 1
x1 = np.ones((p.S, p.J)) * 0.4
xT = np.ones((p.S, p.J)) * 5.0
expected1 = np.tile(
    np.array([
        0.4, 0.51794872, 0.63589744, 0.75384615, 0.87179487, 0.98974359,
        1.10769231, 1.22564103, 1.34358974, 1.46153846, 1.57948718, 1.6974359,
        1.81538462, 1.93333333, 2.05128205, 2.16923077, 2.28717949, 2.40512821,
        2.52307692, 2.64102564, 2.75897436, 2.87692308, 2.99487179, 3.11282051,
        3.23076923, 3.34871795, 3.46666667, 3.58461538, 3.7025641, 3.82051282,
        3.93846154, 4.05641026, 4.17435897, 4.29230769, 4.41025641, 4.52820513,
        4.64615385, 4.76410256, 4.88205128, 5., 5.0, 5.0, 5.0
    ]).reshape(p.T + p.S, 1, 1), (1, p.S, p.J))
expected2 = np.tile(
    np.array([
示例#3
0
test_data = [(b1, p1, expected1),
             (b2, p2, expected2)]


@pytest.mark.parametrize('b,p,expected', test_data,
                         ids=['constant params', 'vary params'])
def test_MTR_wealth(b, p, expected):
    # Test marginal tax rate on wealth
    tau_w_prime = tax.MTR_wealth(b, p.h_wealth[:p.T], p.m_wealth[:p.T],
                                 p.p_wealth[:p.T])

    assert np.allclose(tau_w_prime, expected)


p1 = Specifications()
p1.S = 2
p1.J = 1
p1.e = np.array([0.5, 0.45])
p1.tax_func_type = 'DEP'
etr_params1 = np.reshape(np.array([
    [0.001, 0.002, 0.003, 0.0015, 0.8, 0.8, 0.83, -0.14,
    -0.15, 0.15, 0.16, -0.15],
    [0.001, 0.002, 0.003, 0.0015, 0.8, 0.8, 0.83, -0.14,
    -0.15, 0.15, 0.16, -0.15]]), (1, p1.S, 12))

p2 = Specifications()
p2.S = 2
p2.J = 1
p2.e = np.array([0.5, 0.45])
p2.tax_func_type = 'GS'
etr_params2 = np.reshape(np.array([
示例#4
0
                        [1.4248841, 0.806333875, 6.987729463]]))]


@pytest.mark.parametrize('n,params,expected',
                         test_data,
                         ids=['1', '2', '3', '4', '5', '6', '7', '8'])
def test_marg_ut_labor(n, params, expected):
    # Test marginal utility of labor calculation
    test_value = household.marg_ut_labor(n, params.chi_n, params)

    assert np.allclose(test_value, expected)


p1 = Specifications()
p1.zeta = np.array([[0.1, 0.3], [0.15, 0.4], [0.05, 0.0]])
p1.S = 3
p1.J = 2
p1.T = 3
p1.lambdas = np.array([0.6, 0.4])
p1.omega_SS = np.array([0.25, 0.25, 0.5])
p1.omega = np.tile(p1.omega_SS.reshape((1, p1.S)), (p1.T, 1))
BQ1 = 2.5
p1.use_zeta = True
expected1 = np.array([[1.66666667, 7.5], [2.5, 10.0], [0.416666667, 0.0]])
p2 = Specifications()
p2.zeta = np.array([[0.1, 0.3], [0.15, 0.4], [0.05, 0.0]])
p2.S = 3
p2.J = 2
p2.T = 3
p2.lambdas = np.array([0.6, 0.4])
p2.omega_SS = np.array([0.25, 0.25, 0.5])