Exemplo n.º 1
0
def test_runner():
    # Monkey patch enforcement flag since small data won't pass checks
    SS.ENFORCE_SOLUTION_CHECKS = False
    TPI.ENFORCE_SOLUTION_CHECKS = False
    BASELINE_DIR = './OUTPUT_BASELINE_'
    runner(output_base=BASELINE_DIR, baseline_dir=BASELINE_DIR, test=True,
           time_path=True, baseline=True, run_micro=False, data='cps')
Exemplo n.º 2
0
def test_frisch(frisch):
    output_base = os.path.join(CUR_PATH, "OUTPUT")
    input_dir = os.path.join(CUR_PATH, "OUTPUT")
    user_params = {'frisch': frisch, 'debt_ratio_ss': 1.0}
    runner(output_base=output_base, baseline_dir=input_dir, test=False,
           time_path=False, baseline=True, user_params=user_params,
           run_micro=False, data=PUF_PATH)
Exemplo n.º 3
0
def test_frisch(frisch):
    output_base = os.path.join(CUR_PATH, "OUTPUT")
    input_dir = os.path.join(CUR_PATH, "OUTPUT")
    og_spec = {'frisch': frisch, 'debt_ratio_ss': 1.0}
    runner(output_base=output_base, baseline_dir=input_dir, test=False,
           time_path=False, baseline=True, og_spec=og_spec,
           run_micro=False, data=PUF_PATH)
Exemplo n.º 4
0
def test_run_SS(baseline, param_updates, filename, dask_client):
    # Test SS.run_SS function.  Provide inputs to function and
    # ensure that output returned matches what it has been before.
    if baseline is False:
        tax_func_path_baseline = os.path.join(CUR_PATH,
                                              'TxFuncEst_baseline.pkl')
        tax_func_path = os.path.join(CUR_PATH, 'TxFuncEst_policy.pkl')
        execute.runner(constants.BASELINE_DIR,
                       constants.BASELINE_DIR,
                       time_path=False,
                       baseline=True,
                       og_spec=param_updates,
                       run_micro=False,
                       tax_func_path=tax_func_path_baseline)
    else:
        tax_func_path = os.path.join(CUR_PATH, 'TxFuncEst_baseline.pkl')
    p = Specifications(baseline=baseline,
                       client=dask_client,
                       num_workers=NUM_WORKERS)
    p.update_specifications(param_updates)
    p.get_tax_function_parameters(None,
                                  run_micro=False,
                                  tax_func_path=tax_func_path)
    test_dict = SS.run_SS(p, None)
    expected_dict = utils.safe_read_pickle(
        os.path.join(CUR_PATH, 'test_io_data', filename))

    for k, v in expected_dict.items():
        assert (np.allclose(test_dict[k], v))
Exemplo n.º 5
0
def test_gy(g_y_annual):
    output_base = os.path.join(CUR_PATH, "OUTPUT")
    input_dir = os.path.join(CUR_PATH, "OUTPUT")
    user_params = {'frisch': 0.41, 'debt_ratio_ss': 1.0,
                   'g_y_annual': g_y_annual}
    runner(output_base=output_base, baseline_dir=input_dir, test=False,
           time_path=False, baseline=True, user_params=user_params,
           run_micro=False, data=PUF_PATH)
Exemplo n.º 6
0
def test_gy(g_y_annual):
    output_base = os.path.join(CUR_PATH, "OUTPUT")
    input_dir = os.path.join(CUR_PATH, "OUTPUT")
    og_spec = {'frisch': 0.41, 'debt_ratio_ss': 1.0,
               'g_y_annual': g_y_annual}
    runner(output_base=output_base, baseline_dir=input_dir, test=False,
           time_path=False, baseline=True, og_spec=og_spec,
           run_micro=False, data=PUF_PATH)
Exemplo n.º 7
0
def run_micro_macro(reform, user_params, guid):

    guid = ''
    start_time = time.time()

    REFORM_DIR = "./OUTPUT_REFORM_" + guid
    BASELINE_DIR = "./OUTPUT_BASELINE_" + guid

    # Add start year from reform to user parameters
    start_year = sorted(reform.keys())[0]
    user_params['start_year'] = start_year

    with open("log_{}.log".format(guid), 'w') as f:
        f.write("guid: {}\n".format(guid))
        f.write("reform: {}\n".format(reform))
        f.write("user_params: {}\n".format(user_params))
    '''
    ------------------------------------------------------------------------
        Run baseline
    ------------------------------------------------------------------------
    '''
    output_base = BASELINE_DIR
    kwargs = {
        'output_base': output_base,
        'baseline_dir': BASELINE_DIR,
        'test': True,
        'time_path': True,
        'baseline': True,
        'user_params': user_params,
        'run_micro': False,
        'guid': guid
    }
    runner(**kwargs)
    '''
    ------------------------------------------------------------------------
        Run reform
    ------------------------------------------------------------------------
    '''

    output_base = REFORM_DIR
    kwargs = {
        'output_base': output_base,
        'baseline_dir': BASELINE_DIR,
        'test': True,
        'time_path': True,
        'baseline': False,
        'reform': reform,
        'user_params': user_params,
        'guid': guid,
        'run_micro': False
    }
    runner(**kwargs)
    time.sleep(0.5)
    ans = postprocess.create_diff(baseline_dir=BASELINE_DIR,
                                  policy_dir=REFORM_DIR)
    print("total time was ", (time.time() - start_time))

    return ans
Exemplo n.º 8
0
def test_runner_reform(dask_client):
    runner(output_base=REFORM_DIR,
           baseline_dir=BASELINE_DIR,
           test=True,
           time_path=False,
           baseline=False,
           run_micro=False,
           data='cps',
           client=dask_client,
           num_workers=NUM_WORKERS)
Exemplo n.º 9
0
def test_diff_start_year(year):
    # Monkey patch enforcement flag since small data won't pass checks
    SS.ENFORCE_SOLUTION_CHECKS = False
    TPI.ENFORCE_SOLUTION_CHECKS = False
    output_base = os.path.join(CUR_PATH, "STARTYEAR_OUTPUT")
    input_dir = os.path.join(CUR_PATH, "STARTYEAR_OUTPUT")
    user_params = {'frisch': 0.41, 'debt_ratio_ss': 1.0,
                   'start_year': year}
    runner(output_base=output_base, baseline_dir=input_dir, test=True,
           time_path=True, baseline=True, user_params=user_params,
           run_micro=True, data=PUF_PATH)
Exemplo n.º 10
0
def test_sigma(sigma, dask_client):
    og_spec = {'frisch': 0.41, 'debt_ratio_ss': 1.0, 'sigma': sigma}
    runner(output_base=OUTPUT_DIR,
           baseline_dir=OUTPUT_DIR,
           test=False,
           time_path=False,
           baseline=True,
           og_spec=og_spec,
           run_micro=False,
           tax_func_path=TAX_FUNC_PATH,
           client=dask_client,
           num_workers=NUM_WORKERS)
Exemplo n.º 11
0
def test_run_small(time_path):
    from ogusa.execute import runner
    # Monkey patch enforcement flag since small data won't pass checks
    SS.ENFORCE_SOLUTION_CHECKS = False
    TPI.ENFORCE_SOLUTION_CHECKS = False
    SS.MINIMIZER_TOL = 1e-6
    TPI.MINIMIZER_TOL = 1e-6
    output_base = os.path.join(CUR_PATH, 'OUTPUT')
    input_dir = output_base
    og_spec = {'frisch': 0.41, 'debt_ratio_ss': 0.4}
    runner(output_base=output_base, baseline_dir=input_dir, test=True,
           time_path=time_path, baseline=True, og_spec=og_spec,
           run_micro=False)
Exemplo n.º 12
0
def test_gy(g_y_annual, dask_client):
    og_spec = {'frisch': 0.41, 'debt_ratio_ss': 1.0, 'g_y_annual': g_y_annual}
    runner(output_base=OUTPUT_DIR,
           baseline_dir=OUTPUT_DIR,
           test=False,
           time_path=False,
           baseline=True,
           og_spec=og_spec,
           run_micro=False,
           tax_func_path=TAX_FUNC_PATH,
           data=PUF_PATH,
           client=dask_client,
           num_workers=NUM_WORKERS)
Exemplo n.º 13
0
def test_run_small(time_path):
    from ogusa.execute import runner
    # Monkey patch enforcement flag since small data won't pass checks
    SS.ENFORCE_SOLUTION_CHECKS = False
    TPI.ENFORCE_SOLUTION_CHECKS = False
    SS.MINIMIZER_TOL = 1e-6
    TPI.MINIMIZER_TOL = 1e-6
    output_base = "./OUTPUT"
    input_dir = "./OUTPUT"
    user_params = {'frisch': 0.41, 'debt_ratio_ss': 0.4}
    runner(output_base=output_base, baseline_dir=input_dir, test=True,
           time_path=time_path, baseline=True, user_params=user_params,
           run_micro=False)
def test_diff_start_year(year):
    # Monkey patch enforcement flag since small data won't pass checks
    SS.ENFORCE_SOLUTION_CHECKS = False
    TPI.ENFORCE_SOLUTION_CHECKS = False
    output_base = os.path.join(CUR_PATH, "STARTYEAR_OUTPUT")
    input_dir = os.path.join(CUR_PATH, "STARTYEAR_OUTPUT")
    user_params = {'frisch': 0.41, 'debt_ratio_ss': 1.0, 'start_year': year}
    runner(output_base=output_base,
           baseline_dir=input_dir,
           test=True,
           time_path=True,
           baseline=True,
           user_params=user_params,
           run_micro=True,
           data=PUF_PATH)
Exemplo n.º 15
0
def run_micro_macro(reform, user_params, guid):

    guid = ''
    start_time = time.time()

    REFORM_DIR = "./OUTPUT_REFORM_" + guid
    BASELINE_DIR = "./OUTPUT_BASELINE_" + guid

    # Add start year from reform to user parameters
    start_year = sorted(reform.keys())[0]
    user_params['start_year'] = start_year

    with open("log_{}.log".format(guid), 'w') as f:
        f.write("guid: {}\n".format(guid))
        f.write("reform: {}\n".format(reform))
        f.write("user_params: {}\n".format(user_params))

    '''
    ------------------------------------------------------------------------
        Run baseline
    ------------------------------------------------------------------------
    '''
    output_base = BASELINE_DIR
    kwargs = {'output_base': output_base, 'baseline_dir': BASELINE_DIR,
              'test': True, 'time_path': True, 'baseline': True,
              'user_params': user_params, 'run_micro': False,
              'guid': guid}
    runner(**kwargs)

    '''
    ------------------------------------------------------------------------
        Run reform
    ------------------------------------------------------------------------
    '''

    output_base = REFORM_DIR
    kwargs = {'output_base': output_base, 'baseline_dir': BASELINE_DIR,
              'test': True, 'time_path': True, 'baseline': False,
              'reform': reform, 'user_params': user_params,
              'guid': guid, 'run_micro': False}
    runner(**kwargs)
    time.sleep(0.5)
    ans = postprocess.create_diff(baseline_dir=BASELINE_DIR,
                                  policy_dir=REFORM_DIR)
    print("total time was ", (time.time() - start_time))

    return ans
Exemplo n.º 16
0
def test_diff_start_year(year, dask_client):
    # Monkey patch enforcement flag since small data won't pass checks
    SS.ENFORCE_SOLUTION_CHECKS = False
    TPI.ENFORCE_SOLUTION_CHECKS = False
    output_base = os.path.join(CUR_PATH, "STARTYEAR_OUTPUT")
    input_dir = os.path.join(CUR_PATH, "STARTYEAR_OUTPUT")
    og_spec = {'frisch': 0.41, 'debt_ratio_ss': 1.0, 'start_year': year}
    runner(output_base=output_base,
           baseline_dir=input_dir,
           test=True,
           time_path=True,
           baseline=True,
           og_spec=og_spec,
           run_micro=True,
           data='cps',
           client=dask_client,
           num_workers=NUM_WORKERS)
Exemplo n.º 17
0
def test_run_small(time_path):
    from ogusa.execute import runner
    # Monkey patch enforcement flag since small data won't pass checks
    SS.ENFORCE_SOLUTION_CHECKS = False
    TPI.ENFORCE_SOLUTION_CHECKS = False
    SS.MINIMIZER_TOL = 1e-6
    TPI.MINIMIZER_TOL = 1e-6
    output_base = "./OUTPUT"
    input_dir = "./OUTPUT"
    user_params = {'frisch': 0.41, 'debt_ratio_ss': 0.4}
    runner(output_base=output_base,
           baseline_dir=input_dir,
           test=True,
           time_path=time_path,
           baseline=True,
           user_params=user_params,
           run_micro=False)
Exemplo n.º 18
0
def test_run_small(time_path, dask_client):
    from ogusa.execute import runner
    # Monkey patch enforcement flag since small data won't pass checks
    SS.ENFORCE_SOLUTION_CHECKS = False
    TPI.ENFORCE_SOLUTION_CHECKS = False
    SS.MINIMIZER_TOL = 1e-6
    TPI.MINIMIZER_TOL = 1e-6
    og_spec = {'frisch': 0.41, 'debt_ratio_ss': 0.4}
    runner(output_base=OUTPUT_DIR,
           baseline_dir=OUTPUT_DIR,
           test=True,
           time_path=time_path,
           baseline=True,
           og_spec=og_spec,
           run_micro=False,
           tax_func_path=TAX_FUNC_PATH,
           client=dask_client,
           num_workers=NUM_WORKERS)
Exemplo n.º 19
0
def run_micro_macro(user_params):
    # Grab a reform JSON file already in Tax-Calculator
    # In this example the 'reform' is a change to 2017 law (the
    # baseline policy is tax law in 2018)
    reform_url = ('https://raw.githubusercontent.com/'
                  'PSLmodels/Tax-Calculator/master/taxcalc/'
                  'reforms/2017_law.json')
    ref = Calculator.read_json_param_objects(reform_url, None)
    reform = ref['policy']

    # Define parameters to use for multiprocessing
    client = Client(processes=False)
    num_workers = 1  # multiprocessing.cpu_count()
    print('Number of workers = ', num_workers)
    start_time = time.time()

    # Set some model parameters
    # See parameters.py for description of these parameters
    alpha_T = np.zeros(50)
    alpha_T[0:2] = 0.09
    alpha_T[2:10] = 0.09 + 0.01
    alpha_T[10:40] = 0.09 - 0.01
    alpha_T[40:] = 0.09
    alpha_G = np.zeros(7)
    alpha_G[0:3] = 0.05 - 0.01
    alpha_G[3:6] = 0.05 - 0.005
    alpha_G[6:] = 0.05
    small_open = False
    user_params = {'frisch': 0.41, 'start_year': 2018,
                   'tau_b': [(0.21 * 0.55) * (0.017 / 0.055), (0.21 * 0.55) * (0.017 / 0.055)],
                   'debt_ratio_ss': 1.0, 'alpha_T': alpha_T.tolist(),
                   'alpha_G': alpha_G.tolist(), 'small_open': small_open}

    '''
    ------------------------------------------------------------------------
    Run baseline policy first
    ------------------------------------------------------------------------
    '''
    output_base = BASELINE_DIR
    kwargs = {'output_base': output_base, 'baseline_dir': BASELINE_DIR,
              'test': False, 'time_path': True, 'baseline': True,
              'user_params': user_params, 'guid': '_example',
              'run_micro': True, 'data': 'cps', 'client': client,
              'num_workers': num_workers}

    start_time = time.time()
    runner(**kwargs)
    print('run time = ', time.time()-start_time)

    '''
    ------------------------------------------------------------------------
    Run reform policy
    ------------------------------------------------------------------------
    '''
    user_params = {'frisch': 0.41, 'start_year': 2018,
                   'tau_b': [(0.35 * 0.55) * (0.017 / 0.055)],
                   'debt_ratio_ss': 1.0, 'alpha_T': alpha_T.tolist(),
                   'alpha_G': alpha_G.tolist(), 'small_open': small_open}
    output_base = REFORM_DIR
    kwargs = {'output_base': output_base, 'baseline_dir': BASELINE_DIR,
              'test': False, 'time_path': True, 'baseline': False,
              'user_params': user_params, 'guid': '_example',
              'reform': reform, 'run_micro': True, 'data': 'cps',
              'client': client, 'num_workers': num_workers}

    start_time = time.time()
    runner(**kwargs)
    print('run time = ', time.time()-start_time)

    # return ans - the percentage changes in macro aggregates and prices
    # due to policy changes from the baseline to the reform
    ans = postprocess.create_diff(
        baseline_dir=BASELINE_DIR, policy_dir=REFORM_DIR)

    print("total time was ", (time.time() - start_time))
    print('Percentage changes in aggregates:', ans)
Exemplo n.º 20
0
           'alpha_G': alpha_G.tolist()}

'''
------------------------------------------------------------------------
Run baseline policy first
------------------------------------------------------------------------
'''
output_base = BASELINE_DIR
kwargs = {'output_base': output_base, 'baseline_dir': BASELINE_DIR,
          'test': False, 'time_path': True, 'baseline': True,
          'og_spec': og_spec, 'guid': '_example',
          'run_micro': True, 'data': 'cps', 'client': client,
          'num_workers': num_workers}

start_time = time.time()
runner(**kwargs)
print('run time = ', time.time()-start_time)

'''
------------------------------------------------------------------------
Run reform policy
------------------------------------------------------------------------
'''
# update the effective corporate income tax rate
og_spec = {'frisch': 0.41, 'start_year': 2018,
           'tau_b': [0.0595], 'debt_ratio_ss': 1.0,
           'alpha_T': alpha_T.tolist(),
           'alpha_G': alpha_G.tolist()}
output_base = REFORM_DIR
kwargs = {'output_base': output_base, 'baseline_dir': BASELINE_DIR,
          'test': False, 'time_path': True, 'baseline': False,
Exemplo n.º 21
0
def run_micro_macro(user_params):
    # Grab a reform JSON file already in Tax-Calculator
    # In this example the 'reform' is a change to 2017 law (the
    # baseline policy is tax law in 2018)
    ref = Calculator.read_json_param_objects('2017_law.json', None)
    reform = ref['policy']

    # Define parameters to use for multiprocessing
    client = Client(processes=False)
    num_workers = 1  # multiprocessing.cpu_count()
    print('Number of workers = ', num_workers)
    start_time = time.time()

    # Set some model parameters
    # See parameters.py for description of these parameters
    alpha_T = np.ones(50)
    alpha_T *= 0.1234784428  #Japan transfers
    #alpha_T[0:2] = 0.09
    #alpha_T[2:10] = 0.09 + 0.01
    #alpha_T[10:40] = 0.09 - 0.01
    #alpha_T[40:] = 0.09
    alpha_G = np.ones(7)
    alpha_G *= 0.01239313481  #Japan discretionary spending
    #alpha_G[0:3] = 0.05 - 0.01
    #alpha_G[3:6] = 0.05 - 0.005
    #alpha_G[6:] = 0.05
    small_open = False
    user_params = {
        'frisch': 0.41,
        'start_year': 2018,
        'tau_b': [(0.21 * 0.55) * (0.017 / 0.055),
                  (0.21 * 0.55) * (0.017 / 0.055)],
        'debt_ratio_ss': 2.0,
        'alpha_T': alpha_T.tolist(),
        'alpha_G': alpha_G.tolist(),
        'small_open': small_open
    }

    # debt_ratio_ss: changed to 2
    # alpha_T: can make this smaller to have transfers lower
    # tau_b 55% class c corporates, 21% corporate tax
    '''
    ------------------------------------------------------------------------
    Run baseline policy first
    ------------------------------------------------------------------------
    '''
    output_base = BASELINE_DIR
    kwargs = {
        'output_base': output_base,
        'baseline_dir': BASELINE_DIR,
        'test': False,
        'time_path': True,
        'baseline': True,
        'user_params': user_params,
        'guid': '_example',
        'run_micro': False,
        'data': 'cps',
        'client': client,
        'num_workers': num_workers
    }

    # run_micro: false because already have taxfunc
    # Set 'time_path': False to stop from running transition path
    # updated and included 'tax_func_type'
    # set run_micro: False to stop it from running taxfunc
    # 'tax_func_type': 'GS',

    start_time = time.time()
    runner(**kwargs)
    print('run time = ', time.time() - start_time)
    '''
    '''
    '''
    ------------------------------------------------------------------------
    Run reform policy
    ------------------------------------------------------------------------
    '''
    '''
Exemplo n.º 22
0
def run_micro_macro(user_params):
    # Grab a reform JSON file already in Tax-Calculator
    # In this example the 'reform' is a change to 2017 law (the
    # baseline policy is tax law in 2018)
    reform_url = ('https://raw.githubusercontent.com/'
                  'PSLmodels/Tax-Calculator/master/taxcalc/'
                  'reforms/2017_law.json')
    #ref = Calculator.read_json_param_objects(reform_url, None) # Modified
    #reform = ref['policy'] # Modified

    # Define parameters to use for multiprocessing
    client = Client(processes=False)
    num_workers = 1  # multiprocessing.cpu_count()
    print('Number of workers = ', num_workers)
    start_time = time.time()

    # Set some model parameters
    # See parameters.py for description of these parameters
    alpha_T = np.ones(50) * 0.1230058215  # Modified
    alpha_G = np.ones(7) * 0.01234569933  # Modified
    small_open = False
    user_params = {
        'frisch': 0.5,
        'start_year': 2018,
        'tau_b': [(0.21 * 0.55) * (0.017 / 0.055),
                  (0.21 * 0.55) * (0.017 / 0.055)],
        'debt_ratio_ss': 2.0,
        'alpha_T': alpha_T.tolist(),
        'alpha_G': alpha_G.tolist(),
        'small_open': small_open
    }  # modified
    '''
    ------------------------------------------------------------------------
    Run baseline policy first
    ------------------------------------------------------------------------
    '''
    output_base = BASELINE_DIR
    kwargs = {
        'output_base': output_base,
        'baseline_dir': BASELINE_DIR,
        'test': False,
        'time_path': False,
        'baseline': True,
        'user_params': user_params,
        'guid': '_example',
        'run_micro': False,
        'data': 'cps',
        'client': client,
        'num_workers': num_workers
    }

    start_time = time.time()
    runner(**kwargs)
    print('run time = ', time.time() - start_time)
    '''
    ------------------------------------------------------------------------
    Run reform policy
    ------------------------------------------------------------------------
    '''
    user_params = {
        'frisch': 0.5,
        'start_year': 2018,
        'tau_b': [(0.35 * 0.55) * (0.017 / 0.055)],
        'debt_ratio_ss': 1.0,
        'alpha_T': alpha_T.tolist(),
        'alpha_G': alpha_G.tolist(),
        'small_open': small_open
    }
    output_base = REFORM_DIR
    kwargs = {
        'output_base': output_base,
        'baseline_dir': BASELINE_DIR,
        'test': False,
        'time_path': True,
        'baseline': False,
        'user_params': user_params,
        'guid': '_example',
        'reform': reform,
        'run_micro': True,
        'data': 'cps',
        'client': client,
        'num_workers': num_workers
    }

    start_time = time.time()
    runner(**kwargs)
    print('run time = ', time.time() - start_time)

    # return ans - the percentage changes in macro aggregates and prices
    # due to policy changes from the baseline to the reform
    ans = postprocess.create_diff(baseline_dir=BASELINE_DIR,
                                  policy_dir=REFORM_DIR)

    print("total time was ", (time.time() - start_time))
    print('Percentage changes in aggregates:', ans)
Exemplo n.º 23
0
def main():
    # Define parameters to use for multiprocessing
    client = Client()
    num_workers = min(multiprocessing.cpu_count(), 7)
    print('Number of workers = ', num_workers)
    run_start_time = time.time()

    # Grab a reform JSON file already in Tax-Calculator
    # In this example the 'reform' is a change to 2017 law (the
    # baseline policy is tax law in 2018)
    reform_url = ('https://raw.githubusercontent.com/'
                  'PSLmodels/Tax-Calculator/' + taxcalc.__version__ +
                  '/taxcalc/reforms/2017_law.json')
    ref = Calculator.read_json_param_objects(reform_url, None)
    iit_reform = ref['policy']

    # Directories to save data
    CUR_DIR = os.path.dirname(os.path.realpath(__file__))
    base_dir = os.path.join(CUR_DIR, BASELINE_DIR)
    reform_dir = os.path.join(CUR_DIR, REFORM_DIR)

    # Set some OG model parameters
    # See default_parameters.json for more description of these parameters
    alpha_T = np.zeros(50)  # Adjusting the path of transfer spending
    alpha_T[0:2] = 0.09
    alpha_T[2:10] = 0.09 + 0.01
    alpha_T[10:40] = 0.09 - 0.01
    alpha_T[40:] = 0.09
    alpha_G = np.zeros(7)  # Adjusting the path of non-transfer spending
    alpha_G[0:3] = 0.05 - 0.01
    alpha_G[3:6] = 0.05 - 0.005
    alpha_G[6:] = 0.05
    # Set start year for baseline and reform.
    START_YEAR = 2021
    # Also adjust the Frisch elasticity, the start year, the
    # effective corporate income tax rate, and the SS debt-to-GDP ratio
    og_spec = {
        'frisch': 0.41,
        'start_year': START_YEAR,
        'cit_rate': [0.21],
        'debt_ratio_ss': 1.0,
        'alpha_T': alpha_T.tolist(),
        'alpha_G': alpha_G.tolist()
    }
    '''
    ------------------------------------------------------------------------
    Run baseline policy first
    ------------------------------------------------------------------------
    '''
    tax_func_path = os.path.join(
        CUR_DIR, '..', 'ogusa', 'data', 'tax_functions',
        'TxFuncEst_baseline_CPS.pkl')  # use cached baseline estimates
    kwargs = {
        'output_base': base_dir,
        'baseline_dir': base_dir,
        'test': False,
        'time_path': True,
        'baseline': True,
        'og_spec': og_spec,
        'guid': '_example',
        'run_micro': False,
        'tax_func_path': tax_func_path,
        'data': 'cps',
        'client': client,
        'num_workers': num_workers
    }

    start_time = time.time()
    runner(**kwargs)
    print('run time = ', time.time() - start_time)
    '''
    ------------------------------------------------------------------------
    Run reform policy
    ------------------------------------------------------------------------
    '''
    # update the effective corporate income tax rate
    og_spec = {
        'frisch': 0.41,
        'start_year': START_YEAR,
        'cit_rate': [0.35],
        'debt_ratio_ss': 1.0,
        'alpha_T': alpha_T.tolist(),
        'alpha_G': alpha_G.tolist()
    }
    kwargs = {
        'output_base': reform_dir,
        'baseline_dir': base_dir,
        'test': False,
        'time_path': True,
        'baseline': False,
        'og_spec': og_spec,
        'guid': '_example',
        'iit_reform': iit_reform,
        'run_micro': True,
        'data': 'cps',
        'client': client,
        'num_workers': num_workers
    }

    start_time = time.time()
    runner(**kwargs)
    print('run time = ', time.time() - start_time)

    # return ans - the percentage changes in macro aggregates and prices
    # due to policy changes from the baseline to the reform
    base_tpi = safe_read_pickle(os.path.join(base_dir, 'TPI', 'TPI_vars.pkl'))
    base_params = safe_read_pickle(os.path.join(base_dir, 'model_params.pkl'))
    reform_tpi = safe_read_pickle(
        os.path.join(reform_dir, 'TPI', 'TPI_vars.pkl'))
    reform_params = safe_read_pickle(
        os.path.join(reform_dir, 'model_params.pkl'))
    ans = ot.macro_table(base_tpi,
                         base_params,
                         reform_tpi=reform_tpi,
                         reform_params=reform_params,
                         var_list=['Y', 'C', 'K', 'L', 'r', 'w'],
                         output_type='pct_diff',
                         num_years=10,
                         start_year=og_spec['start_year'])

    # create plots of output
    op.plot_all(base_dir, reform_dir, os.path.join(CUR_DIR,
                                                   'run_example_plots'))

    print("total time was ", (time.time() - run_start_time))
    print('Percentage changes in aggregates:', ans)
    # save percentage change output to csv file
    ans.to_csv('ogusa_example_output.csv')
    client.close()
Exemplo n.º 24
0
def run_micro_macro(user_params,
                    reform=None,
                    baseline_dir=BASELINE_DIR,
                    reform_dir=REFORM_DIR,
                    guid='',
                    data=PUF_PATH,
                    ok_to_run_baseline=True):

    start_time = time.time()

    T_shifts = np.zeros(50)
    T_shifts[2:10] = 0.01
    T_shifts[10:40] = -0.01
    G_shifts = np.zeros(6)
    G_shifts[0:3] = -0.01
    G_shifts[3:6] = -0.005
    user_params = {
        'frisch': 0.41,
        'start_year': 2017,
        'tau_b': 0.20,
        'debt_ratio_ss': 1.0,
        'delta_tau_annual': 0.05,
        'T_shifts': T_shifts.tolist(),
        'G_shifts': G_shifts.tolist()
    }
    '''
    ------------------------------------------------------------------------
        Run baseline
    ------------------------------------------------------------------------
    '''
    print('path exists', not os.path.exists(baseline_dir), ok_to_run_baseline)
    # if not os.path.exists(baseline_dir) and ok_to_run_baseline:
    if ok_to_run_baseline:
        output_base = baseline_dir
        kwargs = {
            'output_base': baseline_dir,
            'baseline_dir': baseline_dir,
            'test': False,
            'time_path': True,
            'baseline': True,
            'analytical_mtrs': False,
            'age_specific': True,
            'user_params': user_params,
            'guid': '',
            'run_micro': False,
            'small_open': False,
            'budget_balance': False,
            'baseline_spending': False,
            'data': data,
            'client': client,
            'num_workers': 4
        }
        runner(**kwargs)
    '''
    ------------------------------------------------------------------------
        Run reform
    ------------------------------------------------------------------------
    '''
    output_base = reform_dir
    kwargs = {
        'output_base': output_base,
        'baseline_dir': baseline_dir,
        'test': False,
        'time_path': True,
        'baseline': False,
        'analytical_mtrs': False,
        'age_specific': True,
        'user_params': user_params,
        'guid': guid,
        'reform': reform,
        'run_micro': False,
        'small_open': False,
        'budget_balance': False,
        'baseline_spending': False,
        'data': data,
        'client': client,
        'num_workers': 4
    }
    runner(**kwargs)

    ans = postprocess.create_diff(baseline_dir=baseline_dir,
                                  policy_dir=reform_dir)

    print("total time was ", (time.time() - start_time))
    print('Percentage changes in aggregates:', ans)
Exemplo n.º 25
0
def test_runner_reform(dask_client):
    runner(output_base=REFORM_DIR, baseline_dir=BASELINE_DIR,
           test=True, time_path=False, baseline=False,
           og_spec={'start_year': 2018}, run_micro=False,
           tax_func_path=REFORM_TAX, data='cps', client=dask_client,
           num_workers=NUM_WORKERS)
Exemplo n.º 26
0
def main():
    # Define parameters to use for multiprocessing
    client = Client(processes=False)
    num_workers = min(multiprocessing.cpu_count(), 7)
    print('Number of workers = ', num_workers)
    run_start_time = time.time()

    # Grab a reform JSON file already in Tax-Calculator
    # In this example the 'reform' is a change to 2017 law (the
    # baseline policy is tax law in 2018)
    reform_url = ('https://raw.githubusercontent.com/'
                  'PSLmodels/Tax-Calculator/master/taxcalc/'
                  'reforms/2017_law.json')
    ref = Calculator.read_json_param_objects(reform_url, None)
    iit_reform = ref['policy']

    # Directories to save data
    CUR_DIR = os.path.dirname(os.path.realpath(__file__))
    base_dir = os.path.join(CUR_DIR, BASELINE_DIR, "SS")
    reform_dir = os.path.join(CUR_DIR, REFORM_DIR, "SS")

    # Set some OG model parameters
    # See default_parameters.json for more description of these parameters
    alpha_T = np.zeros(50)  # Adjusting the path of transfer spending
    alpha_T[0:2] = 0.09
    alpha_T[2:10] = 0.09 + 0.01
    alpha_T[10:40] = 0.09 - 0.01
    alpha_T[40:] = 0.09
    alpha_G = np.zeros(7)  # Adjusting the path of non-transfer spending
    alpha_G[0:3] = 0.05 - 0.01
    alpha_G[3:6] = 0.05 - 0.005
    alpha_G[6:] = 0.05
    # Also adjust the Frisch elasticity, the start year, the
    # effective corporate income tax rate, and the SS debt-to-GDP ratio
    og_spec = {
        'frisch': 0.41,
        'start_year': 2018,
        'tau_b': [0.0357],
        'debt_ratio_ss': 1.0,
        'alpha_T': alpha_T.tolist(),
        'alpha_G': alpha_G.tolist()
    }
    '''
    ------------------------------------------------------------------------
    Run baseline policy first
    ------------------------------------------------------------------------
    '''
    output_base = BASELINE_DIR
    kwargs = {
        'output_base': base_dir,
        'baseline_dir': base_dir,
        'test': False,
        'time_path': True,
        'baseline': True,
        'og_spec': og_spec,
        'guid': '_example',
        'run_micro': True,
        'data': 'cps',
        'client': client,
        'num_workers': num_workers
    }

    start_time = time.time()
    runner(**kwargs)
    print('run time = ', time.time() - start_time)
    '''
    ------------------------------------------------------------------------
    Run reform policy
    ------------------------------------------------------------------------
    '''
    # update the effective corporate income tax rate
    og_spec = {
        'frisch': 0.41,
        'start_year': 2018,
        'tau_b': [0.0595],
        'debt_ratio_ss': 1.0,
        'alpha_T': alpha_T.tolist(),
        'alpha_G': alpha_G.tolist()
    }
    output_base = REFORM_DIR
    kwargs = {
        'output_base': reform_dir,
        'baseline_dir': base_dir,
        'test': False,
        'time_path': True,
        'baseline': False,
        'og_spec': og_spec,
        'guid': '_example',
        'iit_reform': iit_reform,
        'run_micro': True,
        'data': 'cps',
        'client': client,
        'num_workers': num_workers
    }

    start_time = time.time()
    runner(**kwargs)
    print('run time = ', time.time() - start_time)

    # return ans - the percentage changes in macro aggregates and prices
    # due to policy changes from the baseline to the reform
    ans = postprocess.create_diff(baseline_dir=base_dir, policy_dir=reform_dir)

    print("total time was ", (time.time() - run_start_time))
    print('Percentage changes in aggregates:', ans)
Exemplo n.º 27
0
def main():
    # Define parameters to use for multiprocessing
    client = Client()
    num_workers = min(multiprocessing.cpu_count(), 12)
    print('Number of workers = ', num_workers)
    run_start_time = time.time()

    reform_url = ('biden-iitax-reforms.json')
    ref = Calculator.read_json_param_objects(reform_url, None)
    iit_reform = ref['policy']

    # Directories to save data
    CUR_DIR = os.path.dirname(os.path.realpath(__file__))
    base_dir = os.path.join(CUR_DIR, BASELINE_DIR)
    reform_dir = os.path.join(CUR_DIR, REFORM_DIR)
    '''
    ------------------------------------------------------------------------
    Run baseline policy first
    ------------------------------------------------------------------------
    '''
    og_spec_base = {
        'start_year': 2021,
        'tG1': 20,
        'tG2': 200,
        'initial_debt_ratio': 0.982,
        'debt_ratio_ss': 1.5,
        'tax_func_type': 'DEP',
        'age_specific': True
    }
    kwargs = {
        'output_base': base_dir,
        'baseline_dir': base_dir,
        'test': False,
        'time_path': True,
        'baseline': True,
        'og_spec': og_spec_base,
        'guid': '_biden',
        'run_micro': True,
        'tax_func_path': None,
        'data': 'cps',
        'client': client,
        'num_workers': num_workers
    }

    start_time = time.time()
    runner(**kwargs)
    print('run time = ', time.time() - start_time)
    '''
    ------------------------------------------------------------------------
    Run reform policy
    ------------------------------------------------------------------------
    '''
    # update the effective corporate income tax rate
    og_spec_reform = {
        'start_year': 2021,
        'tG1': 20,
        'tG2': 200,
        'initial_debt_ratio': 0.982,
        'debt_ratio_ss': 1.5,
        'tax_func_type': 'DEP',
        'age_specific': True,
        'cit_rate': [0.28]
    }
    kwargs = {
        'output_base': reform_dir,
        'baseline_dir': base_dir,
        'test': False,
        'time_path': True,
        'baseline': False,
        'og_spec': og_spec_reform,
        'guid': '_biden',
        'iit_reform': iit_reform,
        'run_micro': True,
        'tax_func_path': None,
        'data': 'cps',
        'client': client,
        'num_workers': num_workers
    }

    start_time = time.time()
    runner(**kwargs)
    print('run time = ', time.time() - start_time)

    # return ans - the percentage changes in macro aggregates and prices
    # due to policy changes from the baseline to the reform
    base_tpi = safe_read_pickle(os.path.join(base_dir, 'TPI', 'TPI_vars.pkl'))
    base_ss = safe_read_pickle(os.path.join(base_dir, 'SS', 'SS_vars.pkl'))
    base_params = safe_read_pickle(os.path.join(base_dir, 'model_params.pkl'))
    reform_tpi = safe_read_pickle(
        os.path.join(reform_dir, 'TPI', 'TPI_vars.pkl'))
    reform_ss = safe_read_pickle(os.path.join(reform_dir, 'SS', 'SS_vars.pkl'))
    reform_params = safe_read_pickle(
        os.path.join(reform_dir, 'model_params.pkl'))

    # Macro Agg Tables
    ans0 = ot.macro_table(base_tpi,
                          base_params,
                          reform_tpi=reform_tpi,
                          reform_params=reform_params,
                          var_list=['Y', 'C', 'K', 'L', 'r', 'w'],
                          output_type='pct_diff',
                          num_years=10,
                          start_year=2021)
    ans1 = ot.macro_table(base_tpi,
                          base_params,
                          reform_tpi=reform_tpi,
                          reform_params=reform_params,
                          var_list=['Y', 'C', 'K', 'L', 'r', 'w'],
                          output_type='pct_diff',
                          num_years=10,
                          start_year=2031)

    # Dynamic Revenue Feedback Table
    ans2 = ot.dynamic_revenue_decomposition(base_params,
                                            base_tpi,
                                            base_ss,
                                            reform_params,
                                            reform_tpi,
                                            reform_ss,
                                            num_years=10,
                                            include_SS=False,
                                            include_overall=True,
                                            start_year=2021,
                                            table_format=None,
                                            path=None)

    # Data for Macro Aggregates Graph
    ans3 = ot.macro_table(base_tpi,
                          base_params,
                          reform_tpi=reform_tpi,
                          reform_params=reform_params,
                          var_list=['Y', 'K', 'L', 'C'],
                          output_type='pct_diff',
                          num_years=60,
                          start_year=2021)

    # Data for Debt to GDP Graph
    ans4 = ot.macro_table(base_tpi,
                          base_params,
                          reform_tpi=reform_tpi,
                          reform_params=reform_params,
                          var_list=['D', 'Y'],
                          output_type='levels',
                          num_years=60,
                          start_year=2021)

    # Data Dump
    ans5 = ot.tp_output_dump_table(base_params,
                                   base_tpi,
                                   reform_params,
                                   reform_tpi,
                                   table_format=None,
                                   path=None)

    # create plots of output
    op.plot_all(base_dir, reform_dir, os.path.join(CUR_DIR, 'run_biden_plots'))

    print("total time was ", (time.time() - run_start_time))
    print('Percentage changes in aggregates:', ans)

    # save output tables to csv files
    ans0.to_csv('ogusa_biden_output_2021-30.csv')
    ans1.to_csv('ogusa_biden_output_2031-40.csv')
    ans2.to_csv('ogusa_biden_dynamic_revenue.csv')
    ans3.to_csv('ogusa_biden_macro_table.csv')
    ans4.to_csv('ogusa_biden_debt2gdp_2021-30.csv')
    ans5.to_csv('ogusa_biden_output_dump.csv')
    client.close()
Exemplo n.º 28
0
def run_micro_macro(iit_reform, og_spec, guid, client):

    guid = ''
    start_time = time.time()

    REFORM_DIR = os.path.join(CUR_PATH, "OUTPUT_REFORM_" + guid)
    BASELINE_DIR = os.path.join(CUR_PATH, "OUTPUT_BASELINE" + guid)
    tax_func_path_baseline = os.path.join(
        CUR_PATH, 'TxFuncEst_baseline.pkl')
    tax_func_path_reform = os.path.join(
        CUR_PATH, 'TxFuncEst_policy.pkl')

    # Add start year from reform to user parameters
    og_spec['start_year'] = 2018

    with open("log_{}.log".format(guid), 'w') as f:
        f.write("guid: {}\n".format(guid))
        f.write("iit_reform: {}\n".format(iit_reform))
        f.write("og_spec: {}\n".format(og_spec))

    '''
    ------------------------------------------------------------------------
        Run baseline
    ------------------------------------------------------------------------
    '''
    output_base = BASELINE_DIR
    kwargs = {'output_base': output_base, 'baseline_dir': BASELINE_DIR,
              'test': True, 'time_path': True, 'baseline': True,
              'og_spec': og_spec, 'run_micro': False,
              'tax_func_path': tax_func_path_baseline, 'guid': guid,
              'client': client, 'num_workers': NUM_WORKERS}
    runner(**kwargs)

    '''
    ------------------------------------------------------------------------
        Run reform
    ------------------------------------------------------------------------
    '''

    output_base = REFORM_DIR
    kwargs = {'output_base': output_base, 'baseline_dir': BASELINE_DIR,
              'test': True, 'time_path': True, 'baseline': False,
              'iit_reform': iit_reform, 'og_spec': og_spec,
              'guid': guid, 'run_micro': False,
              'tax_func_path': tax_func_path_reform,
              'client': client, 'num_workers': NUM_WORKERS}
    runner(**kwargs)
    time.sleep(0.5)
    base_tpi = safe_read_pickle(
        os.path.join(BASELINE_DIR, 'TPI', 'TPI_vars.pkl'))
    base_params = safe_read_pickle(
        os.path.join(BASELINE_DIR, 'model_params.pkl'))
    reform_tpi = safe_read_pickle(
        os.path.join(REFORM_DIR, 'TPI', 'TPI_vars.pkl'))
    reform_params = safe_read_pickle(
        os.path.join(REFORM_DIR, 'model_params.pkl'))
    ans = ot.macro_table(
        base_tpi, base_params, reform_tpi=reform_tpi,
        reform_params=reform_params,
        var_list=['Y', 'C', 'K', 'L', 'r', 'w'], output_type='pct_diff',
        num_years=10, start_year=og_spec['start_year'])
    print("total time was ", (time.time() - start_time))

    return ans
Exemplo n.º 29
0
def run_micro_macro(user_params,
                    reform=None,
                    baseline_dir=BASELINE_DIR,
                    reform_dir=REFORM_DIR,
                    guid='',
                    data=PUF_PATH,
                    ok_to_run_baseline=True):

    start_time = time.time()

    T_shifts = np.zeros(50)
    T_shifts[2:10] = 0.01
    T_shifts[10:40] = -0.01
    G_shifts = np.zeros(6)
    G_shifts[0:3] = -0.01
    G_shifts[3:6] = -0.005
    user_params = {
        'frisch': 0.41,
        'start_year': 2017,
        'tau_b': 0.20,
        'debt_ratio_ss': 1.0,
        'delta_tau_annual': 0.05,
        'T_shifts': T_shifts.tolist(),
        'G_shifts': G_shifts.tolist()
    }
    '''
    ------------------------------------------------------------------------
        Run baseline
    ------------------------------------------------------------------------
    '''
    print('path exists', not os.path.exists(baseline_dir), ok_to_run_baseline)
    # if not os.path.exists(baseline_dir) and ok_to_run_baseline:
    if ok_to_run_baseline:
        output_base = baseline_dir
        kwargs = {
            'output_base': baseline_dir,
            'baseline_dir': baseline_dir,
            'test': False,
            'time_path': True,
            'baseline': True,
            'analytical_mtrs': False,
            'age_specific': True,
            'user_params': user_params,
            'guid': '',
            'run_micro': False,
            'small_open': False,
            'budget_balance': False,
            'baseline_spending': False,
            'data': data,
            'client': client,
            'num_workers': 4
        }
        runner(**kwargs)
    '''
    ------------------------------------------------------------------------
        Run reform
    ------------------------------------------------------------------------
    '''
    output_base = reform_dir
    kwargs = {
        'output_base': output_base,
        'baseline_dir': baseline_dir,
        'test': False,
        'time_path': True,
        'baseline': False,
        'analytical_mtrs': False,
        'age_specific': True,
        'user_params': user_params,
        'guid': guid,
        'reform': reform,
        'run_micro': False,
        'small_open': False,
        'budget_balance': False,
        'baseline_spending': False,
        'data': data,
        'client': client,
        'num_workers': 4
    }
    runner(**kwargs)

    base_tpi = safe_read_pickle(
        os.path.join(baseline_dir, 'TPI', 'TPI_vars.pkl'))
    base_params = safe_read_pickle(
        os.path.join(baseline_dir, 'model_params.pkl'))
    reform_tpi = safe_read_pickle(
        os.path.join(reform_dir, 'TPI', 'TPI_vars.pkl'))
    reform_params = safe_read_pickle(
        os.path.join(reform_dir, 'model_params.pkl'))
    ans = ot.macro_table(base_tpi,
                         base_params,
                         reform_tpi=reform_tpi,
                         reform_params=reform_params,
                         var_list=['Y', 'C', 'K', 'L', 'r', 'w'],
                         output_type='pct_diff',
                         num_years=10,
                         start_year=2017)

    print("total time was ", (time.time() - start_time))
    print('Percentage changes in aggregates:', ans)