def test_implement_reform(): specs = Specifications() new_specs = {'profit_rate': 0.4, 'm': 0.5} specs.update_specifications(new_specs) assert specs.profit_rate == 0.4 assert specs.m == 0.5 assert len(specs.errors) == 0
def test_implement_reform(): specs = Specifications() new_specs = {'profit_rate': 0.4, 'm': 0.5, 'start_year': 2019} specs.update_specifications(new_specs) assert specs.profit_rate == 0.4 assert specs.m == 0.5 assert specs.start_year == 2019 assert len(specs.parameter_errors) == 0 assert len(specs.parameter_warnings) == 0
def test_implement_bad_reform1(): specs = Specifications() # profit rate has an upper bound at 1.0 new_specs = {'profit_rate': 1.2} specs.update_specifications(new_specs, raise_errors=False) assert len(specs.parameter_errors) > 0 assert specs.parameter_errors == 'ERROR: profit_rate value 1.2 > max value 1.0\n' assert len(specs.parameter_warnings) == 0
def test_implement_bad_reform2(): specs = Specifications() # Pick a category for depreciation that is out of bounds new_specs = {'profit_rate': 0.5, 'DeprecSystem_3yr': 'not_a_deprec_system'} specs.update_specifications(new_specs, raise_errors=False) assert len(specs.parameter_errors) > 0 assert specs.parameter_errors == "ERROR: DeprecSystem_3yr value ['not_a_deprec_system'] not in possible values ['GDS', 'ADS', 'Economic']\n" assert len(specs.parameter_warnings) == 0
def test_implement_bad_reform1(): specs = Specifications() # profit rate has an upper bound at 1.0 new_specs = {'profit_rate': 1.2} specs.update_specifications(new_specs, raise_errors=False) assert len(specs.errors) > 0 print(specs.errors) exp = {'profit_rate': ['profit_rate 1.2 must be less than 1.0.']} assert specs.errors == exp
def test_bubble_widget(): ''' Test asset bubble plot method. ''' assets = Assets() p = Specifications() calc = Calculator(p, assets) p2 = Specifications(year=2026) p2.update_specifications({'CIT_rate': 0.25}) calc2 = Calculator(p2, assets) fig = calc.bubble_widget(calc2) assert fig
def test_implement_bad_reform1(): specs = Specifications() # profit rate has an upper bound at 1.0 new_specs = { 'profit_rate': 1.2 } specs.update_specifications(new_specs, raise_errors=False) assert len(specs.parameter_errors) > 0 assert specs.parameter_errors == 'ERROR: profit_rate value 1.2 > max value 1.0\n' assert len(specs.parameter_warnings) == 0
def test_implement_bad_reform2(): specs = Specifications() # Pick a category for depreciation that is out of bounds new_specs = { 'profit_rate': 0.5, 'DeprecSystem_3yr': 'not_a_deprec_system' } specs.update_specifications(new_specs, raise_errors=False) assert len(specs.parameter_errors) > 0 assert specs.parameter_errors == "ERROR: DeprecSystem_3yr value ['not_a_deprec_system'] not in possible values ['GDS', 'ADS', 'Economic']\n" assert len(specs.parameter_warnings) == 0
def test_range_plot(): ''' Test range_plot method. ''' assets = Assets() p = Specifications() calc = Calculator(p, assets) p2 = Specifications(year=2026) p2.update_specifications({'CIT_rate': 0.25}) calc2 = Calculator(p2, assets) fig = calc.range_plot(calc2) assert fig fig = calc.range_plot(calc2, output_variable='rho') assert fig
def test_implement_bad_reform2(): specs = Specifications() # Pick a category for depreciation that is out of bounds new_specs = {'profit_rate': 0.5, 'DeprecSystem_3yr': 'not_a_deprec_system'} specs.update_specifications(new_specs, raise_errors=False) assert len(specs.errors) > 0 exp = { 'DeprecSystem_3yr': [ 'DeprecSystem_3yr "not_a_deprec_system" must be in list of choices GDS, ADS, Economic.' ] } assert specs.errors == exp
def test_implement_reform(): specs = Specifications() new_specs = { 'profit_rate': 0.4, 'm': 0.5, 'start_year': 2019 } specs.update_specifications(new_specs) assert specs.profit_rate == 0.4 assert specs.m == 0.5 assert specs.start_year == 2019 assert len(specs.parameter_errors) == 0 assert len(specs.parameter_warnings) == 0
def test_asset_bubble(): ''' Test asset bubble plot method. ''' assets = Assets() p = Specifications() calc = Calculator(p, assets) p2 = Specifications(year=2026) p2.update_specifications({'CIT_rate': 0.25}) calc2 = Calculator(p2, assets) fig = calc.asset_bubble(calc2) assert fig fig = calc.asset_bubble(calc2, output_variable='rho_mix') assert fig
def test_grouped_bar(): ''' Test grouped_bar method. ''' assets = Assets() p = Specifications() calc = Calculator(p, assets) p2 = Specifications(year=2026) p2.update_specifications({'CIT_rate': 0.25}) calc2 = Calculator(p2, assets) fig = calc.grouped_bar(calc2) assert fig fig = calc.grouped_bar(calc2, output_variable='rho', group_by_asset=False) assert fig
def test_summary_table(): ''' Test difference_table method. ''' yr = 2018 assets = Assets() p = Specifications(year=yr) calc1 = Calculator(p, assets) assert calc1.current_year == yr reform = {'CIT_rate': 0.38} p.update_specifications(reform) calc2 = Calculator(p, assets) assert calc2.current_year == yr summary_df = calc1.summary_table(calc2) assert isinstance(summary_df, pd.DataFrame)
assets = Assets() # Baseline baseline_parameters = Specifications(year=2019, call_tc=False, iit_reform={}) calc1 = Calculator(baseline_parameters, assets) # Reform reform_parameters = Specifications(year=2019, call_tc=False, iit_reform={}) business_tax_adjustments = { 'CIT_rate': 0.35, 'BonusDeprec_3yr': 0.50, 'BonusDeprec_5yr': 0.50, 'BonusDeprec_7yr': 0.50, 'BonusDeprec_10yr': 0.50, 'BonusDeprec_15yr': 0.50, 'BonusDeprec_20yr': 0.50 } reform_parameters.update_specifications(business_tax_adjustments) calc2 = Calculator(reform_parameters, assets) # Do calculations by asset base_assets_df = calc1.calc_by_asset() reform_assets_df = calc2.calc_by_asset() # Do Calculations by Industry base_industry_df = calc1.calc_by_industry() reform_industry_df = calc2.calc_by_industry() # Generate dataframes with differences diff_assets_df = ccc.utils.diff_two_tables(reform_assets_df, base_assets_df) diff_industry_df = ccc.utils.diff_two_tables(reform_industry_df, base_industry_df) # Save dataframes to disk as csv files
ref = taxcalc.Calculator.read_json_param_objects(reform_url, None) iit_reform = ref['policy'] # Initialize Asset and Calculator Objects assets = Assets() # Baseline baseline_parameters = Specifications(year=2018, call_tc=True, iit_reform={}) calc1 = Calculator(baseline_parameters, assets) # Reform reform_parameters = Specifications(year=2018, call_tc=True, iit_reform=iit_reform) business_tax_adjustments = { 'CIT_rate': 0.35, 'BonusDeprec_3yr': 0.50, 'BonusDeprec_5yr': 0.50, 'BonusDeprec_7yr': 0.50, 'BonusDeprec_10yr': 0.50, 'BonusDeprec_15yr': 0.50, 'BonusDeprec_20yr': 0.50} reform_parameters.update_specifications(business_tax_adjustments) calc2 = Calculator(reform_parameters, assets) # Do calculations by asset base_assets_df = calc1.calc_by_asset() reform_assets_df = calc2.calc_by_asset() # Do Calculations by Industry base_industry_df = calc1.calc_by_industry() reform_industry_df = calc2.calc_by_industry() # Generate dataframes with differences diff_assets_df = ccc.utils.diff_two_tables( reform_assets_df, base_assets_df) diff_industry_df = ccc.utils.diff_two_tables( reform_industry_df, base_industry_df)
from ccc.run_ccc import run_ccc_with_baseline_delta from taxcalc import * from ccc.parameters import Specifications test_run = False # flag for test run (for Travis CI) start_year = 2018 # Note that TCJA is current law baseline in TC 0.16+ # Thus to compare TCJA to 2017 law, we'll use 2017 law as the reform 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'] # Initialize Cost-of-Capital-Calculator parameters baseline_parameters = Specifications(year=2018, call_tc=True, iit_reform={}) reform_parameters = Specifications(year=2018, call_tc=True, iit_reform=iit_reform) reform_params = {'CIT_rate': 0.35, 'BonusDeprec_3yr': 0.50, 'BonusDeprec_5yr': 0.50, 'BonusDeprec_7yr': 0.50, 'BonusDeprec_10yr': 0.50, 'BonusDeprec_15yr': 0.50, 'BonusDeprec_20yr': 0.50} reform_parameters.update_specifications(reform_params) # Run Cost-of-Capital-Calculator run_ccc_with_baseline_delta(baseline_parameters, reform_parameters, data='cps')