Example #1
0
def test_simple_eval():
    specs = Specifications()
    specs.profit_rate = 1.0
    assert specs.simple_eval('profit_rate / 2') == 0.5
    assert specs.simple_eval('profit_rate * 2') == 2.0
    assert specs.simple_eval('profit_rate - 2') == -1.0
    assert specs.simple_eval('profit_rate + 2') == 3.0
Example #2
0
def test_simple_eval():
    specs = Specifications()
    specs.profit_rate = 1.0
    assert specs.simple_eval('profit_rate / 2') == 0.5
    assert specs.simple_eval('profit_rate * 2') == 2.0
    assert specs.simple_eval('profit_rate - 2') == -1.0
    assert specs.simple_eval('profit_rate + 2') == 3.0
Example #3
0
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 validate_inputs(meta_param_dict, adjustment, errors_warnings):
    '''
    Validates user inputs for parameters
    '''
    # ccc doesn't look at meta_param_dict for validating inputs.
    params = Specifications()
    params.adjust(adjustment["ccc"], raise_errors=False)
    errors_warnings["ccc"]["errors"].update(params.errors)
    return errors_warnings
Example #5
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
Example #6
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
Example #7
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
Example #8
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
Example #10
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
Example #11
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 get_inputs(meta_params_dict):
    '''
    Function to get user input parameters from COMP
    '''
    meta_params = MetaParams()
    meta_params.adjust(meta_params_dict)
    params = Specifications()
    spec = params.specification(meta_data=True,
                                serializable=True,
                                year=meta_params.year)
    return (meta_params.specification(meta_data=True, serializable=True), {
        "ccc": spec
    })
Example #13
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
Example #14
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.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_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_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_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_params_start_year(year, expected_values):
    '''
    Test that different start years return the expected parameter values
    as specificed in the default_parameters.json file.
    '''
    p = Specifications(year=year)
    assert (np.allclose(p.u['c'], expected_values[0]))
    assert (np.allclose(p.bonus_deprec['3'], expected_values[1]))
    assert (np.allclose(p.phi, expected_values[2]))
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)
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 = Specifications(year=meta_params.year, call_tc=True, data=data)
    params.adjust(adjustment["ccc"])
    assets = Assets()
    calc1 = Calculator(params, assets)
    params2 = Specifications(year=meta_params.year)
    calc2 = Calculator(params2, assets)
    comp_dict = comp_output(calc1, calc2)

    return comp_dict
Example #22
0
from ccc.calculator import Calculator
from bokeh.io import show

# 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=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)
Example #23
0
# 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()
reform_industry_df = calc2.calc_by_industry()

# Generate dataframes with differences
import numpy as np
from pandas.util.testing import assert_frame_equal
from ccc import run_ccc
from ccc.parameters import Specifications

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

# Load input values
input_tuple = tuple(json.load(open(os.path.join(
    CUR_PATH, 'run_ccc_inputs.json'))))
test_run, baseline, start_year, iit_reform, data, user_params = input_tuple
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'))
parameters = Specifications(year=start_year, call_tc=True,
                            iit_reform=iit_reform)
test_by_asset, test_by_industry = run_ccc.run_ccc(
    parameters, baseline, data='cps')

# Lists of variables to compare
asset_var_list = ['delta', 'z_c', 'z_c_d', 'z_c_e', 'z_nc',
                  'z_nc_d', 'z_nc_e', 'rho_c', 'rho_c_d', 'rho_c_e',
                  'rho_nc', 'rho_nc_d', 'rho_nc_e', 'ucc_c',
                  'ucc_c_d', 'ucc_c_e', 'ucc_nc', 'ucc_nc_d',
                  'ucc_nc_e', 'metr_c', 'metr_c_d', 'metr_c_e',
                  'metr_nc', 'metr_nc_d', 'metr_nc_e', 'mettr_c',
                  'mettr_c_d', 'mettr_c_e', 'mettr_nc',
                  'mettr_nc_d', 'mettr_nc_e', 'assets_c',
                  'assets_nc']
industry_var_list = ['delta_c', 'delta_c', 'z_c', 'z_c_d', 'z_c_e',
                     'z_nc', 'z_nc_d', 'z_nc_e', 'rho_c', 'rho_c_d',
Example #25
0
def test_read_json_params_objects(revision_file):
    exp = {"revision": {"CIT_rate": 0.3}}
    act1 = Specifications.read_json_param_objects(JSON_REVISION_FILE)
    assert exp == act1
    act2 = Specifications.read_json_param_objects(JSON_REVISION_FILE)
    assert exp == act2
import pandas as pd
import numpy as np
import pytest
from pandas.testing import assert_series_equal, assert_frame_equal
from ccc import calcfunctions as cf
from ccc.parameters import Specifications

p = Specifications()
df = pd.DataFrame.from_dict({
    'Method': [
        'DB 200%', 'DB 150%', 'SL', 'Economic', 'Expensing', 'DB 200%',
        'DB 150%', 'SL', 'Economic', 'Expensing'
    ],
    'GDS Life': [10, 10, 3, 15, 27.5, 27.5, 10, 3, 15, 7],
    'ADS Life': [10, 10, 3, 15, 27.5, 27.5, 10, 3, 15, 7],
    'GDS Class Life': [10, 10, 3, 15, 27.5, 27.5, 10, 3, 15, 7]
})
expected_df = df.copy()
expected_df['System'] = pd.Series(
    ['GDS', 'GDS', 'GDS', 'GDS', 'GDS', 'GDS', 'GDS', 'GDS', 'GDS', 'GDS'],
    index=expected_df.index)
expected_df['bonus'] = pd.Series(
    [1.0, 1.0, 1.0, 1.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0],
    index=expected_df.index)
expected_df['b'] = pd.Series([2, 1.5, 1, 1, 1, 2, 1.5, 1, 1, 1],
                             index=expected_df.index)
expected_df['Y'] = pd.Series([10, 10, 3, 15, 27.5, 27.5, 10, 3, 15, 7],
                             index=expected_df.index)
test_data = [(df, p, expected_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')
Example #28
0
def test_create_specs_object():
    specs = Specifications()
    assert specs
Example #29
0
def test_read_json_params_objects(revision_file):
    exp = {"revision": {"CIT_rate": 0.3}}
    act1 = Specifications.read_json_param_objects(JSON_REVISION_FILE)
    assert exp == act1
    act2 = Specifications.read_json_param_objects(JSON_REVISION_FILE)
    assert exp == act2