def test_target():
    # Calculator
    records_x = Records(data=TAXDATA, weights=WEIGHTS, start_year=2009)
    policy_x = Policy()
    growth_x = Growth()
    calc_x = Calculator(policy=policy_x, records=records_x,
                        growth=growth_x)

    # set target
    factor_x = {2015: {'_factor_target': [0.04]}}
    growth_x.update_economic_growth(factor_x)

    AGDPN_pre = calc_x.records.BF.AGDPN[2015]
    ATXPY_pre = calc_x.records.BF.ATXPY[2015]

    target(calc_x, growth_x._factor_target, 2015)

    distance = ((growth_x._factor_target[2015 - 2013] -
                 Growth.default_real_GDP_growth_rate(2015 - 2013)) /
                calc_x.records.BF.APOPN[2015])
    AGDPN_post = AGDPN_pre + distance
    ATXPY_post = ATXPY_pre + distance

    assert calc_x.records.BF.AGDPN[2015] == AGDPN_post
    assert calc_x.records.BF.ATXPY[2015] == ATXPY_post
예제 #2
0
def test_make_calculator_with_growth(records_2009):
    grow = Growth()
    calc = Calculator(policy=Policy(), records=records_2009, growth=grow)
    assert calc.current_year == 2013
    assert isinstance(calc, Calculator)
    # test correct Growth instantiation with dictionary
    grow = Growth(growth_dict=dict())
    assert isinstance(grow, Growth)
    # test incorrect Growth instantiation
    with pytest.raises(ValueError):
        grow = Growth(growth_dict=list())
    with pytest.raises(ValueError):
        grow = Growth(num_years=0)
예제 #3
0
def main():
    parser = argparse.ArgumentParser(
        prog="python stats_summary.py",
        description=('Generates a files for either statistics summary'
                     'on a 10-year span or correlation matrix of current'
                     'tax year. Adding either sum-stats or correlation'
                     'as an argument after python Stats_Summary.py --output'))
    parser.add_argument('--output', default='sum-stats')

    args = parser.parse_args()

    # create a calculator
    tax_dta1 = pd.read_csv(PUF_PATH)
    records1 = Records(tax_dta1)
    policy1 = Policy(start_year=2013)
    growth1 = Growth()
    calc1 = Calculator(records=records1, policy=policy1)

    table = creat_table_base(records=records1)

    if args.output == 'sum-stats':
        gen_sum_stats(table, calc=calc1)
    elif args.output == 'correlation':
        gen_correlation(table, calc=calc1)
    else:
        print("no such output available")

    return 0
예제 #4
0
def test_make_calculator_with_growth():
    # create a Records and Params object
    records_x = Records(data=TAXDATA, weights=WEIGHTS, start_year=2009)
    records_y = Records(data=TAXDATA, weights=WEIGHTS, start_year=2009)
    policy_x = Policy()
    policy_y = Policy()

    # create two Calculators
    growth_x = Growth()
    growth_y = Growth()
    calc_x = Calculator(policy=policy_x, records=records_x, growth=growth_x)
    calc_y = Calculator(policy=policy_y, records=records_y, growth=growth_y)

    assert calc_x.current_year == 2013
    assert isinstance(calc_x, Calculator)
    assert isinstance(calc_y, Calculator)
예제 #5
0
def test_factor_target(records_2009):
    calc = Calculator(policy=Policy(), records=records_2009, growth=Growth())
    AGDPN_pre = calc.records.BF.AGDPN[2015]
    ATXPY_pre = calc.records.BF.ATXPY[2015]
    # specify _factor_target
    ft2015 = 0.04
    factor_target = {2015: {'_factor_target': [ft2015]}}
    calc.growth.update_economic_growth(factor_target)
    assert calc.current_year == 2013
    calc.increment_year()
    calc.increment_year()
    assert calc.current_year == 2015
    distance = ((ft2015 - Growth.default_real_gdp_growth_rate(2015 - 2013)) /
                calc.records.BF.APOPN[2015])
    AGDPN_post = AGDPN_pre + distance
    ATXPY_post = ATXPY_pre + distance
    assert calc.records.BF.AGDPN[2015] == AGDPN_post
    assert calc.records.BF.ATXPY[2015] == ATXPY_post
def test_update_growth():

    records_x = Records(data=TAXDATA, weights=WEIGHTS, start_year=2009)
    records_y = Records(data=TAXDATA, weights=WEIGHTS, start_year=2009)
    policy_x = Policy()
    policy_y = Policy()

    # change growth adjustment/target
    growth_x = Growth()
    factor_x = {2015: {'_factor_target': [0.04]}}
    growth_x.update_economic_growth(factor_x)

    growth_y = Growth()
    factor_y = {2015: {'_factor_adjustment': [0.01]}}
    growth_y.update_economic_growth(factor_y)

    # create two Calculators
    calc_x = Calculator(policy=policy_x, records=records_x,
                        growth=growth_x)
    calc_y = Calculator(policy=policy_y, records=records_y,
                        growth=growth_y)

    assert_array_equal(calc_x.growth.factor_target,
                       growth_x.factor_target)
    assert_array_equal(calc_x.growth._factor_target,
                       np.array([0.0226, 0.0241, 0.04, 0.04, 0.04,
                                0.04, 0.04, 0.04, 0.04, 0.04, 0.04,
                                0.04, 0.04, 0.04]))

    assert_array_equal(calc_y.growth.factor_adjustment,
                       growth_y.factor_adjustment)
    assert_array_equal(calc_y.growth._factor_adjustment,
                       np.array([0.0, 0.0, 0.01, 0.01, 0.01, 0.01,
                                 0.01, 0.01, 0.01, 0.01, 0.01, 0.01,
                                 0.01, 0.01]))
예제 #7
0
def test_factor_adjustment(records_2009):
    calc = Calculator(policy=Policy(), records=records_2009, growth=Growth())
    ATXPY_pre = calc.records.BF.ATXPY[2015]
    AGDPN_pre = calc.records.BF.AGDPN[2015]
    # specify _factor_adjustment
    fa2015 = 0.01
    factor_adj = {2015: {'_factor_adjustment': [fa2015]}}
    calc.growth.update_economic_growth(factor_adj)
    assert calc.current_year == 2013
    calc.increment_year()
    calc.increment_year()
    assert calc.current_year == 2015
    assert calc.records.BF.AGDPN[2015] == AGDPN_pre + fa2015
    assert calc.records.BF.ATXPY[2015] == ATXPY_pre + fa2015
예제 #8
0
def test_target():
    # Calculator
    records_x = Records(data=TAXDATA, weights=WEIGHTS, start_year=2009)
    policy_x = Policy()
    growth_x = Growth()
    calc_x = Calculator(policy=policy_x, records=records_x, growth=growth_x)

    # set target
    factor_x = {2015: {'_factor_target': [0.04]}}
    growth_x.update_economic_growth(factor_x)

    AGDPN_pre = calc_x.records.BF.AGDPN[2015]
    ATXPY_pre = calc_x.records.BF.ATXPY[2015]

    target(calc_x, growth_x._factor_target, 2015)

    distance = ((growth_x._factor_target[2015 - 2013] -
                 Growth.default_real_GDP_growth_rate(2015 - 2013)) /
                calc_x.records.BF.APOPN[2015])
    AGDPN_post = AGDPN_pre + distance
    ATXPY_post = ATXPY_pre + distance

    assert calc_x.records.BF.AGDPN[2015] == AGDPN_post
    assert calc_x.records.BF.ATXPY[2015] == ATXPY_post
예제 #9
0
def test_factor_target(records_2009):
    calc = Calculator(policy=Policy(), records=records_2009, growth=Growth())
    AGDPN_pre = calc.records.BF.AGDPN[2015]
    ATXPY_pre = calc.records.BF.ATXPY[2015]
    # specify _factor_target
    ft2015 = 0.04
    factor_target = {2015: {'_factor_target': [ft2015]}}
    calc.growth.update_economic_growth(factor_target)
    assert calc.current_year == 2013
    calc.increment_year()
    calc.increment_year()
    assert calc.current_year == 2015
    distance = ((ft2015 - Growth.default_real_gdp_growth_rate(2015 - 2013)) /
                calc.records.BF.APOPN[2015])
    AGDPN_post = AGDPN_pre + distance
    ATXPY_post = ATXPY_pre + distance
    assert calc.records.BF.AGDPN[2015] == AGDPN_post
    assert calc.records.BF.ATXPY[2015] == ATXPY_post
예제 #10
0
def test_update_growth():

    records_x = Records(data=TAXDATA, weights=WEIGHTS, start_year=2009)
    records_y = Records(data=TAXDATA, weights=WEIGHTS, start_year=2009)
    policy_x = Policy()
    policy_y = Policy()

    # change growth adjustment/target
    growth_x = Growth()
    factor_x = {2015: {'_factor_target': [0.04]}}
    growth_x.update_economic_growth(factor_x)

    growth_y = Growth()
    factor_y = {2015: {'_factor_adjustment': [0.01]}}
    growth_y.update_economic_growth(factor_y)

    # create two Calculators
    calc_x = Calculator(policy=policy_x, records=records_x, growth=growth_x)
    calc_y = Calculator(policy=policy_y, records=records_y, growth=growth_y)

    assert_array_equal(calc_x.growth.factor_target, growth_x.factor_target)
    assert_array_equal(
        calc_x.growth._factor_target,
        np.array([
            0.0226, 0.0241, 0.04, 0.04, 0.04, 0.04, 0.04, 0.04, 0.04, 0.04,
            0.04, 0.04, 0.04, 0.04
        ]))

    assert_array_equal(calc_y.growth.factor_adjustment,
                       growth_y.factor_adjustment)
    assert_array_equal(
        calc_y.growth._factor_adjustment,
        np.array([
            0.0, 0.0, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01,
            0.01, 0.01, 0.01
        ]))
예제 #11
0
def test_update_growth():
    # try incorrect updates
    grow = Growth()
    with pytest.raises(ValueError):
        grow.update_economic_growth({2013: list()})
    with pytest.raises(ValueError):
        grow.update_economic_growth({2013: {'bad_name': [0.02]}})
    with pytest.raises(ValueError):
        grow.update_economic_growth({2013: {'bad_name_cpi': True}})
    bad_params = {2015: {'_factor_adjustment': [0.01],
                         '_factor_target': [0.08]}}
    with pytest.raises(ValueError):
        grow.update_economic_growth(bad_params)
    # try correct updates
    grow_x = Growth()
    factor_x = {2015: {'_factor_target': [0.04]}}
    grow_x.update_economic_growth(factor_x)
    grow_y = Growth()
    factor_y = {2015: {'_factor_adjustment': [0.01]}}
    grow_y.update_economic_growth(factor_y)
    # create two Calculators
    recs_x = Records(data=TAXDATA, weights=WEIGHTS, start_year=2009)
    recs_y = Records(data=TAXDATA, weights=WEIGHTS, start_year=2009)
    calc_x = Calculator(policy=Policy(), records=recs_x, growth=grow_x)
    calc_y = Calculator(policy=Policy(), records=recs_y, growth=grow_y)
    assert_array_equal(calc_x.growth.factor_target,
                       grow_x.factor_target)
    assert_array_equal(calc_x.growth._factor_target,
                       np.array([0.0226, 0.0241, 0.04, 0.04, 0.04,
                                0.04, 0.04, 0.04, 0.04, 0.04, 0.04,
                                0.04, 0.04, 0.04]))
    assert_array_equal(calc_y.growth.factor_adjustment,
                       grow_y.factor_adjustment)
    assert_array_equal(calc_y.growth._factor_adjustment,
                       np.array([0.0, 0.0, 0.01, 0.01, 0.01, 0.01,
                                 0.01, 0.01, 0.01, 0.01, 0.01, 0.01,
                                 0.01, 0.01]))
예제 #12
0
def test_growth_default_data():
    paramdata = Growth.default_data()
    assert paramdata['_factor_adjustment'] == [0.0]
예제 #13
0
def test_hard_coded_gdp_growth():
    growth = Growth()
    assert_array_equal(growth._factor_target,
                       np.array(Growth.REAL_GDP_GROWTH_RATES))
예제 #14
0
def test_growth_default_data():
    paramdata = Growth.default_data()
    assert paramdata['_factor_adjustment'] == [0.0]
예제 #15
0
def test_update_growth(puf_1991, weights_1991):
    # try incorrect updates
    grow = Growth()
    with pytest.raises(ValueError):
        grow.update_economic_growth({2013: list()})
    with pytest.raises(ValueError):
        grow.update_economic_growth({2013: {'bad_name': [0.02]}})
    with pytest.raises(ValueError):
        grow.update_economic_growth({2013: {'bad_name_cpi': True}})
    bad_params = {
        2015: {
            '_factor_adjustment': [0.01],
            '_factor_target': [0.08]
        }
    }
    with pytest.raises(ValueError):
        grow.update_economic_growth(bad_params)
    # try correct updates
    grow_x = Growth()
    factor_x = {2015: {'_factor_target': [0.04]}}
    grow_x.update_economic_growth(factor_x)
    grow_y = Growth()
    factor_y = {2015: {'_factor_adjustment': [0.01]}}
    grow_y.update_economic_growth(factor_y)
    # create two Calculators
    recs_x = Records(data=puf_1991, weights=weights_1991, start_year=2009)
    recs_y = Records(data=puf_1991, weights=weights_1991, start_year=2009)
    calc_x = Calculator(policy=Policy(), records=recs_x, growth=grow_x)
    calc_y = Calculator(policy=Policy(), records=recs_y, growth=grow_y)
    assert_array_equal(calc_x.growth.factor_target, grow_x.factor_target)
    assert_array_equal(
        calc_x.growth._factor_target,
        np.array([
            0.0226, 0.0241, 0.04, 0.04, 0.04, 0.04, 0.04, 0.04, 0.04, 0.04,
            0.04, 0.04, 0.04, 0.04
        ]))
    assert_array_equal(calc_y.growth.factor_adjustment,
                       grow_y.factor_adjustment)
    assert_array_equal(
        calc_y.growth._factor_adjustment,
        np.array([
            0.0, 0.0, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01,
            0.01, 0.01, 0.01
        ]))