本文整理汇总了Python中taxcalc.Calculator.increment_year方法的典型用法代码示例。如果您正苦于以下问题:Python Calculator.increment_year方法的具体用法?Python Calculator.increment_year怎么用?Python Calculator.increment_year使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类taxcalc.Calculator
的用法示例。
在下文中一共展示了Calculator.increment_year方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: taxcalc_results
# 需要导入模块: from taxcalc import Calculator [as 别名]
# 或者: from taxcalc.Calculator import increment_year [as 别名]
def taxcalc_results(start_year, reform_dict, itax_clp, ptax_clp):
"""
Use taxcalc package on this computer to compute aggregate income tax and
payroll tax revenue difference (between reform and current-law policy)
for ten years beginning with the specified start_year using the specified
reform_dict dictionary and the two specified current-law-policy results
dictionaries.
Return two aggregate tax revenue difference dictionaries indexed by
calendar year.
"""
pol = Policy()
pol.implement_reform(reform_dict)
calc = Calculator(policy=pol,
records=Records(data=PUF_PATH),
verbose=False)
calc.advance_to_year(start_year)
nyears = NUMBER_OF_YEARS
adts = list()
for iyr in range(-1, nyears - 1):
calc.calc_all()
adts.append(create_diagnostic_table(calc))
if iyr < nyears:
calc.increment_year()
adt = pd.concat(adts, axis=1)
# note that adt is Pandas DataFrame object
itax_ref = adt.xs('Ind Income Tax ($b)').to_dict()
ptax_ref = adt.xs('Payroll Taxes ($b)').to_dict()
itax_diff = {}
ptax_diff = {}
for year in itax_ref:
itax_diff[year] = round(itax_ref[year] - itax_clp[year], 1)
ptax_diff[year] = round(ptax_ref[year] - ptax_clp[year], 1)
return (itax_diff, ptax_diff)
示例2: test_make_Calculator_with_reform_after_start_year
# 需要导入模块: from taxcalc import Calculator [as 别名]
# 或者: from taxcalc.Calculator import increment_year [as 别名]
def test_make_Calculator_with_reform_after_start_year(records_2009):
# create Policy object using custom indexing rates
irates = {2013: 0.01, 2014: 0.01, 2015: 0.02, 2016: 0.01, 2017: 0.03}
parm = Policy(start_year=2013, num_years=len(irates),
inflation_rates=irates)
# specify reform in 2015, which is two years after Policy start_year
reform = {2015: {}, 2016: {}}
reform[2015]['_STD_Aged'] = [[1600, 1300, 1600, 1300, 1600, 1300]]
reform[2015]['_II_em'] = [5000]
reform[2016]['_II_em'] = [6000]
reform[2016]['_II_em_cpi'] = False
parm.implement_reform(reform)
calc = Calculator(policy=parm, records=records_2009)
# compare actual and expected parameter values over all years
assert np.allclose(calc.policy._STD_Aged,
np.array([[1500, 1200, 1200, 1500, 1500, 1200],
[1550, 1200, 1200, 1550, 1550, 1200],
[1600, 1300, 1600, 1300, 1600, 1300],
[1632, 1326, 1632, 1326, 1632, 1326],
[1648, 1339, 1648, 1339, 1648, 1339]]),
atol=0.5, rtol=0.0) # handles rounding to dollars
assert np.allclose(calc.policy._II_em,
np.array([3900, 3950, 5000, 6000, 6000]))
# compare actual and expected values for 2015
calc.increment_year()
calc.increment_year()
assert calc.current_year == 2015
assert np.allclose(calc.policy.II_em, 5000)
assert np.allclose(calc.policy.STD_Aged,
np.array([1600, 1300, 1600, 1300, 1600, 1300]))
示例3: test_make_Calculator_with_reform_after_start_year
# 需要导入模块: from taxcalc import Calculator [as 别名]
# 或者: from taxcalc.Calculator import increment_year [as 别名]
def test_make_Calculator_with_reform_after_start_year():
# create Policy object using custom indexing rates
irates = {2013: 0.01, 2014: 0.01, 2015: 0.02, 2016: 0.01, 2017: 0.03}
parm = Policy(start_year=2013, num_years=len(irates),
inflation_rates=irates)
# specify reform in 2015, which is two years after Policy start_year
reform = {2015: {}, 2016: {}}
reform[2015]['_STD_Aged'] = [[1600, 1300, 1600, 1300, 1600, 1300]]
reform[2015]['_II_em'] = [5000]
reform[2016]['_II_em'] = [6000]
reform[2016]['_II_em_cpi'] = False
parm.implement_reform(reform)
recs = Records(data=TAX_DTA, weights=WEIGHTS, start_year=2009)
calc = Calculator(policy=parm, records=recs)
# compare actual and expected parameter values over all years
exp_STD_Aged = np.array([[1500, 1200, 1200, 1500, 1500, 1200],
[1550, 1200, 1200, 1550, 1550, 1200],
[1600, 1300, 1600, 1300, 1600, 1300],
[1632, 1326, 1632, 1326, 1632, 1326],
[1648, 1339, 1648, 1339, 1648, 1339]])
exp_II_em = np.array([3900, 3950, 5000, 6000, 6000])
assert_array_equal(calc.policy._STD_Aged, exp_STD_Aged)
assert_array_equal(calc.policy._II_em, exp_II_em)
# compare actual and expected values for 2015
calc.increment_year()
calc.increment_year()
assert calc.current_year == 2015
exp_2015_II_em = 5000
assert_array_equal(calc.policy.II_em, exp_2015_II_em)
exp_2015_STD_Aged = np.array([1600, 1300, 1600, 1300, 1600, 1300])
assert_array_equal(calc.policy.STD_Aged, exp_2015_STD_Aged)
示例4: test_make_calculator_with_multiyear_reform
# 需要导入模块: from taxcalc import Calculator [as 别名]
# 或者: from taxcalc.Calculator import increment_year [as 别名]
def test_make_calculator_with_multiyear_reform(cps_subsample):
"""
Test Calculator class ctor with multi-year policy reform.
"""
rec = Records.cps_constructor(data=cps_subsample)
year = rec.current_year
# create a Policy object and apply a policy reform
pol = Policy()
reform = {2015: {}, 2016: {}}
reform[2015]['_II_em'] = [5000, 6000] # reform values for 2015 and 2016
reform[2015]['_II_em_cpi'] = False
reform[2016]['_STD_Aged'] = [[1600, 1300, 1600, 1300, 1600]]
pol.implement_reform(reform)
# create a Calculator object using this policy-reform
calc = Calculator(policy=pol, records=rec)
# check that Policy object embedded in Calculator object is correct
assert pol.num_years == Policy.DEFAULT_NUM_YEARS
assert calc.current_year == year
assert calc.policy_param('II_em') == 3950
exp_II_em = [3900, 3950, 5000] + [6000] * (Policy.DEFAULT_NUM_YEARS - 3)
assert np.allclose(calc.policy_param('_II_em'),
np.array(exp_II_em))
calc.increment_year()
calc.increment_year()
assert calc.current_year == 2016
assert np.allclose(calc.policy_param('STD_Aged'),
np.array([1600, 1300, 1600, 1300, 1600]))
示例5: test_full_dropq_puf
# 需要导入模块: from taxcalc import Calculator [as 别名]
# 或者: from taxcalc.Calculator import increment_year [as 别名]
def test_full_dropq_puf(puf_path):
myvars = {}
myvars['_II_rt4'] = [0.39, 0.40, 0.41]
myvars['_PT_rt4'] = [0.39, 0.40, 0.41]
myvars['_II_rt3'] = [0.31, 0.32, 0.33]
myvars['_PT_rt3'] = [0.31, 0.32, 0.33]
first = 2016
user_mods = {first: myvars}
nyrs = 2
# create a Policy object (clp) containing current-law policy parameters
clp = Policy()
clp.implement_reform(user_mods)
# create a Records object (rec) containing all puf.csv input records
rec = Records(data=puf_path)
# create a Calculator object using clp policy and puf records
calc = Calculator(policy=clp, records=rec)
calc.increment_year()
calc.increment_year()
calc.increment_year()
# create aggregate diagnostic table (adt) as a Pandas DataFrame object
adt = multiyear_diagnostic_table(calc, nyrs)
taxes_fullsample = adt.loc["Combined Liability ($b)"]
assert taxes_fullsample is not None
# Create a Public Use File object
tax_data = pd.read_csv(puf_path)
(mY_dec, mX_dec, df_dec, pdf_dec, cdf_dec, mY_bin, mX_bin, df_bin,
pdf_bin, cdf_bin, fiscal_tots) = dropq.run_models(tax_data,
start_year=first,
user_mods=user_mods,
return_json=False,
num_years=2)
pure_reform_revenue = taxes_fullsample.loc[first]
dropq_reform_revenue = mY_dec['_combined_dec_0'].loc['sums']
dropq_reform_revenue /= 1e9 # Round to billions of dollars
diff = abs(pure_reform_revenue - dropq_reform_revenue)
# Assert that dropq revenue is similar to the "pure" calculation
assert diff / dropq_reform_revenue < 0.02
# Assert that Reform - Baseline = Reported Delta
delta_yr0 = fiscal_tots[0]
baseline_yr0 = fiscal_tots[1]
reform_yr0 = fiscal_tots[2]
diff_yr0 = (reform_yr0.loc['combined_tax'] -
baseline_yr0.loc['combined_tax']).values
delta_yr0 = delta_yr0.loc['combined_tax'].values
npt.assert_array_almost_equal(diff_yr0, delta_yr0, decimal=3)
示例6: test_factor_adjustment
# 需要导入模块: from taxcalc import Calculator [as 别名]
# 或者: from taxcalc.Calculator import increment_year [as 别名]
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
示例7: test_factor_adjustment
# 需要导入模块: from taxcalc import Calculator [as 别名]
# 或者: from taxcalc.Calculator import increment_year [as 别名]
def test_factor_adjustment():
recs = Records(data=TAXDATA, weights=WEIGHTS, start_year=2009)
calc = Calculator(policy=Policy(), records=recs, 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: reform_results
# 需要导入模块: from taxcalc import Calculator [as 别名]
# 或者: from taxcalc.Calculator import increment_year [as 别名]
def reform_results(rid, reform_dict, puf_data, reform_2017_law):
"""
Return actual results of the reform specified by rid and reform_dict.
"""
# pylint: disable=too-many-locals
rec = Records(data=puf_data)
# create baseline Calculator object, calc1
pol = Policy()
if reform_dict['baseline'] == '2017_law.json':
pol.implement_reform(reform_2017_law)
elif reform_dict['baseline'] == 'policy_current_law.json':
pass
else:
msg = 'illegal baseline value {}'
raise ValueError(msg.format(reform_dict['baseline']))
calc1 = Calculator(policy=pol, records=rec, verbose=False)
# create reform Calculator object, calc2
start_year = reform_dict['start_year']
reform = dict()
for name, value in reform_dict['value'].items():
reform[name] = {start_year: value}
pol.implement_reform(reform)
calc2 = Calculator(policy=pol, records=rec, verbose=False)
# increment both Calculator objects to reform's start_year
calc1.advance_to_year(start_year)
calc2.advance_to_year(start_year)
# calculate baseline and reform output for several years
output_type = reform_dict['output_type']
num_years = 4
results = list()
for _ in range(0, num_years):
calc1.calc_all()
baseline = calc1.array(output_type)
calc2.calc_all()
reform = calc2.array(output_type)
diff = reform - baseline
weighted_sum_diff = (diff * calc1.array('s006')).sum() * 1.0e-9
results.append(weighted_sum_diff)
calc1.increment_year()
calc2.increment_year()
# write actual results to actual_str
actual_str = '{}'.format(rid)
for iyr in range(0, num_years):
actual_str += ',{:.1f}'.format(results[iyr])
return actual_str
示例9: test_with_pufcsv
# 需要导入模块: from taxcalc import Calculator [as 别名]
# 或者: from taxcalc.Calculator import increment_year [as 别名]
def test_with_pufcsv(puf_fullsample):
# specify usermods dictionary in code
start_year = 2017
reform_year = start_year
analysis_year = 2026
year_n = analysis_year - start_year
reform = {
'_FICA_ss_trt': [0.2]
}
usermods = dict()
usermods['policy'] = {reform_year: reform}
usermods['consumption'] = {}
usermods['growdiff_baseline'] = {}
usermods['growdiff_response'] = {}
seed = random_seed(usermods)
assert seed == 2568216296
# create a Policy object (pol) containing reform policy parameters
pol = Policy()
pol.implement_reform(usermods['policy'])
# create a Records object (rec) containing all puf.csv input records
rec = Records(data=puf_fullsample)
# create a Calculator object using clp policy and puf records
calc = Calculator(policy=pol, records=rec)
while calc.current_year < analysis_year:
calc.increment_year()
# create aggregate diagnostic table (adt) as a Pandas DataFrame object
adt = calc.diagnostic_table(1)
taxes_fullsample = adt.loc["Combined Liability ($b)"]
assert taxes_fullsample is not None
fulls_reform_revenue = float(taxes_fullsample.loc[analysis_year])
# call run_nth_year_tax_calc_model function
resdict = run_nth_year_taxcalc_model(year_n, start_year,
use_puf_not_cps=True,
use_full_sample=True,
user_mods=usermods,
return_dict=True)
total = resdict['aggr_2']
tbi_reform_revenue = float(total['combined_tax_9'])
# assert that tbi revenue is similar to the fullsample calculation
diff = abs(fulls_reform_revenue - tbi_reform_revenue)
proportional_diff = diff / fulls_reform_revenue
frmt = 'f,d,adiff,pdiff= {:.4f} {:.4f} {:.4f} {}'
print(frmt.format(fulls_reform_revenue, tbi_reform_revenue,
diff, proportional_diff))
assert proportional_diff < 0.0001 # one-hundredth of one percent
示例10: test_factor_target
# 需要导入模块: from taxcalc import Calculator [as 别名]
# 或者: from taxcalc.Calculator import increment_year [as 别名]
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
示例11: test_create_tables
# 需要导入模块: from taxcalc import Calculator [as 别名]
# 或者: from taxcalc.Calculator import increment_year [as 别名]
def test_create_tables(puf_1991, weights_1991):
# create a current-law Policy object and Calculator object calc1
policy1 = Policy()
records1 = Records(data=puf_1991, weights=weights_1991, start_year=2009)
calc1 = Calculator(policy=policy1, records=records1)
calc1.calc_all()
# create a policy-reform Policy object and Calculator object calc2
reform = {2013: {'_II_rt4': [0.56]}}
policy2 = Policy()
policy2.implement_reform(reform)
records2 = Records(data=puf_1991, weights=weights_1991, start_year=2009)
calc2 = Calculator(policy=policy2, records=records2)
calc2.calc_all()
# test creating various distribution tables
dt1 = create_difference_table(calc1.records, calc2.records,
groupby='large_income_bins')
dt2 = create_difference_table(calc1.records, calc2.records,
groupby='webapp_income_bins')
with pytest.raises(ValueError):
dt = create_difference_table(calc1.records, calc2.records,
groupby='bad_bins')
with pytest.raises(ValueError):
dt = create_distribution_table(calc2.records,
groupby='small_income_bins',
result_type='bad_result_type')
with pytest.raises(ValueError):
dt = create_distribution_table(calc2.records,
groupby='bad_bins',
result_type='weighted_sum')
dt3 = create_distribution_table(calc2.records,
groupby='small_income_bins',
result_type='weighted_sum',
baseline_obj=calc1.records, diffs=True)
calc1.increment_year()
with pytest.raises(ValueError):
dt = create_difference_table(calc1.records, calc2.records,
groupby='large_income_bins')
with pytest.raises(ValueError):
dt = create_distribution_table(calc2.records,
groupby='small_income_bins',
result_type='weighted_sum',
baseline_obj=calc1.records, diffs=True)
示例12: taxcalc_clp_results
# 需要导入模块: from taxcalc import Calculator [as 别名]
# 或者: from taxcalc.Calculator import increment_year [as 别名]
def taxcalc_clp_results():
"""
Use taxcalc package on this computer to compute aggregate income tax
and payroll tax revenues for years beginning with MIN_START_YEAR and
ending with MAX_START_YEAR+NUMBER_OF_YEARS-1 for current-law policy.
Return two aggregate revenue dictionaries indexed by calendar year.
"""
calc = Calculator(policy=Policy(),
records=Records(data=PUF_PATH),
verbose=False)
nyears = MAX_START_YEAR + NUMBER_OF_YEARS - MIN_START_YEAR - 1
adts = list()
for iyr in range(-1, nyears - 1):
calc.calc_all()
adts.append(create_diagnostic_table(calc))
if iyr < nyears:
calc.increment_year()
adt = pd.concat(adts, axis=1)
# note that adt is Pandas DataFrame object
return (adt.xs('Ind Income Tax ($b)').to_dict(),
adt.xs('Payroll Taxes ($b)').to_dict())
示例13: test_puf_var_stats
# 需要导入模块: from taxcalc import Calculator [as 别名]
# 或者: from taxcalc.Calculator import increment_year [as 别名]
def test_puf_var_stats(tests_path, puf_fullsample):
"""
Main logic of test.
"""
# create a baseline Policy object containing 2017_law.json parameters
pre_tcja_jrf = os.path.join(tests_path, '..', 'reforms', '2017_law.json')
pre_tcja = Calculator.read_json_param_objects(pre_tcja_jrf, None)
baseline_policy = Policy()
baseline_policy.implement_reform(pre_tcja['policy'])
# create a Calculator object using baseline_policy and full puf.csv sample
rec = Records(data=puf_fullsample)
calc = Calculator(policy=baseline_policy, records=rec, verbose=False)
# create base tables
table_mean = create_base_table(tests_path)
table_corr = copy.deepcopy(table_mean)
del table_corr['description']
# add statistics to tables
year_headers = ['description']
for year in range(Policy.JSON_START_YEAR, Policy.LAST_BUDGET_YEAR + 1):
assert year == calc.current_year
year_headers.append(str(year))
calc.calc_all()
calculate_mean_stats(calc, table_mean, year)
if year == 2016:
calculate_corr_stats(calc, table_corr)
if year < Policy.LAST_BUDGET_YEAR:
calc.increment_year()
# write tables to new CSV files
mean_path = os.path.join(tests_path, MEAN_FILENAME + '-new')
table_mean.sort_index(inplace=True)
table_mean.to_csv(mean_path, header=year_headers, float_format='%8.0f')
corr_path = os.path.join(tests_path, CORR_FILENAME + '-new')
table_corr.sort_index(inplace=True)
table_corr.to_csv(corr_path, float_format='%8.2f',
columns=table_corr.index)
# compare new and old CSV files for nonsmall differences
mean_msg = differences(mean_path, mean_path[:-4], 'MEAN')
corr_msg = differences(corr_path, corr_path[:-4], 'CORR')
if mean_msg or corr_msg:
raise ValueError(mean_msg + corr_msg)
示例14: test_make_Calculator_with_multiyear_reform
# 需要导入模块: from taxcalc import Calculator [as 别名]
# 或者: from taxcalc.Calculator import increment_year [as 别名]
def test_make_Calculator_with_multiyear_reform():
# create a Policy object and apply a policy reform
policy3 = Policy()
reform3 = {2015: {}}
reform3[2015]['_STD_Aged'] = [[1600, 1300, 1600, 1300, 1600, 1300]]
reform3[2015]['_II_em'] = [5000, 6000] # reform values for 2015 and 2016
reform3[2015]['_II_em_cpi'] = False
policy3.implement_reform(reform3)
# create a Calculator object using this policy-reform
puf = Records(data=TAX_DTA, weights=WEIGHTS, start_year=2009)
calc3 = Calculator(policy=policy3, records=puf)
# check that Policy object embedded in Calculator object is correct
assert calc3.current_year == 2013
assert calc3.policy.II_em == 3900
assert calc3.policy.num_years == 12
exp_II_em = [3900, 3950, 5000] + [6000] * 9
assert_array_equal(calc3.policy._II_em, np.array(exp_II_em))
calc3.increment_year()
calc3.increment_year()
assert calc3.current_year == 2015
assert_array_equal(calc3.policy.STD_Aged,
np.array([1600, 1300, 1600, 1300, 1600, 1300]))
示例15: test_make_Calculator_with_multiyear_reform
# 需要导入模块: from taxcalc import Calculator [as 别名]
# 或者: from taxcalc.Calculator import increment_year [as 别名]
def test_make_Calculator_with_multiyear_reform(records_2009):
# create a Policy object and apply a policy reform
policy3 = Policy()
reform3 = {2015: {}}
reform3[2015]['_STD_Aged'] = [[1600, 1300, 1600, 1300, 1600, 1300]]
reform3[2015]['_II_em'] = [5000, 6000] # reform values for 2015 and 2016
reform3[2015]['_II_em_cpi'] = False
policy3.implement_reform(reform3)
# create a Calculator object using this policy-reform
calc3 = Calculator(policy=policy3, records=records_2009)
# check that Policy object embedded in Calculator object is correct
assert calc3.current_year == 2013
assert calc3.policy.II_em == 3900
assert calc3.policy.num_years == Policy.DEFAULT_NUM_YEARS
exp_II_em = [3900, 3950, 5000] + [6000] * (Policy.DEFAULT_NUM_YEARS - 3)
assert np.allclose(calc3.policy._II_em,
np.array(exp_II_em))
calc3.increment_year()
calc3.increment_year()
assert calc3.current_year == 2015
assert np.allclose(calc3.policy.STD_Aged,
np.array([1600, 1300, 1600, 1300, 1600, 1300]))