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
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]))
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
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
        ]))
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]))
Exemple #6
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
        ]))