def test_store_assets():
    assets = Assets()
    p = Specification()
    dp = DepreciationParams()
    calc1 = Calculator(p, dp, assets)
    calc1.store_assets()
    assert isinstance(calc1, Calculator)
def test_p_param_return_value():
    assets = Assets()
    p = Specification()
    dp = DepreciationParams()
    calc1 = Calculator(p, dp, assets)
    obj = calc1.p_param('tau_int')
    assert np.allclose(obj, np.array([0.31774924]))
def test_p_param_set_value():
    assets = Assets()
    p = Specification()
    calc1 = Calculator(p, assets)
    new_tau_int = np.array([0.396])
    calc1.p_param('tau_int', new_tau_int)
    assert np.allclose(calc1._Calculator__p.tau_int, new_tau_int)
def test_calc_by_asset():
    '''
    Test calc_by_asset method
    '''
    assets = Assets()
    p = Specification()
    calc = Calculator(p, assets)
    asset_df = calc.calc_by_asset()
    assert ('major_asset_group' in asset_df.keys())
def test_calc_by_industry(include_land, include_inventories):
    '''
    Test calc_by_industry method
    '''
    assets = Assets()
    p = Specification()
    calc = Calculator(p, assets)
    ind_df = calc.calc_by_industry(include_land=include_land,
                                   include_inventories=include_inventories)
    assert ('major_industry' in ind_df.keys())
def test_calc_by_industry():
    '''
    Test difference_table method.
    '''
    yr = 2018
    assets = Assets()
    p = Specifications(year=yr)
    calc1 = Calculator(p, assets)
    assert calc1.current_year == yr
    asset_df = calc1.calc_by_industry()
    assert isinstance(asset_df, pd.DataFrame)
Example #7
0
def test_calc_by_asset():
    '''
    Test calc_by_asset method.
    '''
    cyr = 2018
    assets = Assets()
    p = Specification(year=cyr)
    calc1 = Calculator(p, assets)
    assert calc1.current_year == cyr
    asset_df = calc1.calc_by_asset()
    assert isinstance(asset_df, pd.DataFrame)
def test_calc_base():
    '''
    Test calc_base method
    '''
    assets = Assets()
    p = Specification()
    calc = Calculator(p, assets)
    calc.calc_base()
    calc_base_df = calc._Calculator__assets.df
    assert ('z_mix' in calc_base_df.keys())
    assert ('rho_mix' in calc_base_df.keys())
def test_asset_share_table(include_land, include_inventories):
    '''
    Test asset_share_table method.
    '''
    cyr = 2018
    assets = Assets()
    p = Specification(year=cyr)
    calc1 = Calculator(p, assets)
    assert calc1.current_year == cyr
    asset_df = calc1.asset_share_table(include_land=include_land,
                                       include_inventories=include_inventories)
    assert isinstance(asset_df, pd.DataFrame)
def test_bubble_widget():
    '''
    Test asset bubble plot method.
    '''
    assets = Assets()
    p = Specification()
    calc = Calculator(p, assets)
    p2 = Specification(year=2026)
    p2.update_specification({'CIT_rate': 0.25})
    calc2 = Calculator(p2, assets)
    fig = calc.bubble_widget(calc2)
    assert fig
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_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
Example #14
0
def test_summary_table():
    '''
    Test summary_table method.
    '''
    cyr = 2018
    assets = Assets()
    p = Specification(year=cyr)
    calc1 = Calculator(p, assets)
    assert calc1.current_year == cyr
    p.update_specification({'CIT_rate': 0.38})
    calc2 = Calculator(p, assets)
    assert calc2.current_year == cyr
    summary_df = calc1.summary_table(calc2)
    assert isinstance(summary_df, pd.DataFrame)
def test_calc_other():
    '''
    Test calc_other method
    '''
    assets = Assets()
    p = Specification()
    calc = Calculator(p, assets)
    df = calc.calc_by_asset()
    calc_other_df = calc.calc_other(df)
    assert ('ucc_mix' in calc_other_df.keys())
    assert ('metr_mix' in calc_other_df.keys())
    assert ('mettr_mix' in calc_other_df.keys())
    assert ('tax_wedge_mix' in calc_other_df.keys())
    assert ('eatr_mix' in calc_other_df.keys())
Example #16
0
def run_model(meta_param_dict, adjustment):
    '''
    Initializes classes from CCC that compute the model under
    different policies.  Then calls function get output objects.
    '''
    # update MetaParams
    meta_params = MetaParams()
    meta_params.adjust(meta_param_dict)
    # Get data chosen by user
    if meta_params.data_source == "PUF":
        data = retrieve_puf(AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY)
    else:
        data = "cps"
    # Get TC params adjustments
    iit_mods = cs2tc.convert_policy_adjustment(
        adjustment["Individual and Payroll Tax Parameters"])
    filtered_ccc_params = {}
    # filter out CCC params that will not change between baeline and
    # reform runs (These are the Household Savings Behavior and
    # Economic Assumptions)
    constant_param_list = [
        'omega_scg', 'omega_lcg', 'omega_xcg', 'alpha_c_e_ft', 'alpha_c_e_td',
        'alpha_c_e_nt', 'alpha_c_d_ft', 'alpha_c_d_td', 'alpha_c_d_nt',
        'alpha_nc_d_ft', 'alpha_nc_d_td', 'alpha_nc_d_nt', 'alpha_h_d_ft',
        'alpha_h_d_td', 'alpha_h_d_nt', 'Y_td', 'Y_scg', 'Y_lcg', 'gamma',
        'E_c', 'inflation_rate', 'nominal_interest_rate'
    ]
    filtered_ccc_params = OrderedDict()
    for k, v in adjustment['Business Tax Parameters'].items():
        if k in constant_param_list:
            filtered_ccc_params[k] = v
    # Baseline CCC calculator
    params = Specification(year=meta_params.year,
                           call_tc=False,
                           iit_reform={},
                           data=data)
    params.update_specification(filtered_ccc_params)
    assets = Assets()
    dp = DepreciationParams()
    calc1 = Calculator(params, dp, assets)
    # Reform CCC calculator - includes TC adjustments
    params2 = Specification(year=meta_params.year,
                            call_tc=True,
                            iit_reform=iit_mods,
                            data=data)
    params2.update_specification(adjustment["Business Tax Parameters"])
    calc2 = Calculator(params2, dp, assets)
    comp_dict = comp_output(calc1, calc2)

    return comp_dict
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)
def test_Caculator_exception1():
    '''
    Raise exception for not passing parameters object
    '''
    assets = Assets()
    with pytest.raises(Exception):
        assert Calculator(assets=assets)
def test_calc_all():
    '''
    Test calc_all method
    '''
    assets = Assets()
    p = Specification()
    calc = Calculator(p, assets)
    calc.calc_all()
    calc_all_df = calc._Calculator__assets.df
    assert ('z_mix' in calc_all_df.keys())
    assert ('rho_mix' in calc_all_df.keys())
    assert ('ucc_mix' in calc_all_df.keys())
    assert ('metr_mix' in calc_all_df.keys())
    assert ('mettr_mix' in calc_all_df.keys())
    assert ('tax_wedge_mix' in calc_all_df.keys())
    assert ('eatr_mix' in calc_all_df.keys())
def test_Caculator_exception2():
    '''
    Raise exception for not passing assets object
    '''
    p = Specification()
    with pytest.raises(Exception):
        assert Calculator(p=p)
def test_Calculator_exception2():
    '''
    Raise exception for not passing depreciation parameters object
    '''
    p = Specification()
    assets = Assets()
    with pytest.raises(Exception):
        assert Calculator(p=p, assets=assets)
def test_asset_bubble():
    '''
    Test asset bubble plot method.
    '''
    assets = Assets()
    p = Specification()
    dp = DepreciationParams()
    calc = Calculator(p, dp, assets)
    p2 = Specification(year=2026)
    p2.update_specification({'CIT_rate': 0.25})
    calc2 = Calculator(p2, dp, assets)
    fig = calc.asset_bubble(calc2, include_title=True)
    assert fig
    fig = calc.asset_bubble(calc2,
                            output_variable='rho_mix',
                            include_title=True)
    assert fig
def test_Calculator_exception3():
    '''
    Raise exception for not passing assets object
    '''
    p = Specification()
    dp = DepreciationParams()
    with pytest.raises(Exception):
        assert Calculator(p=p, dp=dp)
def test_range_plot(corporate):
    '''
    Test range_plot method.
    '''
    assets = Assets()
    p = Specification()
    calc = Calculator(p, assets)
    p2 = Specification(year=2026)
    p2.update_specification({'CIT_rate': 0.25})
    calc2 = Calculator(p2, assets)
    fig = calc.range_plot(calc2, corporate=corporate, include_title=True)
    assert fig
    fig = calc.range_plot(calc2,
                          output_variable='rho',
                          corporate=corporate,
                          include_title=True)
    assert fig
def test_industry_summary_table(include_land, include_inventories):
    '''
    Test industry_summary_table method.
    '''
    cyr = 2018
    assets = Assets()
    p = Specification(year=cyr)
    calc1 = Calculator(p, assets)
    assert calc1.current_year == cyr
    p.update_specification({'CIT_rate': 0.38})
    calc2 = Calculator(p, assets)
    assert calc2.current_year == cyr
    ind_df = calc1.industry_summary_table(
        calc2,
        include_land=include_land,
        include_inventories=include_inventories)
    assert isinstance(ind_df, pd.DataFrame)
def test_Calculator_exception1():
    '''
    Raise exception for not passing parameters object
    '''
    assets = Assets()
    dp = DepreciationParams()
    with pytest.raises(Exception):
        assert Calculator(dp=dp, assets=assets)
def test_grouped_bar(corporate):
    '''
    Test grouped_bar method.
    '''
    assets = Assets()
    p = Specification()
    dp = DepreciationParams()
    calc = Calculator(p, dp, assets)
    p2 = Specification(year=2026)
    p2.update_specification({'CIT_rate': 0.25})
    calc2 = Calculator(p2, dp, assets)
    fig = calc.grouped_bar(calc2, corporate=corporate)
    assert fig
    fig = calc.grouped_bar(calc2,
                           output_variable='rho',
                           corporate=corporate,
                           group_by_asset=False)
    assert fig
Example #28
0
def run_model(meta_param_dict, adjustment):
    '''
    Initiliazes classes from CCC that compute the model under
    different policies.  Then calls function get output objects.
    '''
    meta_params = MetaParams()
    meta_params.adjust(meta_param_dict)
    if meta_params.data_source == "PUF":
        data = retrieve_puf(AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY)
    else:
        data = "cps"
    params = Specification(year=meta_params.year, call_tc=True, data=data)
    params.adjust(adjustment["ccc"])
    assets = Assets()
    calc1 = Calculator(params, assets)
    params2 = Specification(year=meta_params.year)
    calc2 = Calculator(params2, assets)
    comp_dict = comp_output(calc1, calc2)

    return comp_dict
def test_restore_assets():
    assets = Assets()
    p = Specification()
    calc1 = Calculator(p, assets)
    calc1.store_assets()
    calc1.restore_assets()
    assert isinstance(calc1, Calculator)
def test_calc_by_methods():
    """
    Test the Calculator calc_by_asset and calc_by_industry methods by
    comparing actual and expect dataframes
    """
    # execute Calculator calc_by methods to get actual results
    p = Specification()
    dp = DepreciationParams()
    assets = Assets()
    calc = Calculator(p, dp, assets)
    actual_by_asset = calc.calc_by_asset()
    actual_by_industry = calc.calc_by_industry()
    # load expected results from the calc_by_ methods
    expect_by_asset = pd.read_json(
        os.path.join(TDIR, 'run_ccc_asset_output.json'))
    expect_by_industry = pd.read_json(
        os.path.join(TDIR, 'run_ccc_industry_output.json'))
    # compare the actual and expect DataFrames
    for actual_df, expect_df in zip([actual_by_asset, actual_by_industry],
                                    [expect_by_asset, expect_by_industry]):
        actual_df.sort_index(inplace=True)
        actual_df.reset_index(inplace=True)
        expect_df.sort_index(inplace=True)
        expect_df.reset_index(inplace=True)
        assert tuple(actual_df.columns) == tuple(expect_df.columns)
        for col in expect_df.columns:
            try:
                example = getattr(actual_df, col).iloc[0]
                can_diff = isinstance(example, numbers.Number)
                if can_diff:
                    assert np.allclose(actual_df[col].values,
                                       expect_df[col].values,
                                       atol=1e-5)
                else:
                    pass
            except AttributeError:
                pass
Example #31
0
import pandas as pd
import numpy as np
import numbers
import subprocess
from pandas.testing import assert_frame_equal
from ccc.parameters import Specifications
from ccc.calculator import Calculator
from ccc.data import Assets

CUR_PATH = os.path.abspath(os.path.dirname(__file__))

# Load input values
p = Specifications()
assets = Assets()
p = Specifications()
calc1 = Calculator(p, assets)
# Compute results
test_by_asset = calc1.calc_by_asset()
test_by_industry = calc1.calc_by_industry()
# Load expected results
result_by_asset = pd.read_json(os.path.join(
    CUR_PATH, 'run_ccc_asset_output.json'))
result_by_industry = pd.read_json(os.path.join(
    CUR_PATH, 'run_ccc_industry_output.json'))


@pytest.mark.parametrize('test_df,expected_df',
                         [(test_by_asset, result_by_asset),
                          (test_by_industry, result_by_industry)],
                         ids=['by assset', 'by industry'])
def test_run_ccc(test_df, expected_df):
Example #32
0
from ccc.calculator import Calculator

# Read in a reform to compare against
# 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 = 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()