Skip to content

Commit

Permalink
Merge pull request #38 from Peter-Metz/qbid
Browse files Browse the repository at this point in the history
Add parameters for qualified business income and update to taxcalc 3.0
  • Loading branch information
Peter-Metz authored Sep 1, 2020
2 parents e2dd4d1 + 130250e commit 15e07bc
Show file tree
Hide file tree
Showing 25 changed files with 301,041 additions and 948 deletions.
46 changes: 30 additions & 16 deletions cs-config/cs_config/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import paramtools
import pandas as pd
import inspect
from .helpers import convert_defaults, convert_adj
from .outputs import credit_plot, rate_plot, liability_plot
from .constants import MetaParameters
from bokeh.models import ColumnDataSource
Expand All @@ -20,12 +19,21 @@
with open(os.path.join(TCDIR, "policy_current_law.json"), "r") as f:
pcl = json.loads(f.read())

RES = convert_defaults(pcl)

def fix_checkbox(params):
"""
Replace param_checkbox with param-indexed.
"""
pol_params = {}
# drop checkbox parameters.
for param, data in params.items():
if param.endswith("checkbox"):
base_param = param.split("_checkbox")[0]
pol_params[f"{base_param}-indexed"] = data
else:
pol_params[param] = data

class TCParams(paramtools.Parameters):
defaults = RES

return pol_params

def get_version():
version = taxcrunch.__version__
Expand All @@ -40,12 +48,15 @@ def get_inputs(meta_params_dict):
metaparams.adjust(meta_params_dict)

params = CruncherParams()
policy_params = TCParams()
policy_params = Policy()

policy_params.set_state(
year=metaparams.year.tolist())

filtered_pol_params = OrderedDict()
policy_params._schema["operators"].update(
{"label_to_extend": None, "uses_extend_func": False, "array_first": False}
)
for k, v in policy_params.dump().items():
if k =="schema" or v.get("section_1", False):
filtered_pol_params[k] = v
Expand Down Expand Up @@ -73,6 +84,10 @@ def get_inputs(meta_params_dict):
"otheritem",
"childcare",
"mortgage",
"businc",
"sstb",
"w2paid",
"qualprop",
"mtr_options",
"schema"
]
Expand All @@ -93,14 +108,10 @@ def validate_inputs(meta_params_dict, adjustment, errors_warnings):
params.adjust(adjustment["Tax Information"], raise_errors=False)
errors_warnings["Tax Information"]["errors"].update(params.errors)

pol_params = {}
# drop checkbox parameters.
for param, data in list(adjustment["Policy"].items()):
if not param.endswith("checkbox"):
pol_params[param] = data
policy_adj = fix_checkbox(adjustment["Policy"])

policy_params = TCParams()
policy_params.adjust(pol_params, raise_errors=False)
policy_params = Policy()
policy_params.adjust(policy_adj, raise_errors=False, ignore_warnings=True)
errors_warnings["Policy"]["errors"].update(policy_params.errors)

return {"errors_warnings": errors_warnings}
Expand All @@ -110,17 +121,17 @@ def run_model(meta_params_dict, adjustment):
meta_params = MetaParameters()
meta_params.adjust(meta_params_dict)

policy_mods = convert_adj(adjustment["Policy"], meta_params.year.tolist())

adjustment["Tax Information"]["year"] = meta_params.year
params = CruncherParams()
params.adjust(adjustment["Tax Information"], raise_errors=False)
newvals = params.specification()

policy_mods = fix_checkbox(adjustment["Policy"])

crunch = Cruncher(inputs=newvals, custom_reform=policy_mods)

# make dataset for bokeh plots
ivar = crunch.ivar
ivar = crunch.batch_ivar
_, mtr_opt, _ = crunch.taxsim_inputs()
df = pd.concat([ivar] * 5000, ignore_index=True)
increments = pd.DataFrame(list(range(0, 500000, 100)))
Expand Down Expand Up @@ -156,6 +167,9 @@ def run_model(meta_params_dict, adjustment):
elif mtr_opt == 'Mortgage':
span = int(ivar[23])
df[23] = increments
elif mtr_opt == 'Business Income':
span = int(ivar[24])
df[24] = increments

b = Batch(df)
df_base = b.create_table()
Expand Down
130 changes: 0 additions & 130 deletions cs-config/cs_config/helpers.py

This file was deleted.

31 changes: 2 additions & 29 deletions cs-config/cs_config/tests/test_functions.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from cs_kit import CoreTestFunctions

from cs_config import functions, helpers
from cs_config import functions


class TestFunctions1(CoreTestFunctions):
Expand All @@ -10,31 +10,4 @@ class TestFunctions1(CoreTestFunctions):
bad_adjustment = {"Tax Information": {"mstat": [{"value": 2}]}, "Policy":{"STD": -1}}
ok_adjustment = {"Tax Information": {"mstat": [{"value": "Joint"}]}, "Policy":{}}
get_inputs = functions.get_inputs
get_version = functions.get_version


def test_convert_adj():
adj = {
"STD": [
{"MARS": "single", "year": "2019", "value": 0},
{"MARS": "mjoint", "year": 2019, "value": 1}
],
"EITC_c": [{"EIC": "0kids", "year": "2019", "value": 1000.0}],
"BEN_ssi_repeal": [
{"year": 2019, "value": True}
]
}

res = helpers.convert_adj(adj, 2019)

assert res == {
"STD": {
2019: [0, 1, 12200.0, 18350.0, 24400.0]
},
"EITC_c": {
2019: [1000.0, 3526.0, 5828.0, 6557.0]
},
"BEN_ssi_repeal": {
2019: True
}
}
get_version = functions.get_version
8 changes: 6 additions & 2 deletions docs/INPUT_INSTRUCTIONS.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ To analyze multiple tax filers, the user must specify a csv file with the filers

1. RECID (ID for tax filer)
2. year
3. mstat (1 - single; 2 - joint (married))
3. mstat (1 - single; 2 - married)
4. page (age of primary taxpayer)
5. sage (age of spouse)
6. depx (number of dependents)
Expand All @@ -27,9 +27,13 @@ To analyze multiple tax filers, the user must specify a csv file with the filers
22. otheritem (other itemized deductions subject to SALT cap, e.g. state and local taxes)
23. childcare (child care expenses)
24. mortgage (itemized deductions not subject to SALT cap, e.g., charitable contributions and home mortgage interest)
25. businc (business income)
26. sstb (1 - business income from professional services business; 0 - business income not from professional pervices business)
27. w2paid (W-2 wages paid by business)
28. qualprop (filer's share of qualified property)

For example, a 50-year old single filer with 3 dependents under 13 who makes $50,000 per year could be represented by the following:

```
1,2019,1,50,0,3,3,3,3,50000,0,0,0,0,0,0,0,0,0,0,0,0,0,0
1,2019,1,50,0,3,3,3,3,50000,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
```
Loading

0 comments on commit 15e07bc

Please sign in to comment.