test_data, ids=['scalar', 'vector', 'matrix', '3D array']) def test_get_cons(model_args, expected): # Test consumption calculation r, w, b, b_splus1, n, bq, net_tax, tau_c, p = model_args test_value = household.get_cons(r, w, b, b_splus1, n, bq, net_tax, p.e, tau_c, p) assert np.allclose(test_value, expected) # Define variables for test of SS version p1 = Specifications() p1.e = np.array([1.0, 0.9, 1.4]).reshape(3, 1) p1.sigma = 2.0 p1.beta = 0.96 p1.g_y = 0.03 p1.chi_b = np.array([1.5]) p1.tau_bq = np.array([0.0]) p1.rho = np.array([0.1, 0.2, 1.0]) p1.lambdas = np.array([1.0]) p1.J = 1 p1.S = 3 p1.T = 3 p1.analytical_mtrs = False etr_params = np.array([ np.array([[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.33, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.25, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.20, 0]]), np.array([[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.9, 0],
def test_firstdoughnutring(dask_client): # Test TPI.firstdoughnutring function. Provide inputs to function and # ensure that output returned matches what it has been before. input_tuple = utils.safe_read_pickle( os.path.join(CUR_PATH, 'test_io_data', 'firstdoughnutring_inputs.pkl')) guesses, r, w, b, BQ, TR, j, params = input_tuple income_tax_params, tpi_params, initial_b = params tpi_params = tpi_params + [True] p = Specifications(client=dask_client, num_workers=NUM_WORKERS) (p.J, p.S, p.T, p.BW, beta, p.sigma, p.alpha, p.gamma, p.epsilon, Z, p.delta, p.ltilde, p.nu, p.g_y, p.g_n, tau_b, delta_tau, tau_payroll, tau_bq, p.rho, p.omega, N_tilde, lambdas, p.imm_rates, p.e, retire, p.mean_income_data, factor, h_wealth, p_wealth, m_wealth, p.b_ellipse, p.upsilon, p.chi_b, p.chi_n, theta, p.baseline) = tpi_params p.beta = np.ones(p.J) * beta p.Z = np.ones(p.T + p.S) * Z p.tau_bq = np.ones(p.T + p.S) * 0.0 p.tau_payroll = np.ones(p.T + p.S) * tau_payroll p.tau_b = np.ones(p.T + p.S) * tau_b p.delta_tau = np.ones(p.T + p.S) * delta_tau p.h_wealth = np.ones(p.T + p.S) * h_wealth p.p_wealth = np.ones(p.T + p.S) * p_wealth p.m_wealth = np.ones(p.T + p.S) * m_wealth p.retire = (np.ones(p.T + p.S) * retire).astype(int) p.tax_func_type = 'DEP' p.analytical_mtrs, etr_params, mtrx_params, mtry_params =\ income_tax_params p.etr_params = np.transpose(etr_params, (1, 0, 2)) p.mtrx_params = np.transpose(mtrx_params, (1, 0, 2)) p.mtry_params = np.transpose(mtry_params, (1, 0, 2)) etr_params_old = p.etr_params mtrx_params_old = p.mtrx_params mtry_params_old = p.mtry_params p.etr_params = etr_params_old.copy() p.etr_params[:, :, 5] = etr_params_old[:, :, 6] p.etr_params[:, :, 6] = etr_params_old[:, :, 11] p.etr_params[:, :, 7] = etr_params_old[:, :, 5] p.etr_params[:, :, 8] = etr_params_old[:, :, 7] p.etr_params[:, :, 9] = etr_params_old[:, :, 8] p.etr_params[:, :, 10] = etr_params_old[:, :, 9] p.etr_params[:, :, 11] = etr_params_old[:, :, 10] p.mtrx_params = mtrx_params_old.copy() p.mtrx_params[:, :, 5] = mtrx_params_old[:, :, 6] p.mtrx_params[:, :, 6] = mtrx_params_old[:, :, 11] p.mtrx_params[:, :, 7] = mtrx_params_old[:, :, 5] p.mtrx_params[:, :, 8] = mtrx_params_old[:, :, 7] p.mtrx_params[:, :, 9] = mtrx_params_old[:, :, 8] p.mtrx_params[:, :, 10] = mtrx_params_old[:, :, 9] p.mtrx_params[:, :, 11] = mtrx_params_old[:, :, 10] p.mtry_params = mtry_params_old.copy() p.mtry_params[:, :, 5] = mtry_params_old[:, :, 6] p.mtry_params[:, :, 6] = mtry_params_old[:, :, 11] p.mtry_params[:, :, 7] = mtry_params_old[:, :, 5] p.mtry_params[:, :, 8] = mtry_params_old[:, :, 7] p.mtry_params[:, :, 9] = mtry_params_old[:, :, 8] p.mtry_params[:, :, 10] = mtry_params_old[:, :, 9] p.mtry_params[:, :, 11] = mtry_params_old[:, :, 10] p.lambdas = lambdas.reshape(p.J, 1) p.num_workers = 1 bq = BQ / p.lambdas[j] tr = TR test_list = TPI.firstdoughnutring(guesses, r, w, bq, tr, theta, factor, j, initial_b, p) expected_list = utils.safe_read_pickle( os.path.join(CUR_PATH, 'test_io_data', 'firstdoughnutring_outputs.pkl')) assert (np.allclose(np.array(test_list), np.array(expected_list)))
ids=['scalar', 'vector', 'matrix', '3D array']) def test_get_cons(model_args, expected): # Test consumption calculation r, w, b, b_splus1, n, bq, net_tax, tau_c, p = model_args test_value = household.get_cons(r, w, b, b_splus1, n, bq, net_tax, p.e, tau_c, p) assert np.allclose(test_value, expected) # Define variables for test of SS version p1 = Specifications() p1.e = np.array([1.0, 0.9, 1.4]).reshape(3, 1) p1.sigma = 2.0 p1.J = 1 p1.beta = np.ones(p1.J) * 0.96 p1.g_y = 0.03 p1.chi_b = np.array([1.5]) p1.tau_bq = np.array([0.0]) p1.rho = np.array([0.1, 0.2, 1.0]) p1.lambdas = np.array([1.0]) p1.S = 3 p1.T = 3 p1.analytical_mtrs = False etr_params = np.array([ np.array([[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.33, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.25, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.20, 0]]), np.array([[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.9, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.5, 0]]),
def test_inner_loop(dask_client): # Test TPI.inner_loop function. Provide inputs to function and # ensure that output returned matches what it has been before. input_tuple = utils.safe_read_pickle( os.path.join(CUR_PATH, 'test_io_data', 'tpi_inner_loop_inputs.pkl')) guesses, outer_loop_vars, params, j = input_tuple income_tax_params, tpi_params, initial_values, ind = params initial_values = initial_values[:-1] tpi_params = tpi_params p = Specifications(client=dask_client, num_workers=NUM_WORKERS) (p.J, p.S, p.T, p.BW, beta, p.sigma, p.alpha, p.gamma, p.epsilon, Z, p.delta, p.ltilde, p.nu, p.g_y, p.g_n, tau_b, delta_tau, tau_payroll, tau_bq, p.rho, p.omega, N_tilde, lambdas, p.imm_rates, p.e, retire, p.mean_income_data, factor, h_wealth, p_wealth, m_wealth, p.b_ellipse, p.upsilon, p.chi_b, p.chi_n, theta, p.baseline) = tpi_params p.beta = np.ones(p.J) * beta p.eta = p.omega.reshape(p.T + p.S, p.S, 1) * p.lambdas.reshape(1, p.J) p.Z = np.ones(p.T + p.S) * Z p.tau_bq = np.ones(p.T + p.S) * 0.0 p.tau_payroll = np.ones(p.T + p.S) * tau_payroll p.tau_b = np.ones(p.T + p.S) * tau_b p.delta_tau = np.ones(p.T + p.S) * delta_tau p.h_wealth = np.ones(p.T + p.S) * h_wealth p.p_wealth = np.ones(p.T + p.S) * p_wealth p.m_wealth = np.ones(p.T + p.S) * m_wealth p.retire = (np.ones(p.T + p.S) * retire).astype(int) p.tax_func_type = 'DEP' p.analytical_mtrs, etr_params, mtrx_params, mtry_params =\ income_tax_params p.etr_params = np.transpose(etr_params, (1, 0, 2))[:p.T, :, :] p.mtrx_params = np.transpose(mtrx_params, (1, 0, 2))[:p.T, :, :] p.mtry_params = np.transpose(mtry_params, (1, 0, 2))[:p.T, :, :] etr_params_old = p.etr_params mtrx_params_old = p.mtrx_params mtry_params_old = p.mtry_params p.etr_params = etr_params_old.copy() p.etr_params[:, :, 5] = etr_params_old[:, :, 6] p.etr_params[:, :, 6] = etr_params_old[:, :, 11] p.etr_params[:, :, 7] = etr_params_old[:, :, 5] p.etr_params[:, :, 8] = etr_params_old[:, :, 7] p.etr_params[:, :, 9] = etr_params_old[:, :, 8] p.etr_params[:, :, 10] = etr_params_old[:, :, 9] p.etr_params[:, :, 11] = etr_params_old[:, :, 10] p.mtrx_params = mtrx_params_old.copy() p.mtrx_params[:, :, 5] = mtrx_params_old[:, :, 6] p.mtrx_params[:, :, 6] = mtrx_params_old[:, :, 11] p.mtrx_params[:, :, 7] = mtrx_params_old[:, :, 5] p.mtrx_params[:, :, 8] = mtrx_params_old[:, :, 7] p.mtrx_params[:, :, 9] = mtrx_params_old[:, :, 8] p.mtrx_params[:, :, 10] = mtrx_params_old[:, :, 9] p.mtrx_params[:, :, 11] = mtrx_params_old[:, :, 10] p.mtry_params = mtry_params_old.copy() p.mtry_params[:, :, 5] = mtry_params_old[:, :, 6] p.mtry_params[:, :, 6] = mtry_params_old[:, :, 11] p.mtry_params[:, :, 7] = mtry_params_old[:, :, 5] p.mtry_params[:, :, 8] = mtry_params_old[:, :, 7] p.mtry_params[:, :, 9] = mtry_params_old[:, :, 8] p.mtry_params[:, :, 10] = mtry_params_old[:, :, 9] p.mtry_params[:, :, 11] = mtry_params_old[:, :, 10] p.lambdas = lambdas.reshape(p.J, 1) p.num_workers = 1 (K0, b_sinit, b_splus1init, factor, initial_b, initial_n, p.omega_S_preTP, initial_debt) = initial_values initial_values_in = (K0, b_sinit, b_splus1init, factor, initial_b, initial_n) (r, K, BQ, TR) = outer_loop_vars wss = firm.get_w_from_r(r[-1], p, 'SS') w = np.ones(p.T + p.S) * wss w[:p.T] = firm.get_w_from_r(r[:p.T], p, 'TPI') outer_loop_vars_in = (r, w, r, BQ, TR, theta) guesses = (guesses[0], guesses[1]) test_tuple = TPI.inner_loop(guesses, outer_loop_vars_in, initial_values_in, j, ind, p) expected_tuple = utils.safe_read_pickle( os.path.join(CUR_PATH, 'test_io_data', 'tpi_inner_loop_outputs.pkl')) for i, v in enumerate(expected_tuple): assert (np.allclose(test_tuple[i], v))