Ejemplo n.º 1
0
    def test_convert(self):

        values = {"II_brk2_0": [36000., 38000., 40000.],
                    "II_brk2_1": [72250., 74000.],
                    "II_brk2_2": [36500.]
                    }

        ans = package_up_vars(values, first_budget_year=FBY)
        pp = Policy(start_year=2013)
        pp.set_year(FBY)
        # irates are rates for 2015, 2016, and 2017
        irates = pp.indexing_rates_for_update(param_name='II_brk2', calyear=FBY,
                                            num_years_to_expand=3)

        # User choices propagate through to all future years
        # The user has specified part of the parameter up to 2017.
        # So, we choose to fill in the propagated value, which is
        # either inflated or not.

        f2_2016 = int(36500 * (1.0 + irates[0]))
        f3_2016 = int(50200 * (1.0 + irates[0]))
        f4_2016 = int(74900 * (1.0 + irates[0]))
        f5_2016 = int(37450 * (1.0 + irates[0]))

        f1_2017 = int(74000 * (1.0 + irates[1]))
        f2_2017 = int(f2_2016 * (1.0 + irates[1]))
    
        exp =  [[36000, 72250, 36500, 50200, 74900, 37450],
                [38000, 74000, f2_2016, 50400, 75300, 37650],
                [40000, f1_2017, f2_2017, None, None, None]]

        assert ans['_II_brk2'] == exp
        assert len(ans) == 1
Ejemplo n.º 2
0
    def test_convert(self):

        values = {"II_brk2_0": [36000., 38000., 40000.],
                    "II_brk2_1": [72250., 74000.],
                    "II_brk2_2": [36500.]
                    }

        ans = package_up_vars(values, first_budget_year=FBY)
        pp = Policy(start_year=2013)
        pp.set_year(FBY)
        # irates are rates for 2015, 2016, and 2017
        irates = pp.indexing_rates_for_update(param_name='II_brk2', calyear=FBY,
                                            num_years_to_expand=3)

        # User choices propagate through to all future years
        # The user has specified part of the parameter up to 2017.
        # So, we choose to fill in the propagated value, which is
        # either inflated or not.

        f2_2016 = int(36500 * (1.0 + irates[0]))
        f3_2016 = int(50200 * (1.0 + irates[0]))
        f4_2016 = int(74900 * (1.0 + irates[0]))
        f5_2016 = int(37450 * (1.0 + irates[0]))

        f1_2017 = int(74000 * (1.0 + irates[1]))
        f2_2017 = int(f2_2016 * (1.0 + irates[1]))

        exp =  [[36000, 72250, 36500, 50200, 74900],
                [38000, 74000, f2_2016, 50400.0, 75300.0],
                [40000, f1_2017, f2_2017, 50800.0, 75900.0]]

        assert ans['_II_brk2'] == exp
        assert len(ans) == 1
Ejemplo n.º 3
0
def propagate_user_list(x, defaults, cpi, first_budget_year):
    """
    Dispatch to either expand_1D or expand2D depending on the dimension of x

    Parameters:
    -----------
    x : list from user to propagate forward in time. The first value is for
        year 'first_budget_year'. The value at index i is the value for
        budget year first_budget_year + i. 

    defaults: list of default values; our result must be at least this long

    cpi: Bool

    first_budget_year: int 

    Returns:
    --------
    list of length 'num_years'. if 'cpi'==True, the values will be inflated
    based on the last value the user specified

    """
    # x can't be empty
    assert x

    num_years = max(len(defaults), len(x))

    is_rate = any([ i < 1.0 for i in x])

    pp = Policy(start_year=2013)
    pp.set_year(first_budget_year)
    # irates are rates for 2015, 2016, and 2017
    if cpi:
        irates = pp.indexing_rates_for_update(param_name='II_brk2',
                                              calyear=first_budget_year,
                                              num_years_to_expand=num_years)
    else:
        irates = [0.0] * num_years

    last_val = x[-1]
    ans = [None] * num_years
    for i in range(num_years):
        if i < len(x):
            if x[i] == '*':
                ans[i] = defaults[i]
            else:
                ans[i] = x[i]
        else:
            newval = ans[i-1] * (1.0 + irates[i-1])
            ans[i] = newval if is_rate else int(newval)


    return ans
Ejemplo n.º 4
0
    def test_convert_multiple_items(self):
        values = {
            "II_brk2_0": [36000., 38000., 40000., 41000],
            "II_brk2_1": [72250., 74000.],
            "II_brk2_2": [36500.]
        }

        values['II_em'] = [4000]

        ans = package_up_vars(values, first_budget_year=FBY)

        defaults = taxcalc.policy.Policy.default_data(start_year=FBY)

        pp = Policy(start_year=2013)
        pp.set_year(FBY)
        # irates are rates for 2015, 2016, and 2017
        irates = pp.indexing_rates_for_update(param_name='II_brk2',
                                              calyear=FBY,
                                              num_years_to_expand=4)

        # User choices propagate through to all future years
        # The user has specified part of the parameter up to 2017.
        # So, we choose to fill in the propagated value, which is
        # either inflated or not.

        f2_2016 = int(36500 * (1.0 + irates[0]))
        f3_2016 = int(50200 * (1.0 + irates[0]))
        f4_2016 = int(74900 * (1.0 + irates[0]))
        f5_2016 = int(37450 * (1.0 + irates[0]))

        f1_2017 = int(74000 * (1.0 + irates[1]))
        f2_2017 = int(f2_2016 * (1.0 + irates[1]))

        f1_2018 = int(f1_2017 * (1.0 + irates[2]))
        f2_2018 = int(f2_2017 * (1.0 + irates[2]))

        exp = [[36000, 72250, 36500, 50200, 74900, 37450],
               [38000, 74000, f2_2016, 50400, 75300, 37650],
               [40000, 75687, f2_2017, 50800.0, 75900.0, 37950.0],
               [41000, f1_2018, f2_2018, None, None, None]]

        assert ans['_II_brk2'] == exp

        # For scalar parameter values, we still have that all user
        # choices propagate up through whatever is specified as
        # a default. We know that _II_em is specified up to 2016, so
        # package up vars needs to overwrite those default and return
        # 2015 and 2016 values

        exp_em = [4000, int(4000 * (1 + irates[0])), 4165]
        assert ans['_II_em'] == exp_em
        assert len(ans) == 2
Ejemplo n.º 5
0
    def test_convert_multiple_items(self):
        values = {"II_brk2_0": [36000., 38000., 40000., 41000],
                    "II_brk2_1": [72250., 74000.],
                    "II_brk2_2": [36500.]
                    }

        values['II_em'] = [4000]

        ans = package_up_vars(values, first_budget_year=FBY)

        defaults = taxcalc.policy.Policy.default_data(start_year=FBY)

        pp = Policy(start_year=2013)
        pp.set_year(FBY)
        # irates are rates for 2015, 2016, and 2017
        irates = pp.indexing_rates_for_update(param_name='II_brk2', calyear=FBY,
                                            num_years_to_expand=4)

        # User choices propagate through to all future years
        # The user has specified part of the parameter up to 2017.
        # So, we choose to fill in the propagated value, which is
        # either inflated or not.

        f2_2016 = int(36500 * (1.0 + irates[0]))
        f3_2016 = int(50200 * (1.0 + irates[0]))
        f4_2016 = int(74900 * (1.0 + irates[0]))
        f5_2016 = int(37450 * (1.0 + irates[0]))

        f1_2017 = int(74000 * (1.0 + irates[1]))
        f2_2017 = int(f2_2016 * (1.0 + irates[1]))

        f1_2018 = int(f1_2017 * (1.0 + irates[2]))
        f2_2018 = int(f2_2017 * (1.0 + irates[2]))

        exp =  [[36000, 72250, 36500, 50200, 74900, 37450],
                [38000, 74000, f2_2016, 50400, 75300, 37650],
                [40000, f1_2017, f2_2017, None, None, None],
                [41000, f1_2018, f2_2018, None, None, None]]

        assert ans['_II_brk2'] == exp

        # For scalar parameter values, we still have that all user
        # choices propagate up through whatever is specified as 
        # a default. We know that _II_em is specified up to 2016, so
        # package up vars needs to overwrite those default and return
        # 2015 and 2016 values

        exp_em = [4000, int(4000 *(1 + irates[0]))]
        assert ans['_II_em'] == exp_em
        assert len(ans) == 2
Ejemplo n.º 6
0
def propagate_user_list(x, num_years, cpi, first_budget_year):
    """
    Dispatch to either expand_1D or expand2D depending on the dimension of x

    Parameters:
    -----------
    x : list from user to progagate forward in time. The first value is for
        year 'first_budget_year'. The value at index i is the value for
        budget year first_budget_year + i. 

    num_years: int 
               Number of budget years to expand

    cpi: Bool

    first_budget_year: int 

    Returns:
    --------
    list of length 'num_years'. if 'cpi'==True, the values will be inflated
    based on the last value the user specified

    """
    # x can't be empty
    assert x

    pp = Policy(start_year=2013)
    pp.set_year(first_budget_year)
    # irates are rates for 2015, 2016, and 2017
    if cpi:
        irates = pp.indexing_rates_for_update(param_name='II_brk2',
                                              calyear=first_budget_year,
                                              num_years_to_expand=num_years)
    else:
        irates = [0.0] * num_years

    last_val = x[-1]
    ans = [None] * num_years
    for i in range(num_years):
        if i < len(x):
            ans[i] = x[i]
        else:
            ans[i] = int(ans[i-1] * (1.0 + irates[i-1]))

    return ans
Ejemplo n.º 7
0
    def test_convert_non_cpi_inflated(self):
        values = {"EITC_InvestIncome_c": [3200]}

        ans = package_up_vars(values, first_budget_year=FBY)

        defaults = taxcalc.policy.Policy.default_data(start_year=2015)

        pp = Policy(start_year=2013)
        pp.set_year(FBY)
        # irates are rates for 2015, 2016, and 2017
        irates = pp.indexing_rates_for_update(param_name='EITC_InvestIncome_c', calyear=FBY,
                                            num_years_to_expand=2)

        # User choices propagate through to all future years
        # The user has specified the parameter just for 2015, but
        # the defaults JSON file has values up to 2016. We should
        # give back values up to 2016, with user choice propagating

        exp = [3200, 3258, 3332]
        assert ans['_EITC_InvestIncome_c'] == exp
Ejemplo n.º 8
0
    def test_convert_non_cpi_inflated(self):
        values = {"FEI_ec_c": [100000.]}

        ans = package_up_vars(values, first_budget_year=FBY)

        defaults = taxcalc.policy.Policy.default_data(start_year=2015)

        pp = Policy(start_year=2013)
        pp.set_year(FBY)
        # irates are rates for 2015, 2016, and 2017
        irates = pp.indexing_rates_for_update(param_name='FEI_ec_c', calyear=FBY,
                                            num_years_to_expand=2)

        # User choices propagate through to all future years
        # The user has specified the parameter just for 2015, but
        # the defaults JSON file has values up to 2016. We should
        # give back values up to 2016, with user choice propagating

        f2_2016 = 100000

        exp =  [100000, f2_2016]
        assert ans['_FEI_ec_c'] == exp
def propagate_user_list(x, name, defaults, cpi, first_budget_year,
                        multi_param_idx=-1):
    """
    Dispatch to either expand_1D or expand2D depending on the dimension of x

    Parameters:
    -----------
    x : list from user to propagate forward in time. The first value is for
        year 'first_budget_year'. The value at index i is the value for
        budget year first_budget_year + i. 

    defaults: list of default values; our result must be at least this long

    name: the parameter name for looking up the indexing rate

    cpi: Bool

    first_budget_year: int 

    multi_param_idx: int, optional. If this parameter is multi-valued, this
        is the index for which the values for 'x' apply. So, for exampe, if
        multi_param_idx=0, the values for x are typically for the 'single'
        filer status. -1 indidcates that this is not a multi-valued
        parameter

    Returns:
    --------
    list of length 'num_years'. if 'cpi'==True, the values will be inflated
    based on the last value the user specified

    """
    # x must have a real first value
    assert len(x) > 0
    assert x[0] not in ("", None)

    num_years = max(len(defaults), len(x))

    is_rate = any([ i < 1.0 for i in x])

    pp = Policy(start_year=2013)
    pp.set_year(first_budget_year)
    # irates are rates for 2015, 2016, and 2017
    if cpi:
        irates = pp.indexing_rates_for_update(param_name=name,
                                              calyear=first_budget_year,
                                              num_years_to_expand=num_years)
    else:
        irates = [0.0] * num_years

    last_val = x[-1]
    ans = [None] * num_years
    for i in range(num_years):
        if i < len(x):
            if is_wildcard(x[i]):
                if multi_param_idx > -1:
                    ans[i] = defaults[i][multi_param_idx]
                else:
                    ans[i] = defaults[i]

            else:
                ans[i] = x[i]

        if ans[i] is not None:
            continue
        else:
            newval = ans[i-1] * (1.0 + irates[i-1])
            ans[i] = newval if is_rate else int(newval)

    return ans