def test_variable_inflation_rate_with_reform(): """ Test indexing of policy parameters involved in a reform. """ pol = Policy() syr = Policy.JSON_START_YEAR assert pol._II_em[2013 - syr] == 3900 # implement reform in 2020 which is two years before the last year, 2022 reform = { 'II_em': { 2018: 1000, # to avoid divide-by-zero under TCJA 2020: 20000 } } pol.implement_reform(reform) pol.set_year(2020) assert pol.current_year == 2020 # extract price inflation rates pirates = pol.inflation_rates() irate2018 = pirates[2018 - syr] irate2020 = pirates[2020 - syr] irate2021 = pirates[2021 - syr] # check implied inflation rate between 2018 and 2019 (before the reform) grate = float(pol._II_em[2019 - syr]) / float(pol._II_em[2018 - syr]) assert round(grate - 1.0, 5) == round(irate2018, 5) # check implied inflation rate between 2020 and 2021 (after the reform) grate = float(pol._II_em[2021 - syr]) / float(pol._II_em[2020 - syr]) assert round(grate - 1.0, 5) == round(irate2020, 5) # check implied inflation rate between 2021 and 2022 (after the reform) grate = float(pol._II_em[2022 - syr]) / float(pol._II_em[2021 - syr]) assert round(grate - 1.0, 5) == round(irate2021, 5)
def test_constant_inflation_rate_with_reform(): syr = 2013 pol = Policy(start_year=syr) # implement reform in year before final year fyr = Policy.LAST_BUDGET_YEAR ryr = fyr - 1 reform = { (ryr - 3): { '_II_em': [1000] }, # to avoid divide-by-zero under TCJA ryr: { '_II_em': [20000] } } pol.implement_reform(reform) # extract price inflation rates pirates = pol.inflation_rates() irate_b = pirates[ryr - 2 - syr] irate_a = pirates[ryr - syr] # check implied inflation rate just before reform grate = float(pol._II_em[ryr - 1 - syr]) / float(pol._II_em[ryr - 2 - syr]) assert round(grate - 1.0, 4) == round(irate_b, 4) # check implied inflation rate just after reform grate = float(pol._II_em[ryr + 1 - syr]) / float(pol._II_em[ryr - syr]) assert round(grate - 1.0, 6) == round(irate_a, 6)
def test_constant_inflation_rate_with_reform(): """ Test indexing of policy parameters involved in a reform. """ pol = Policy() # implement reform in year before final year fyr = Policy.LAST_BUDGET_YEAR ryr = fyr - 1 reform = { 'II_em': { (ryr - 3): 1000, # to avoid divide-by-zero under TCJA ryr: 20000 } } pol.implement_reform(reform) # extract price inflation rates pirates = pol.inflation_rates() syr = Policy.JSON_START_YEAR irate_b = pirates[ryr - 2 - syr] irate_a = pirates[ryr - syr] # check implied inflation rate just before reform grate = float(pol._II_em[ryr - 1 - syr]) / float(pol._II_em[ryr - 2 - syr]) assert round(grate - 1.0, 4) == round(irate_b, 4) # check implied inflation rate just after reform grate = float(pol._II_em[ryr + 1 - syr]) / float(pol._II_em[ryr - syr]) assert round(grate - 1.0, 6) == round(irate_a, 6)
def test_make_calculator_increment_years_first(cps_subsample): # create Policy object with policy reform syr = 2013 pol = Policy(start_year=syr, num_years=5) reform = {2015: {}, 2016: {}} std5 = 2000 reform[2015]['_STD_Aged'] = [[std5, std5, std5, std5, std5]] reform[2015]['_II_em'] = [5000] reform[2016]['_II_em'] = [6000] reform[2016]['_II_em_cpi'] = False pol.implement_reform(reform) # create Calculator object with Policy object as modified by reform rec = Records.cps_constructor(data=cps_subsample) calc = Calculator(policy=pol, records=rec) # compare expected policy parameter values with those embedded in calc irates = pol.inflation_rates() irate2015 = irates[2015 - syr] irate2016 = irates[2016 - syr] std6 = std5 * (1.0 + irate2015) std7 = std6 * (1.0 + irate2016) exp_STD_Aged = np.array([[1500, 1200, 1200, 1500, 1500], [1550, 1200, 1200, 1550, 1550], [std5, std5, std5, std5, std5], [std6, std6, std6, std6, std6], [std7, std7, std7, std7, std7]]) assert np.allclose(calc.policy._STD_Aged, exp_STD_Aged) exp_II_em = np.array([3900, 3950, 5000, 6000, 6000]) assert np.allclose(calc.policy._II_em, exp_II_em)
def test_make_calculator_increment_years_first(cps_subsample): """ Test Calculator inflation indexing of policy parameters. """ # pylint: disable=too-many-locals # create Policy object with policy reform pol = Policy() std5 = 2000 reform = { 'STD_Aged': {2015: [std5, std5, std5, std5, std5]}, 'II_em': {2015: 5000, 2016: 6000}, 'II_em-indexed': {2016: False} } pol.implement_reform(reform) # create Calculator object with Policy object as modified by reform rec = Records.cps_constructor(data=cps_subsample) calc = Calculator(policy=pol, records=rec) # compare expected policy parameter values with those embedded in calc irates = pol.inflation_rates() syr = Policy.JSON_START_YEAR irate2015 = irates[2015 - syr] irate2016 = irates[2016 - syr] std6 = std5 * (1.0 + irate2015) std7 = std6 * (1.0 + irate2016) exp_STD_Aged = np.array([[1500, 1200, 1200, 1500, 1200], [1550, 1200, 1200, 1550, 1200], [std5, std5, std5, std5, std5], [std6, std6, std6, std6, std6], [std7, std7, std7, std7, std7]]) act_STD_Aged = calc.policy_param('_STD_Aged') assert np.allclose(act_STD_Aged[:5], exp_STD_Aged) exp_II_em = np.array([3900, 3950, 5000, 6000, 6000]) act_II_em = calc.policy_param('_II_em') assert np.allclose(act_II_em[:5], exp_II_em)
def test_variable_inflation_rate_with_reform(): syr = 2013 pol = Policy(start_year=syr) assert pol._II_em[2013 - syr] == 3900 # implement reform in 2020 which is two years before the last year, 2022 reform = { 2018: { '_II_em': [1000] }, # to avoid divide-by-zero under TCJA 2020: { '_II_em': [20000] } } pol.implement_reform(reform) pol.set_year(2020) assert pol.current_year == 2020 # extract price inflation rates pirates = pol.inflation_rates() irate2018 = pirates[2018 - syr] irate2020 = pirates[2020 - syr] irate2021 = pirates[2021 - syr] # check implied inflation rate between 2018 and 2019 (before the reform) grate = float(pol._II_em[2019 - syr]) / float(pol._II_em[2018 - syr]) assert round(grate - 1.0, 5) == round(irate2018, 5) # check implied inflation rate between 2020 and 2021 (after the reform) grate = float(pol._II_em[2021 - syr]) / float(pol._II_em[2020 - syr]) assert round(grate - 1.0, 5) == round(irate2020, 5) # check implied inflation rate between 2021 and 2022 (after the reform) grate = float(pol._II_em[2022 - syr]) / float(pol._II_em[2021 - syr]) assert round(grate - 1.0, 5) == round(irate2021, 5)
def test_make_calculator_increment_years_first(cps_subsample): """ Test Calculator inflation indexing of policy parameters. """ # pylint: disable=too-many-locals # create Policy object with policy reform pol = Policy() reform = {2015: {}, 2016: {}} std5 = 2000 reform[2015]['_STD_Aged'] = [[std5, std5, std5, std5, std5]] reform[2015]['_II_em'] = [5000] reform[2016]['_II_em'] = [6000] reform[2016]['_II_em_cpi'] = False pol.implement_reform(reform) # create Calculator object with Policy object as modified by reform rec = Records.cps_constructor(data=cps_subsample) calc = Calculator(policy=pol, records=rec) # compare expected policy parameter values with those embedded in calc irates = pol.inflation_rates() syr = Policy.JSON_START_YEAR irate2015 = irates[2015 - syr] irate2016 = irates[2016 - syr] std6 = std5 * (1.0 + irate2015) std7 = std6 * (1.0 + irate2016) exp_STD_Aged = np.array([[1500, 1200, 1200, 1500, 1500], [1550, 1200, 1200, 1550, 1550], [std5, std5, std5, std5, std5], [std6, std6, std6, std6, std6], [std7, std7, std7, std7, std7]]) act_STD_Aged = calc.policy_param('_STD_Aged') assert np.allclose(act_STD_Aged[:5], exp_STD_Aged) exp_II_em = np.array([3900, 3950, 5000, 6000, 6000]) act_II_em = calc.policy_param('_II_em') assert np.allclose(act_II_em[:5], exp_II_em)
def test_expand_2d_accept_none(): # pylint doesn't like caps in var name, so pylint: disable=invalid-name _II_brk2 = [[36000, 72250, 36500, 48600, 72500], [38000, 74000, 36900, 49400, 73800], [40000, 74900, 37450, 50200, 74900], [41000, None, None, None, None]] exp1 = 74900 * 1.02 exp2 = 37450 * 1.02 exp3 = 50200 * 1.02 exp4 = 74900 * 1.02 exp = [[36000, 72250, 36500, 48600, 72500], [38000, 74000, 36900, 49400, 73800], [40000, 74900, 37450, 50200, 74900], [41000, exp1, exp2, exp3, exp4]] exp = np.array(exp).astype('i4', casting='unsafe') res = ParametersBase._expand_array(_II_brk2, inflate=True, inflation_rates=[0.02] * 5, num_years=4) assert_equal(res, exp) syr = 2013 pol = Policy(start_year=syr) irates = pol.inflation_rates() reform = {2016: {u'_II_brk2': _II_brk2}} pol.implement_reform(reform) pol.set_year(2019) # The 2019 policy should be the combination of the user-defined # value and CPI-inflated values from 2018 exp_2019 = [41000.] + [(1.0 + irates[2018 - syr]) * i for i in _II_brk2[2][1:]] exp_2019 = np.array(exp_2019) assert_equal(pol.II_brk2, exp_2019)
def test_variable_inflation_rate_with_reform(): """ Test indexing of policy parameters involved in a reform. """ pol = Policy() syr = Policy.JSON_START_YEAR assert pol._II_em[2013 - syr] == 3900 # implement reform in 2020 which is two years before the last year, 2022 reform = { 'II_em': {2018: 1000, # to avoid divide-by-zero under TCJA 2020: 20000} } pol.implement_reform(reform) pol.set_year(2020) assert pol.current_year == 2020 # extract price inflation rates pirates = pol.inflation_rates() irate2018 = pirates[2018 - syr] irate2020 = pirates[2020 - syr] irate2021 = pirates[2021 - syr] # check implied inflation rate between 2018 and 2019 (before the reform) grate = float(pol._II_em[2019 - syr]) / float(pol._II_em[2018 - syr]) assert round(grate - 1.0, 5) == round(irate2018, 5) # check implied inflation rate between 2020 and 2021 (after the reform) grate = float(pol._II_em[2021 - syr]) / float(pol._II_em[2020 - syr]) assert round(grate - 1.0, 5) == round(irate2020, 5) # check implied inflation rate between 2021 and 2022 (after the reform) grate = float(pol._II_em[2022 - syr]) / float(pol._II_em[2021 - syr]) assert round(grate - 1.0, 5) == round(irate2021, 5)
def test_inflation_rates(): pol = Policy() # automatically includes embedded GrowFactors object syr = pol.current_year assert syr == 2017 # extract price inflation rates as specified in growfactors.csv file irates = pol.inflation_rates() assert irates[2017 - syr] == 0.045 assert irates[2018 - syr] == 0.045 assert irates[2019 - syr] == 0.045
def test_expand_2D_accept_None_additional_row(): _II_brk2 = [[36000, 72250, 36500, 48600, 72500, 36250], [38000, 74000, 36900, 49400, 73800, 36900], [40000, 74900, 37450, 50200, 74900, 37450], [41000, None, None, None, None, None], [43000, None, None, None, None, None]] exp1 = 74900 * 1.02 exp2 = 37450 * 1.02 exp3 = 50200 * 1.02 exp4 = 74900 * 1.02 exp5 = 37450 * 1.02 exp6 = exp1 * 1.03 exp7 = exp2 * 1.03 exp8 = exp3 * 1.03 exp9 = exp4 * 1.03 exp10 = exp5 * 1.03 exp = [[36000, 72250, 36500, 48600, 72500, 36250], [38000, 74000, 36900, 49400, 73800, 36900], [40000, 74900, 37450, 50200, 74900, 37450], [41000, exp1, exp2, exp3, exp4, exp5], [43000, exp6, exp7, exp8, exp9, exp10]] inflation_rates = [0.015, 0.02, 0.02, 0.03] res = Policy.expand_array(_II_brk2, inflate=True, inflation_rates=inflation_rates, num_years=5) npt.assert_array_equal(res, exp) user_mods = {2016: {u'_II_brk2': _II_brk2}} syr = 2013 pol = Policy(start_year=syr) irates = pol.inflation_rates() pol.implement_reform(user_mods) pol.set_year(2020) irates = pol.inflation_rates() # The 2020 policy should be the combination of the user-defined # value and CPI-inflated values from 2018 exp_2020 = [43000.] + [(1 + irates[2019 - syr]) * (1 + irates[2018 - syr]) * i for i in _II_brk2[2][1:]] exp_2020 = np.array(exp_2020) npt.assert_allclose(pol.II_brk2, exp_2020)
def test_expand_2d_accept_none_add_row(): # pylint doesn't like caps in var name, so pylint: disable=invalid-name _II_brk2 = [[36000, 72250, 36500, 48600, 72500], [38000, 74000, 36900, 49400, 73800], [40000, 74900, 37450, 50200, 74900], [41000, None, None, None, None], [43000, None, None, None, None]] exx = [0.0] exx.append(74900 * 1.02) # exx[1] exx.append(37450 * 1.02) # exx[2] exx.append(50200 * 1.02) # exx[3] exx.append(74900 * 1.02) # exx[4] exx.append(0.0) exx.append(exx[1] * 1.03) # exx[6] exx.append(exx[2] * 1.03) # exx[7] exx.append(exx[3] * 1.03) # exx[8] exx.append(exx[4] * 1.03) # exx[9] exp = [[36000, 72250, 36500, 48600, 72500], [38000, 74000, 36900, 49400, 73800], [40000, 74900, 37450, 50200, 74900], [41000, exx[1], exx[2], exx[3], exx[4]], [43000, exx[6], exx[7], exx[8], exx[9]]] inflation_rates = [0.015, 0.02, 0.02, 0.03] res = ParametersBase._expand_array(_II_brk2, inflate=True, inflation_rates=inflation_rates, num_years=5) assert_equal(res, exp) user_mods = {2016: {'_II_brk2': _II_brk2}} syr = 2013 pol = Policy(start_year=syr) irates = pol.inflation_rates() pol.implement_reform(user_mods) pol.set_year(2020) irates = pol.inflation_rates() # The 2020 policy should be the combination of the user-defined # value and CPI-inflated values from 2018 exp_2020 = [43000.] + [(1 + irates[2019 - syr]) * (1 + irates[2018 - syr]) * i for i in _II_brk2[2][1:]] exp_2020 = np.array(exp_2020) assert np.allclose(pol.II_brk2, exp_2020)
def test_cpi_offset_affect_on_prior_years(): """ Test that CPI_offset does not have affect on inflation rates in earlier years. """ reform = {'CPI_offset': {2022: -0.005}} p1 = Policy() p2 = Policy() p2.implement_reform(reform) start_year = p1.start_year p1_rates = np.array(p1.inflation_rates()) p2_rates = np.array(p2.inflation_rates()) # Inflation rates prior to 2022 are the same. np.testing.assert_allclose(p1_rates[:2022 - start_year], p2_rates[:2022 - start_year]) # Inflation rate in 2022 was updated. np.testing.assert_allclose(p1_rates[2022 - start_year], p2_rates[2022 - start_year] - (-0.005))
def test_chained_cpi_reform(offset): """ Test that _cpi_offset policy parameter works as expected. """ # specify reform without using cpi_offset parameter pem = 10000 bare_reform = {2022: {'_II_em': [pem]}} with_reform = {2022: {'_II_em': [pem]}, 2020: {'_cpi_offset': [offset]}} syr = Policy.JSON_START_YEAR pol_bare = Policy(start_year=syr) pol_bare.implement_reform(bare_reform) pol_with = Policy(start_year=syr) pol_with.implement_reform(with_reform) # check relative _II_em values in the two reforms for several years pem_bare = pol_bare._II_em pem_with = pol_with._II_em if offset == 0: assert pem_with[2019 - syr] == pem_bare[2019 - syr] assert pem_with[2020 - syr] == pem_bare[2020 - syr] assert pem_with[2021 - syr] == pem_bare[2021 - syr] assert pem_with[2022 - syr] == pem assert pem_bare[2022 - syr] == pem assert pem_with[2023 - syr] == pem_bare[2023 - syr] elif offset < 0: assert pem_with[2019 - syr] == pem_bare[2019 - syr] assert pem_with[2020 - syr] == pem_bare[2020 - syr] assert pem_with[2021 - syr] < pem_bare[2021 - syr] assert pem_with[2022 - syr] == pem assert pem_bare[2022 - syr] == pem assert pem_with[2023 - syr] < pem_bare[2023 - syr] # check exact _II_em values for 2023, which are # equal to 2022 values indexed by 2022 inflation rates unchained_cpi = pol_bare.inflation_rates()[2022 - syr] assert pem_bare[2023 - syr] == round(pem * (1 + unchained_cpi), 2) chained_cpi = unchained_cpi + offset assert pem_with[2023 - syr] == round(pem * (1 + chained_cpi), 2) # check that _STD value for 2023 with chained CPI indexing is # equal to _STD value for 2023 when specifying chained CPI indexing # as a difference in assumed inflation rates if offset != 0: # ... compute _STD value using difference-in-growth-factors approach growfactors = Growfactors() growdiff = Growdiff() growdiff.update_growdiff({2020: {'_ACPIU': [offset]}}) growdiff.apply_to(growfactors) pol = Policy(gfactors=growfactors, start_year=syr) pol.implement_reform(bare_reform) # ... compare the _STD values derived from the two approaches assert_allclose(pol_with._STD[2023 - syr], pol._STD[2023 - syr], atol=0.01, rtol=0.0)
def test_variable_inflation_rate_without_reform(): syr = 2013 pol = Policy(start_year=syr, num_years=10) assert pol._II_em[2013 - syr] == 3900 # no reform # extract price inflation rates pirates = pol.inflation_rates() irate2020 = pirates[2020 - syr] irate2021 = pirates[2021 - syr] # check implied inflation rate between 2020 and 2021 grate = float(pol._II_em[2021 - syr]) / float(pol._II_em[2020 - syr]) assert round(grate - 1.0, 5) == round(irate2020, 5) # check implied inflation rate between 2021 and 2022 grate = float(pol._II_em[2022 - syr]) / float(pol._II_em[2021 - syr]) assert round(grate - 1.0, 5) == round(irate2021, 5)
def test_constant_inflation_rate_with_reform(): syr = 2013 pol = Policy(start_year=syr, num_years=10) # implement reform in 2021 which is the year before the last year = 2022 reform = {2021: {'_II_em': [20000]}} pol.implement_reform(reform) # extract price inflation rates pirates = pol.inflation_rates() irate2019 = pirates[2019 - syr] irate2021 = pirates[2021 - syr] # check implied inflation rate just before reform grate = float(pol._II_em[2020 - syr]) / float(pol._II_em[2019 - syr]) assert round(grate - 1.0, 4) == round(irate2019, 4) # check implied inflation rate just after reform grate = float(pol._II_em[2022 - syr]) / float(pol._II_em[2021 - syr]) assert round(grate - 1.0, 6) == round(irate2021, 6)
def test_create_parameters_from_file(monkeypatch, defaultpolicyfile): # pytest monkeypatch sets the temporary file path as the default path; # after the test completes, monkeypatch restores the default settings. monkeypatch.setattr(Policy, 'DEFAULTS_FILENAME', defaultpolicyfile.name) ppo = Policy() inf_rates = ppo.inflation_rates() assert np.allclose(ppo._almdep, Policy._expand_array(np.array([7150, 7250, 7400], dtype=np.float64), False, False, inflate=True, inflation_rates=inf_rates, num_years=ppo.num_years), atol=0.01, rtol=0.0) assert np.allclose(ppo._almsep, Policy._expand_array(np.array([40400, 41050], dtype=np.float64), False, False, inflate=True, inflation_rates=inf_rates, num_years=ppo.num_years), atol=0.01, rtol=0.0) assert np.allclose(ppo._rt5, Policy._expand_array(np.array([0.33]), False, False, inflate=False, inflation_rates=inf_rates, num_years=ppo.num_years), atol=0.01, rtol=0.0) assert np.allclose(ppo._rt7, Policy._expand_array(np.array([0.396]), False, False, inflate=False, inflation_rates=inf_rates, num_years=ppo.num_years), atol=0.01, rtol=0.0)
def test_create_parameters_from_file(policyfile): with open(policyfile.name) as pfile: policy = json.load(pfile) ppo = Policy(parameter_dict=policy) inf_rates = ppo.inflation_rates() assert_allclose(ppo._almdep, Policy._expand_array(np.array([7150, 7250, 7400], dtype=np.float64), False, inflate=True, inflation_rates=inf_rates, num_years=ppo.num_years), atol=0.01, rtol=0.0) assert_allclose(ppo._almsep, Policy._expand_array(np.array([40400, 41050], dtype=np.float64), False, inflate=True, inflation_rates=inf_rates, num_years=ppo.num_years), atol=0.01, rtol=0.0) assert_allclose(ppo._rt5, Policy._expand_array(np.array([0.33]), False, inflate=False, inflation_rates=inf_rates, num_years=ppo.num_years), atol=0.01, rtol=0.0) assert_allclose(ppo._rt7, Policy._expand_array(np.array([0.396]), False, inflate=False, inflation_rates=inf_rates, num_years=ppo.num_years), atol=0.01, rtol=0.0)
def test_constant_inflation_rate_with_reform(): """ Test indexing of policy parameters involved in a reform. """ pol = Policy() # implement reform in year before final year fyr = Policy.LAST_BUDGET_YEAR ryr = fyr - 1 reform = { 'II_em': {(ryr - 3): 1000, # to avoid divide-by-zero under TCJA ryr: 20000} } pol.implement_reform(reform) # extract price inflation rates pirates = pol.inflation_rates() syr = Policy.JSON_START_YEAR irate_b = pirates[ryr - 2 - syr] irate_a = pirates[ryr - syr] # check implied inflation rate just before reform grate = float(pol._II_em[ryr - 1 - syr]) / float(pol._II_em[ryr - 2 - syr]) assert round(grate - 1.0, 4) == round(irate_b, 4) # check implied inflation rate just after reform grate = float(pol._II_em[ryr + 1 - syr]) / float(pol._II_em[ryr - syr]) assert round(grate - 1.0, 6) == round(irate_a, 6)
if pname not in skip_list: reverting_params.append(pname) print('number_of_reverting_parameters= {}'.format(len(reverting_params))) # write ppp.old containing existing values for reverting policy parameters old = open('ppp.old', 'w') for pname in reverting_params: old.write('*** {} ***\n'.format(pname)) # write parameter values for each year in [pyear,fyear] range for year in range(pyear, fyear + 1): value = pdata[pname]['value'][year - syear] old.write('{}: {}\n'.format(year, value)) old.close() # get TCJA parameter inflation rates for each year irate = clp.inflation_rates() # construct final-year inflation factor from prior year # < NOTE: pvalue[t+1] = pvalue[t] * ( 1 + irate[t] ) > final_ifactor = 1.0 for year in range(pyear, fyear): final_ifactor *= 1 + irate[year - syear] # construct intermediate-year inflation factors from base year # < NOTE: pvalue[t+1] = pvalue[t] * ( 1 + irate[t] ) > ifactor = dict() factor = 1.0 for year in range(byear, fyear): ifactor[year] = factor factor *= 1 + irate[year - syear]
def test_multi_year_reform(): """ Test multi-year reform involving 1D and 2D parameters. """ # specify dimensions of policy Policy object syr = Policy.JSON_START_YEAR nyrs = Policy.DEFAULT_NUM_YEARS pol = Policy() iratelist = pol.inflation_rates() ifactor = {} for i in range(0, nyrs): ifactor[syr + i] = 1.0 + iratelist[i] wratelist = pol.wage_growth_rates() wfactor = {} for i in range(0, nyrs): wfactor[syr + i] = 1.0 + wratelist[i] # confirm that parameters have current-law values assert np.allclose(getattr(pol, '_EITC_c'), Policy._expand_array( np.array([[487, 3250, 5372, 6044], [496, 3305, 5460, 6143], [503, 3359, 5548, 6242], [506, 3373, 5572, 6269], [510, 3400, 5616, 6318], [519, 3461, 5716, 6431]], dtype=np.float64), 'real', inflate=True, inflation_rates=iratelist, num_years=nyrs), atol=0.01, rtol=0.0) assert np.allclose(getattr(pol, '_STD_Dep'), Policy._expand_array( np.array([1000, 1000, 1050, 1050, 1050, 1050], dtype=np.float64), 'real', inflate=True, inflation_rates=iratelist, num_years=nyrs), atol=0.01, rtol=0.0) assert np.allclose(getattr(pol, '_CTC_c'), Policy._expand_array( np.array([1000] * 5 + [2000] * 8 + [1000], dtype=np.float64), 'real', inflate=False, inflation_rates=iratelist, num_years=nyrs), atol=0.01, rtol=0.0) # this parameter uses a different indexing rate assert np.allclose(getattr(pol, '_SS_Earnings_c'), Policy._expand_array( np.array([113700, 117000, 118500, 118500, 127200, 128400], dtype=np.float64), 'real', inflate=True, inflation_rates=wratelist, num_years=nyrs), atol=0.01, rtol=0.0) # specify multi-year reform using a param:year:value-fomatted dictionary reform = { 'SS_Earnings_c': {2016: 300000, 2017: 500000, 2019: 700000}, 'SS_Earnings_c-indexed': {2017: False, 2019: True}, 'CTC_c': {2015: 2000}, 'EITC_c': {2016: [900, 5000, 8000, 9000], 2019: [1200, 7000, 10000, 12000]}, 'II_em': {2016: 7000, 2019: 9000} } # implement multi-year reform pol.implement_reform(reform) assert pol.current_year == syr # move policy Policy object forward in time so current_year is syr+2 # Note: this would be typical usage because the first budget year # is typically greater than Policy start_year. pol.set_year(pol.start_year + 2) assert pol.current_year == syr + 2 # confirm that actual parameters have expected post-reform values check_eitc_c(pol, reform, ifactor) check_ii_em(pol, reform, ifactor) check_ss_earnings_c(pol, reform, wfactor) check_ctc_c(pol, reform)
def test_multi_year_reform(): """ Test multi-year reform involving 1D and 2D parameters. """ # specify dimensions of policy Policy object syr = Policy.JSON_START_YEAR nyrs = Policy.DEFAULT_NUM_YEARS pol = Policy() iratelist = pol.inflation_rates() ifactor = {} for i in range(0, nyrs): ifactor[syr + i] = 1.0 + iratelist[i] wratelist = pol.wage_growth_rates() wfactor = {} for i in range(0, nyrs): wfactor[syr + i] = 1.0 + wratelist[i] # confirm that parameters have current-law values assert np.allclose(getattr(pol, '_EITC_c'), Policy._expand_array(np.array( [[487, 3250, 5372, 6044], [496, 3305, 5460, 6143], [503, 3359, 5548, 6242], [506, 3373, 5572, 6269], [510, 3400, 5616, 6318], [519, 3461, 5716, 6431], [529, 3526, 5828, 6557]], dtype=np.float64), 'real', inflate=True, inflation_rates=iratelist, num_years=nyrs), atol=0.01, rtol=0.0) assert np.allclose(getattr(pol, '_STD_Dep'), Policy._expand_array(np.array( [1000, 1000, 1050, 1050, 1050, 1050, 1100], dtype=np.float64), 'real', inflate=True, inflation_rates=iratelist, num_years=nyrs), atol=0.01, rtol=0.0) assert np.allclose(getattr(pol, '_CTC_c'), Policy._expand_array(np.array([1000] * 5 + [2000] * 8 + [1000], dtype=np.float64), 'real', inflate=False, inflation_rates=iratelist, num_years=nyrs), atol=0.01, rtol=0.0) # this parameter uses a different indexing rate assert np.allclose( getattr(pol, '_SS_Earnings_c'), Policy._expand_array(np.array( [113700, 117000, 118500, 118500, 127200, 128400, 132900], dtype=np.float64), 'real', inflate=True, inflation_rates=wratelist, num_years=nyrs), atol=0.01, rtol=0.0) # specify multi-year reform using a param:year:value-fomatted dictionary reform = { 'SS_Earnings_c': { 2016: 300000, 2017: 500000, 2019: 700000 }, 'SS_Earnings_c-indexed': { 2017: False, 2019: True }, 'CTC_c': { 2015: 2000 }, 'EITC_c': { 2016: [900, 5000, 8000, 9000], 2019: [1200, 7000, 10000, 12000] }, 'II_em': { 2016: 7000, 2019: 9000 } } # implement multi-year reform pol.implement_reform(reform) assert pol.current_year == syr # move policy Policy object forward in time so current_year is syr+2 # Note: this would be typical usage because the first budget year # is typically greater than Policy start_year. pol.set_year(pol.start_year + 2) assert pol.current_year == syr + 2 # confirm that actual parameters have expected post-reform values check_eitc_c(pol, reform, ifactor) check_ii_em(pol, reform, ifactor) check_ss_earnings_c(pol, reform, wfactor) check_ctc_c(pol, reform)
def test_multi_year_reform(): """ Test multi-year reform involving 1D and 2D parameters. """ # specify dimensions of policy Policy object syr = 2013 nyrs = Policy.DEFAULT_NUM_YEARS pol = Policy(start_year=syr) iratelist = pol.inflation_rates() ifactor = {} for i in range(0, nyrs): ifactor[syr + i] = 1.0 + iratelist[i] wratelist = pol.wage_growth_rates() wfactor = {} for i in range(0, nyrs): wfactor[syr + i] = 1.0 + wratelist[i] # confirm that parameters have current-law values assert_allclose(getattr(pol, '_EITC_c'), Policy._expand_array(np.array( [[487, 3250, 5372, 6044], [496, 3305, 5460, 6143], [503, 3359, 5548, 6242], [506, 3373, 5572, 6269], [510, 3400, 5616, 6318]], dtype=np.float64), False, inflate=True, inflation_rates=iratelist, num_years=nyrs), atol=0.01, rtol=0.0) assert_allclose(getattr(pol, '_STD_Dep'), Policy._expand_array(np.array( [1000, 1000, 1050, 1050, 1050], dtype=np.float64), False, inflate=True, inflation_rates=iratelist, num_years=nyrs), atol=0.01, rtol=0.0) assert_allclose(getattr(pol, '_CTC_c'), Policy._expand_array(np.array([1000] * 5 + [1400] * 4 + [1500] * 3 + [1600] + [1000], dtype=np.float64), False, inflate=False, inflation_rates=iratelist, num_years=nyrs), atol=0.01, rtol=0.0) # this parameter uses a different indexing rate assert_allclose(getattr(pol, '_SS_Earnings_c'), Policy._expand_array(np.array( [113700, 117000, 118500, 118500, 127200], dtype=np.float64), False, inflate=True, inflation_rates=wratelist, num_years=nyrs), atol=0.01, rtol=0.0) # specify multi-year reform using a dictionary of year_provisions dicts reform = { 2015: { '_CTC_c': [2000] }, 2016: { '_EITC_c': [[900, 5000, 8000, 9000]], '_II_em': [7000], '_SS_Earnings_c': [300000] }, 2017: { '_SS_Earnings_c': [500000], '_SS_Earnings_c_cpi': False }, 2019: { '_EITC_c': [[1200, 7000, 10000, 12000]], '_II_em': [9000], '_SS_Earnings_c': [700000], '_SS_Earnings_c_cpi': True } } # implement multi-year reform pol.implement_reform(reform) assert pol.current_year == syr # move policy Policy object forward in time so current_year is syr+2 # Note: this would be typical usage because the first budget year # is greater than Policy start_year. pol.set_year(pol.start_year + 2) assert pol.current_year == syr + 2 # confirm that actual parameters have expected post-reform values check_eitc_c(pol, reform, ifactor) check_ii_em(pol, reform, ifactor) check_ss_earnings_c(pol, reform, wfactor) check_ctc_c(pol, reform)