Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dynamic inputs for small_open boolean and world interest rate #703

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions templates/dynamic/includes/params/inputs/dynamic.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ <h1>Macroeconomic Parameters</h1>
{% endblock %}
</div>

<h2>Open Economy Assumptions</h2>
{% include 'taxbrain/includes/params/inputs/param.html' with param=params.small_open %}
{% include 'taxbrain/includes/params/inputs/param.html' with param=params.world_int_rate %}
<h2>Macroeconomic Parameters</h2>
{% include 'taxbrain/includes/params/inputs/param.html' with param=params.g_y_annual %}
{% include 'taxbrain/includes/params/inputs/param.html' with param=params.frisch %}
Expand Down
5 changes: 5 additions & 0 deletions templates/dynamic/includes/params/inputs/elastic.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ <h1>Macroeconomic Parameters</h1>
{% endblock %}
</div>

<h2>Open Economy Assumptions</h2>
{% include 'taxbrain/includes/params/inputs/param.html' with param=params.small_open %}
{% include 'taxbrain/includes/params/inputs/param.html' with param=params.world_int_rate %}


<h2>Elasticity of GDP wrt 1 - AMTR</h2>
{% include 'taxbrain/includes/params/inputs/param.html' with param=params.elastic_gdp %}

Expand Down
110 changes: 31 additions & 79 deletions webapp/apps/dynamic/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,34 +185,40 @@ class Meta:
exclude = ['creation_date']
widgets = {}
labels = {}
for param in ELASTICITY_DEFAULT_PARAMS.values():
for field in param.col_fields:
attrs = {
'class': 'form-control',
'placeholder': field.default_value,
}

if param.coming_soon:
attrs['disabled'] = True
attrs['checked'] = False
widgets[field.id] = forms.CheckboxInput(attrs=attrs, check_test=bool_like)
else:
widgets[field.id] = forms.TextInput(attrs=attrs)
_update_widgets(widgets, OGUSA_DEFAULT_PARAMS)


def _update_widgets(widgets, defaults):
boolean_fields = [
"world_int_rate"
]

for param in defaults.values():
for field in param.col_fields:
attrs = {
'class': 'form-control',
'placeholder': field.default_value,
}

labels[field.id] = field.label
if param.tc_id in boolean_fields:
checkbox = forms.CheckboxInput(attrs=attrs, check_test=bool_like)
widgets[field.id] = checkbox
else:
widgets[field.id] = forms.TextInput(attrs=attrs)

if param.inflatable:
field = param.cpi_field
attrs = {
'class': 'form-control sr-only',
'placeholder': bool(field.default_value),
}
labels[field.id] = field.label

if param.coming_soon:
attrs['disabled'] = True
if param.inflatable:
field = param.cpi_field
attrs = {
'class': 'form-control sr-only',
'placeholder': bool(field.default_value),
}

widgets[field.id] = forms.NullBooleanSelect(attrs=attrs)
if param.coming_soon:
attrs['disabled'] = True

widgets[field.id] = forms.NullBooleanSelect(attrs=attrs)

class DynamicBehavioralInputsModelForm(ModelForm):

Expand Down Expand Up @@ -380,33 +386,7 @@ class Meta:
exclude = ['creation_date']
widgets = {}
labels = {}
for param in BEHAVIOR_DEFAULT_PARAMS.values():
for field in param.col_fields:
attrs = {
'class': 'form-control',
'placeholder': field.default_value,
}

if param.coming_soon:
attrs['disabled'] = True
attrs['checked'] = False
widgets[field.id] = forms.CheckboxInput(attrs=attrs, check_test=bool_like)
else:
widgets[field.id] = forms.TextInput(attrs=attrs)

labels[field.id] = field.label

if param.inflatable:
field = param.cpi_field
attrs = {
'class': 'form-control sr-only',
'placeholder': bool(field.default_value),
}

if param.coming_soon:
attrs['disabled'] = True

widgets[field.id] = forms.NullBooleanSelect(attrs=attrs)
_update_widgets(widgets, BEHAVIOR_DEFAULT_PARAMS)


class DynamicInputsModelForm(ModelForm):
Expand Down Expand Up @@ -568,40 +548,12 @@ def do_taxcalc_validations(self):
int_to_nth(i + 1),
source, mins[i]))



class Meta:
model = DynamicSaveInputs
exclude = ['creation_date']
widgets = {}
labels = {}
for param in OGUSA_DEFAULT_PARAMS.values():
for field in param.col_fields:
attrs = {
'class': 'form-control',
'placeholder': field.default_value,
}

if param.coming_soon:
attrs['disabled'] = True
attrs['checked'] = False
widgets[field.id] = forms.CheckboxInput(attrs=attrs, check_test=bool_like)
else:
widgets[field.id] = forms.TextInput(attrs=attrs)

labels[field.id] = field.label

if param.inflatable:
field = param.cpi_field
attrs = {
'class': 'form-control sr-only',
'placeholder': bool(field.default_value),
}

if param.coming_soon:
attrs['disabled'] = True

widgets[field.id] = forms.NullBooleanSelect(attrs=attrs)
_update_widgets(widgets, OGUSA_DEFAULT_PARAMS)


def has_field_errors(form):
Expand Down
4 changes: 2 additions & 2 deletions webapp/apps/dynamic/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,8 +257,8 @@ def dynamic_params_from_model(model):
"ogusa_parameters.json")
with open(ogusa_params_path, "r") as f:
OGUSA_PARAMS = json.load(f)

params = {k:inputs[k] for k in USER_MODIFIABLE_PARAMS}
defaults = {'world_int_rate': 0.4}
params = {k:inputs.get(k, defaults[k]) for k in USER_MODIFIABLE_PARAMS}

for k, v in params.items():
if v == '':
Expand Down
25 changes: 25 additions & 0 deletions webapp/apps/dynamic/migrations/0016_auto_20171012_1733.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import models, migrations
import webapp.apps.taxbrain.models


class Migration(migrations.Migration):

dependencies = [
('dynamic', '0015_auto_20170918_1255'),
]

operations = [
migrations.AddField(
model_name='dynamicsaveinputs',
name='small_open',
field=models.NullBooleanField(default=None),
),
migrations.AddField(
model_name='dynamicsaveinputs',
name='world_int_rate',
field=webapp.apps.taxbrain.models.CommaSeparatedField(default=None, max_length=200, null=True, blank=True),
),
]
25 changes: 25 additions & 0 deletions webapp/apps/dynamic/migrations/0017_auto_20171012_1826.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import models, migrations
import webapp.apps.taxbrain.models


class Migration(migrations.Migration):

dependencies = [
('dynamic', '0016_auto_20171012_1733'),
]

operations = [
migrations.AddField(
model_name='dynamicelasticitysaveinputs',
name='small_open',
field=models.NullBooleanField(default=None),
),
migrations.AddField(
model_name='dynamicelasticitysaveinputs',
name='world_int_rate',
field=webapp.apps.taxbrain.models.CommaSeparatedField(default=None, max_length=200, null=True, blank=True),
),
]
25 changes: 25 additions & 0 deletions webapp/apps/dynamic/migrations/0018_auto_20171013_0131.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import models, migrations
import webapp.apps.taxbrain.models


class Migration(migrations.Migration):

dependencies = [
('dynamic', '0017_auto_20171012_1826'),
]

operations = [
migrations.AddField(
model_name='dynamicbehaviorsaveinputs',
name='small_open',
field=models.NullBooleanField(default=None),
),
migrations.AddField(
model_name='dynamicbehaviorsaveinputs',
name='world_int_rate',
field=webapp.apps.taxbrain.models.CommaSeparatedField(default=None, max_length=200, null=True, blank=True),
),
]
7 changes: 7 additions & 0 deletions webapp/apps/dynamic/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ class DynamicSaveInputs(models.Model):
"""

# Parameters used for the dynamic model
small_open = models.NullBooleanField(default=None, blank=True, null=True)
world_int_rate = CommaSeparatedField(default=None, null=True, blank=True)
g_y_annual = CommaSeparatedField(default=None, null=True, blank=True)
g_y_annual_cpi = models.NullBooleanField(default=None, blank=True, null=True)
upsilon = CommaSeparatedField(default=None, null=True, blank=True)
Expand Down Expand Up @@ -62,6 +64,8 @@ class DynamicBehaviorSaveInputs(models.Model):
"""

# Behavioral Effects
small_open = models.NullBooleanField(default=None, blank=True, null=True)
world_int_rate = CommaSeparatedField(default=None, null=True, blank=True)
BE_inc = CommaSeparatedField(default=None, blank=True, null=True)
BE_sub = CommaSeparatedField(default=None, blank=True, null=True)
BE_cg = CommaSeparatedField(default=None, blank=True, null=True)
Expand Down Expand Up @@ -99,6 +103,9 @@ class DynamicElasticitySaveInputs(models.Model):
"""

# Elasticity of GDP w.r.t. average marginal tax rates
small_open = models.NullBooleanField(default=None, blank=True, null=True)
world_int_rate = CommaSeparatedField(default=None, null=True, blank=True)

elastic_gdp = CommaSeparatedField(default=None, blank=True, null=True)

# Job IDs when running a job
Expand Down
52 changes: 51 additions & 1 deletion webapp/apps/dynamic/ogusa_parameters.json
Original file line number Diff line number Diff line change
@@ -1 +1,51 @@
{"g_y_annual": {"col_label": ["Growth rate of technology"], "description": "This parameter gives the underlying growth rate for labor augmenting technological change. The growth rate determines long-run economic growth in OG-USA.", "irs_ref": "", "notes": "", "value": 0.03, "long_name": "Growth rate of technology"}, "frisch": {"col_label": ["Frisch elasticity"], "description": "The Frisch elasticity gives the elasticity of labor supply to changes in the net of tax wage rate, holding wealth constant. This means that the Frisch elasticity captures the substitution effects, but not the income effects, of a change in the net of tax wage rate. A Frisch elasticity of 0.4 would indicate that if the net of tax wage rate increases by 10% then hours worked would increase by 4%, if wealth were held constant. Note that OG-USA uses an elliptical utility function for labor supply. We parameterize this function to fit a constant Frisch elasticity function with a Frisch elasticity as input here.", "irs_ref": "", "notes": "", "validations": {"max": 0.8, "min": 0.1}, "value": 0.4, "long_name": "Frisch elastictiy of labor supply used to fit elliptical utility"}}
{
"g_y_annual": {
"col_label": [
"Growth rate of technology"
],
"description": "This parameter gives the underlying growth rate for labor augmenting technological change. The growth rate determines long-run economic growth in OG-USA.",
"long_name": "Growth rate of technology",
"notes": "",
"value": 0.03,
"irs_ref": ""
},
"frisch": {
"col_label": [
"Frisch elasticity"
],
"description": "The Frisch elasticity gives the elasticity of labor supply to changes in the net of tax wage rate, holding wealth constant. This means that the Frisch elasticity captures the substitution effects, but not the income effects, of a change in the net of tax wage rate. A Frisch elasticity of 0.4 would indicate that if the net of tax wage rate increases by 10% then hours worked would increase by 4%, if wealth were held constant. Note that OG-USA uses an elliptical utility function for labor supply. We parameterize this function to fit a constant Frisch elasticity function with a Frisch elasticity as input here.",
"long_name": "Frisch elastictiy of labor supply used to fit elliptical utility",
"notes": "",
"validations": {
"max": 0.8,
"min": 0.1
},
"value": 0.4,
"irs_ref": ""
},
"world_int_rate": {
"col_label": [
"World interest rate"
],
"description": "World interest rate",
"long_name": "World interest rate if using 'small open' economy",
"notes": "World interest rate if using 'small open' economy",
"validations": {
"max": 0.8,
"min": -0.8
},
"value": 0.04,
"irs_ref": ""
},
"small_open": {
"col_label": [
"Use 'small open' economy"
],
"description": "Small open economy assumptionx",
"long_name": "TODO long_name",
"notes": "TODO notes",
"value": true,
"irs_ref": ""
}
}

2 changes: 1 addition & 1 deletion webapp/apps/dynamic/ogusa_user_modifiable.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"USER_MODIFIABLE_PARAMS": ["g_y_annual", "frisch"]}
{"USER_MODIFIABLE_PARAMS": ["g_y_annual", "frisch", "world_int_rate"]}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import models, migrations


class Migration(migrations.Migration):

dependencies = [
('taxbrain', '0054_outputurl_webapp_vers'),
]

operations = [
migrations.RemoveField(
model_name='taxsaveinputs',
name='reform_style',
),
]