forked from PSLmodels/Tax-Calculator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
extend_tcja.py
166 lines (158 loc) · 6.9 KB
/
extend_tcja.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
"""
This script generates a JSON reform file, which could be called
extend_tcja.json, that can serve as an alternative baseline to
current-law policy (which ends TCJA temporary provisions after 2025).
USAGE: (taxcalc-dev) Tax-Calculator% python extend_tcja.py > ext.json
THEN CHECK: % diff ext.json taxcalc/reforms/ext.json
IF DIFFS: % mv ext.json taxcalc/reforms/ext.json
WHEN TO USE: use this script to update reforms/ext.json in these situations:
(a) whenever inflation rates in the growfactors.csv files are changed
OR
(b) whenever inflation-indexed parameters are updated (usually as part
of changes that increase the value of Policy.LAST_KNOWN_YEAR).
"""
import sys
import numpy
import taxcalc
TCJA_CATEGORY = None # set to None to generate all TCJA temporary provisions
TCJA_PARAMETERS = {
# category 1 ...
"II_rt1": {"indexed": False, "category": 1},
"II_brk1": {"indexed": True, "category": 1},
"PT_rt1": {"indexed": False, "category": 1},
"PT_brk1": {"indexed": True, "category": 1},
"II_rt2": {"indexed": False, "category": 1},
"II_brk2": {"indexed": True, "category": 1},
"PT_rt2": {"indexed": False, "category": 1},
"PT_brk2": {"indexed": True, "category": 1},
"II_rt3": {"indexed": False, "category": 1},
"II_brk3": {"indexed": True, "category": 1},
"PT_rt3": {"indexed": False, "category": 1},
"PT_brk3": {"indexed": True, "category": 1},
"II_rt4": {"indexed": False, "category": 1},
"II_brk4": {"indexed": True, "category": 1},
"PT_rt4": {"indexed": False, "category": 1},
"PT_brk4": {"indexed": True, "category": 1},
"II_rt5": {"indexed": False, "category": 1},
"II_brk5": {"indexed": True, "category": 1},
"PT_rt5": {"indexed": False, "category": 1},
"PT_brk5": {"indexed": True, "category": 1},
"II_rt6": {"indexed": False, "category": 1},
"II_brk6": {"indexed": True, "category": 1},
"PT_rt6": {"indexed": False, "category": 1},
"PT_brk6": {"indexed": True, "category": 1},
"II_rt7": {"indexed": False, "category": 1},
"II_brk7": {"indexed": True, "category": 1},
"PT_rt7": {"indexed": False, "category": 1},
"PT_brk7": {"indexed": True, "category": 1},
# category 2 ...
"CTC_c": {"indexed": False, "category": 2},
"ACTC_c": {"indexed": False, "category": 2},
"ODC_c": {"indexed": False, "category": 2},
"CTC_ps": {"indexed": False, "category": 2},
"ACTC_Income_thd": {"indexed": False, "category": 2},
# category 3 ...
"AMT_em": {"indexed": True, "category": 3},
"AMT_em_ps": {"indexed": True, "category": 3},
"AMT_em_pe": {"indexed": True, "category": 3},
# category 4 ...
"STD": {"indexed": True, "category": 4},
# category 5 ...
"ID_AllTaxes_c": {"indexed": False, "category": 5},
"ID_Charity_crt_cash": {"indexed": False, "category": 5},
"ID_Casualty_hc": {"indexed": False, "category": 5},
"ID_Miscellaneous_hc": {"indexed": False, "category": 5},
"ID_ps": {"indexed": True, "category": 5},
"ID_prt": {"indexed": False, "category": 5},
"ID_crt": {"indexed": False, "category": 5},
# category 6 ...
"II_em": {"indexed": True, "category": 6},
"II_em_ps": {"indexed": True, "category": 6},
# category 7 ...
"PT_qbid_rt": {"indexed": False, "category": 7},
"PT_qbid_taxinc_thd": {"indexed": True, "category": 7},
"PT_qbid_taxinc_gap": {"indexed": False, "category": 7},
"PT_qbid_w2_wages_rt": {"indexed": False, "category": 7},
"PT_qbid_alt_w2_wages_rt": {"indexed": False, "category": 7},
"PT_qbid_alt_property_rt": {"indexed": False, "category": 7},
# category 8 ...
"ALD_BusinessLosses_c": {"indexed": True, "category": 8},
}
def main():
"""
High-level script logic.
"""
# identify last parameter name in TCJA_PARAMETERS
last_pname = list(TCJA_PARAMETERS.keys())[-1]
# calculate 2025-to-2026 parameters indexing factor
pol = taxcalc.Policy()
pirates = pol.inflation_rates()
ifactor25 = 1.0 + pirates[2025-taxcalc.Policy.JSON_START_YEAR]
ifactor28 = 1.0 + pirates[2028-taxcalc.Policy.JSON_START_YEAR]
# specify extend-TCJA-beyond-2025 reform
# ... get 2025 parameter values
pol.set_year(2025)
pdata = dict(pol.items())
# ... write reform header comments
print( '// REFORM TO EXTEND TEMPORARY TCJA PROVISIONS BEYOND 2025')
print(f'// USING TAX-CALCULATOR {taxcalc.__version__}')
print(f'// WITH 2025-to-2026 INDEXING FACTOR = {ifactor25:.6f}')
print(f'// AND 2028-to-2029 INDEXING FACTOR = {ifactor28:.6f}')
if TCJA_CATEGORY:
print(f'// ONLY TCJA PROVISIONS IN CATEGORY {TCJA_CATEGORY}')
print('{')
# ... set 2026/29 nonreverted values for the parameters set to revert
left_brace = '{'
right_brace = '}'
year = 2026
for pname, pinfo in TCJA_PARAMETERS.items():
if TCJA_CATEGORY and pinfo['category'] != TCJA_CATEGORY:
continue # skip this parameter
if pname == 'ALD_BusinessLosses_c':
ifactor = ifactor28
year = 2029
pol.set_year(2028)
pdata = dict(pol.items())
else:
if year != 2026:
pol.set_year(2025)
pdata = dict(pol.items())
ifactor = ifactor25
year = 2026
trailing_comma = '' if pname == last_pname else ','
if pinfo['indexed']:
pval = pdata[pname][0] * ifactor
if isinstance(pval, numpy.ndarray):
# handle vector parameter
pval = numpy.minimum(9e99, pval.round(2))
sys.stdout.write(f' "{pname}": ')
sys.stdout.write(f'{left_brace}"{year}": ')
sys.stdout.write(f'{pval.tolist()}')
sys.stdout.write(f'{right_brace}{trailing_comma}\n')
else:
# handle scalar parameter
pval = min(9e99, pval)
sys.stdout.write(f' "{pname}": ')
sys.stdout.write(f'{left_brace}"{year}": ')
sys.stdout.write(f'{pval*ifactor:.2f}')
sys.stdout.write(f'{right_brace}{trailing_comma}\n')
else: # if parameter is not indexed
pval = pdata[pname][0]
if isinstance(pval, numpy.ndarray):
# handle vector parameter
pval = numpy.minimum(9e99, pval.round(2))
sys.stdout.write(f' "{pname}": ')
sys.stdout.write(f'{left_brace}"{year}": ')
sys.stdout.write(f'{pval.tolist()}')
sys.stdout.write(f'{right_brace}{trailing_comma}\n')
else:
# handle scalar parameter
sys.stdout.write(f' "{pname}": ')
sys.stdout.write(f'{left_brace}"{year}": ')
sys.stdout.write(f'{pval:.2f}')
sys.stdout.write(f'{right_brace}{trailing_comma}\n')
print('}')
return 0
# end main function code
if __name__ == '__main__':
sys.exit(main())