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)
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)
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) # Extract debt items of interest debteffect = pd.DataFrame({'year': range(2014, 2030)})
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'}, 'depr_20yr_method': {2020: 'Expensing'},
}, '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) corp_diff['year'] = BM.corp_base.real_results['year'] corp_diff.to_csv('example_results/nresp_corp_diff.csv', index=False)