def test_incorrect_calc_all(): """ Test incorrect call of calc_all method. """ # Do a quick "simulation" of executing response.calc_all(...) by setting # one of the calculated responses to anything other than None pre_calc_response = Response() pre_calc_response.investment_response = 9.99 # Try to use pre_calc_response as argument to BusinessModel.calc_all method bizmod = BusinessModel(Policy(), itax.Policy(), investor_data='nodata.csv') with pytest.raises(ValueError): bizmod.calc_all(response=pre_calc_response)
def test_reforms(reform_number, reforms, puf_subsample, actual_vs_expect): """ Test BusinessModel corporate tax return results under reforms with no response. """ bizmod = BusinessModel(reforms[reform_number]['policy_obj'], itax.Policy(), investor_data=puf_subsample) bizmod.calc_all(response=None) # compare actual and expected results dec = 3 results = bizmod.corp_ref.taxreturn.combined_return.round(dec) fname = 'bizmod_corp_ref{}_expect.csv'.format(reform_number) actual_vs_expect(results, fname, precision=dec)
'newIntPaid_corp_hc': 1.0, 'newIntPaid_corp_hcyear': 2018, 'oldIntPaid_corp_hc': 1.0, 'oldIntPaid_corp_hcyear': 2018, 'newIntPaid_noncorp_hc': 1.0, 'newIntPaid_noncorp_hcyear': 2018, 'oldIntPaid_noncorp_hc': 1.0, 'oldIntPaid_noncorp_hcyear': 2018 } } # Create an individual-tax policy reform dictionary with no reform iitax_refdict = dict() # Create a BusinessModel object BM = BusinessModel(btax_refdict, iitax_refdict) # Execute the no-response calculations BM.calc_noresponse() # Look at the changes in total corporate and individual income tax liability output_df = BM.ModelResults.round(3) output_df.to_csv('example_results/nresp_model_results.csv', index=False) # Take a closer look at corporate tax items under baseline and reform policy output_df = BM.corp_base.taxreturn.combined_return.round(3) output_df.to_csv('example_results/nresp_base.csv', index=False) output_df = BM.corp_ref.taxreturn.combined_return.round(3) output_df.to_csv('example_results/nresp_refm.csv', index=False) # Look at differences in real effects on corporations without any responses
def test_bm_corp0(with_response, actual_vs_expect, puf_fullsample, tests_path): """ Test BusinessModel corporate results under a corporate-income-tax reform using calc_norespone() and calc_withresponse() with zero elasticities, checking that the two sets of results are the same. """ # ensure that expected results in the two with_response cases are the same assert filecmp.cmp(os.path.join(tests_path, 'bm_corp0_base_nresp_expect.csv'), os.path.join(tests_path, 'bm_corp0_base_wresp_expect.csv'), shallow=False) assert filecmp.cmp(os.path.join(tests_path, 'bm_corp0_refm_nresp_expect.csv'), os.path.join(tests_path, 'bm_corp0_refm_wresp_expect.csv'), shallow=False) # specify corporate-income-tax reform dictionary with these provisions: # - apply a 28% corporate tax rate # - eliminate bonus depreciation # - establish 50% haircut on the deductibility of interest on new debt citax_refdict = { 2018: { 'tau_c': 0.28, 'depr_3yr_bonus': 0.0, 'depr_5yr_bonus': 0.0, 'depr_7yr_bonus': 0.0, 'depr_10yr_bonus': 0.0, 'depr_15yr_bonus': 0.0, 'depr_20yr_bonus': 0.0, 'depr_25yr_bonus': 0.0, 'depr_275yr_bonus': 0.0, 'depr_39yr_bonus': 0.0, 'pymtc_status': 1, 'newIntPaid_corp_hc': 1.0, 'newIntPaid_corp_hcyear': 2018, 'oldIntPaid_corp_hc': 1.0, 'oldIntPaid_corp_hcyear': 2018, 'newIntPaid_noncorp_hc': 1.0, 'newIntPaid_noncorp_hcyear': 2018, 'oldIntPaid_noncorp_hc': 1.0, 'oldIntPaid_noncorp_hcyear': 2018 } } # specify individual-income-tax reform dictionary with no reform provisions iitax_refdict = {} bizmod = BusinessModel(citax_refdict, iitax_refdict, investor_data=puf_fullsample) # calculate results in different ways depending on value of with_response if with_response: bizmod.update_elasticities({}) # all elasticities are zero bizmod.calc_withresponse() else: bizmod.calc_noresponse() # compare actual and expected results resp = 'wresp' if with_response else 'nresp' dec = 4 results = bizmod.corp_base.taxreturn.combined_return.round(dec) fname = 'bm_corp0_base_{}_expect.csv'.format(resp) actual_vs_expect(results, fname, precision=dec) results = bizmod.corp_ref.taxreturn.combined_return.round(dec) fname = 'bm_corp0_refm_{}_expect.csv'.format(resp) actual_vs_expect(results, fname, precision=dec)
def test_bm_corp0(with_response, actual_vs_expect, puf_subsample, tests_path): """ Test BusinessModel corporate results under a corporate-income-tax reform using calc_all(response=None) and calc_all(response=zero_elasticities), checking that the two sets of results are exactly the same, which is what is expected. """ # ensure that expected results in the two with_response cases are the same assert filecmp.cmp(os.path.join(tests_path, 'bm_corp0_base_nresp_expect.csv'), os.path.join(tests_path, 'bm_corp0_base_wresp_expect.csv'), shallow=False) assert filecmp.cmp(os.path.join(tests_path, 'bm_corp0_refm_nresp_expect.csv'), os.path.join(tests_path, 'bm_corp0_refm_wresp_expect.csv'), shallow=False) # specify corporate-income-tax reform policy with these provisions: # - apply a 28% corporate tax rate # - eliminate bonus depreciation # - establish 50% haircut on the deductibility of interest on new debt btax_reform = { 'tau_c': {2018: 0.28}, 'depr_3yr_bonus': {2018: 0.0}, 'depr_5yr_bonus': {2018: 0.0}, 'depr_7yr_bonus': {2018: 0.0}, 'depr_10yr_bonus': {2018: 0.0}, 'depr_15yr_bonus': {2018: 0.0}, 'depr_20yr_bonus': {2018: 0.0}, 'depr_25yr_bonus': {2018: 0.0}, 'depr_275yr_bonus': {2018: 0.0}, 'depr_39yr_bonus': {2018: 0.0}, 'pymtc_hc': {2018: 1.0}, 'newIntPaid_corp_hc': {2018: 1.0}, 'newIntPaid_corp_hcyear': {2018: 2018}, 'oldIntPaid_corp_hc': {2018: 1.0}, 'oldIntPaid_corp_hcyear': {2018: 2018}, 'newIntPaid_noncorp_hc': {2018: 1.0}, 'newIntPaid_noncorp_hcyear': {2018: 2018}, 'oldIntPaid_noncorp_hc': {2018: 1.0}, 'oldIntPaid_noncorp_hcyear': {2018: 2018} } btax_policy_ref = Policy() btax_policy_ref.implement_reform(btax_reform) # specify individual-tax reform dictionary with no reform provisions itax_reform = {} itax_policy_ref = itax.Policy() itax_policy_ref.implement_reform(itax_reform) # calculate results in different ways depending on value of with_response if with_response: zero_elast_response = Response() zero_elast_response.update_elasticities({}) # all zero elasticities bizmod = BusinessModel(btax_policy_ref, itax_policy_ref, investor_data=puf_subsample) bizmod.calc_all(response=zero_elast_response) else: bizmod = BusinessModel(btax_policy_ref, itax_policy_ref, investor_data=puf_subsample) bizmod.calc_all(response=None) # compare actual and expected results resp = 'wresp' if with_response else 'nresp' dec = 4 results = bizmod.corp_base.taxreturn.combined_return.round(dec) fname = 'bm_corp0_base_{}_expect.csv'.format(resp) actual_vs_expect(results, fname, precision=dec) results = bizmod.corp_ref.taxreturn.combined_return.round(dec) fname = 'bm_corp0_refm_{}_expect.csv'.format(resp) actual_vs_expect(results, fname, precision=dec)
} # Policies for business tax rules pol_pre = Policy() pol_pre.implement_reform(bdict1) pol_post = Policy() pol_post.implement_reform(bdict2) # Policies for individual income tax rules ipol_pre = taxcalc.Policy() #ipol_pre.implement_reform(taxcalc.Policy.read_json_reform('2017_law.json')) ipol_post = taxcalc.Policy() #ipol_post.implement_reform(taxcalc.Policy.read_json_reform('TCJA.json')) # Create and run model bm = BusinessModel(btax_policy_ref=pol_post, itax_policy_ref=ipol_post, btax_policy_base=pol_pre, itax_policy_base=ipol_pre) bm.calc_all(response=None) # Update the MTRs from taxcalc bm.update_mtrlists() # Create Response object resp = Response() resp.update_elasticities({ 'debt_taxshield_c': 0.17, 'reprate_inc': -0.61, 'first_year_response': 2018 }) resp.calc_all(bm.btax_params_base, bm.btax_params_ref)
""" import taxcalc as itax # capabilities of individual Tax-Calculator from biztax import Policy, BusinessModel, Response import pandas as pd btax_reform_dict0 = {'tau_c': {2020: 0.20}} # Create business Policy object btax_policy_reform0 = Policy() btax_policy_reform0.implement_reform(btax_reform_dict0) # Create an individual-tax itax.Policy object with no reform itax_policy_noreform0 = itax.Policy() # Execute BusinessModel calculations with no response BM0 = BusinessModel(btax_policy_reform0, itax_policy_noreform0, investor_data='rpuf.csv') BM0.calc_all(response=None) print(BM0.model_results) print('Change in corporate tax revenue ($B): ' + str(sum(BM0.model_results['CTax_change']))) btax_reform_dict1 = { 'depr_3yr_method': {2020: 'Expensing'}, 'depr_5yr_method': {2020: 'Expensing'}, 'depr_7yr_method': {2020: 'Expensing'}, 'depr_10yr_method': {2020: 'Expensing'}, 'depr_15yr_method': {2020: 'Expensing'},
def reforms(): reform_dict = dict() # reform 0, the baseline reform_dict[0] = Data().btax_defaults # reform 1 btax_dict1 = { 2017: { 'tau_c': 0.3, 'depr_3yr_method': 'GDS', 'depr_3yr_bonus': 0.8, 'depr_5yr_method': 'ADS', 'depr_5yr_bonus': 0.8, 'depr_7yr_method': 'Economic', 'depr_7yr_bonus': 0.8, 'depr_10yr_method': 'GDS', 'depr_10yr_bonus': 0.6, 'depr_15yr_method': 'Expensing', 'depr_15yr_bonus': 0.6, 'depr_20yr_method': 'ADS', 'depr_20yr_bonus': 0.4, 'depr_25yr_method': 'EconomicDS', 'depr_25yr_bonus': 0.2, 'depr_275yr_method': 'GDS', 'depr_275yr_bonus': 0.2, 'depr_39yr_method': 'ADS', 'depr_39yr_bonus': 0.2, 'tau_amt': 0.0, 'pymtc_status': 1 }, 2018: { 'netIntPaid_corp_hc': 0.5, 'sec199_hc': 0.5, 'ftc_hc': 0.5 } } bizmod = BusinessModel(btax_dict1, {}) reform_dict[1] = bizmod.btax_params_ref del btax_dict1 del bizmod # reform 2 btax_dict2 = { 2017: { 'oldIntPaid_corp_hcyear': 2017, 'oldIntPaid_corp_hc': 0.5, 'newIntPaid_corp_hcyear': 2017, 'newIntPaid_corp_hc': 1.0, 'oldIntPaid_noncorp_hcyear': 2017, 'oldIntPaid_noncorp_hc': 0.5, 'newIntPaid_noncorp_hcyear': 2017, 'newIntPaid_noncorp_hc': 1.0 }, 2018: { 'undepBasis_corp_hcyear': 2018, 'undepBasis_corp_hc': 0.5, 'undepBasis_noncorp_hcyear': 2018, 'undepBasis_noncorp_hc': 0.5 } } bizmod = BusinessModel(btax_dict2, {}) reform_dict[2] = bizmod.btax_params_ref del btax_dict2 del bizmod return reform_dict
'oldIntPaid_noncorp_hc': { 2018: 1.0 }, 'oldIntPaid_noncorp_hcyear': { 2018: 2018 } } btax_policy_reform = Policy() btax_policy_reform.implement_reform(btax_reform_dict) # Create an individual-tax itax.Policy object with no reform itax_policy_noreform = itax.Policy() # Execute BusinessModel calculations with no response BM = BusinessModel(btax_policy_reform, itax_policy_noreform, investor_data='puf.csv') BM.calc_all(response=None) # Look at the changes in total corporate and individual income tax liability output_df = BM.model_results.round(3) output_df.to_csv('example_results/nresp_model_results.csv', index=False) # Take a closer look at corporate tax items under baseline and reform policy output_df = BM.corp_base.taxreturn.combined_return.round(3) output_df.to_csv('example_results/nresp_base.csv', index=False) output_df = BM.corp_ref.taxreturn.combined_return.round(3) output_df.to_csv('example_results/nresp_refm.csv', index=False) # Look at differences in real effects on corporations without any responses corp_diff = (BM.corp_ref.real_results - BM.corp_base.real_results).round(3)