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

Add parameter indexing #65

Merged
merged 10 commits into from Aug 23, 2019

Conversation

@hdoupe
Copy link
Collaborator

commented Jul 8, 2019

This PR adds parameter indexing. This is turned on by setting the class attribute indexed to True and by implementing an indexing_rate method. Here's an example that indexes Tax-Calculator's parameters:

import paramtools

class TaxParams(paramtools.Parameters):
    defaults = {
        "schema": {
            "labels": {
                "year": {
                    "type": "int",
                    "validators": {"range": {"min": 2013, "max": 2027}}
                },
                "marital_status": {
                    "type": "str",
                    "validators": {"choice": {"choices": ["single", "joint"]}}
                },
            }
        },
        "standard_deduction": {
            "title": "Standard deduction amount",
            "description": "Amount filing unit can use as a standard deduction.",
            "type": "float",

            # Set indexed to True to extend standard_deduction with the built-in
            # extension logic.
            "indexed": True,

            "value": [
                {"year": 2017, "marital_status": "single", "value": 6350},
                {"year": 2017, "marital_status": "joint", "value": 12700},
                {"year": 2018, "marital_status": "single", "value": 12000},
                {"year": 2018, "marital_status": "joint", "value": 24000},
                {"year": 2026, "marital_status": "single", "value": 7685},
                {"year": 2026, "marital_status": "joint", "value": 15369}],
            "validators": {
                "range": {
                    "min": 0,
                    "max": 9e+99
                }
            }
        },
    }
    array_first = True
    label_to_extend = "year"
    # Activate use of extend_func method.
    uses_extend_func = True
    # inflation rates from Tax-Calculator v2.5.0
    index_rates = {
        2013: 0.0148,
        2014: 0.0159,
        2015: 0.0012,
        2016: 0.0127,
        2017: 0.0187,
        2018: 0.0224,
        2019: 0.0186,
        2020: 0.0233,
        2021: 0.0229,
        2022: 0.0228,
        2023: 0.0221,
        2024: 0.0211,
        2025: 0.0209,
        2026: 0.0211,
        2027: 0.0208,
        2028: 0.021,
        2029: 0.021
    }


params = TaxParams()
params.standard_deduction

# output:
# array([[ 6074.92, 12149.84],
#        [ 6164.83, 12329.66],
#        [ 6262.85, 12525.7 ],
#        [ 6270.37, 12540.73],
#        [ 6350.  , 12700.  ],
#        [12000.  , 24000.  ],
#        [12268.8 , 24537.6 ],
#        [12497.  , 24994.  ],
#        [12788.18, 25576.36],
#        [13081.03, 26162.06],
#        [13379.28, 26758.55],
#        [13674.96, 27349.91],
#        [13963.5 , 27926.99],
#        [ 7685.  , 15369.  ],
#        [ 7847.15, 15693.29]])

TODO:

  • Implement way for indexing to be turned on and off for specific parameters.
  • Add tests.
  • Add docs.

Note: ParamTools will not support updating index rates after the class has been initialized. That is, any updates to the indexing rates should be applied to the rates before this class is initialized.

@hdoupe

This comment has been minimized.

Copy link
Collaborator Author

commented Jul 30, 2019

Haven't forgotten about #65--I'll be coming back to it soon. I've been caught up with some other projects.

@hdoupe hdoupe referenced this pull request Jul 30, 2019
@hdoupe

This comment has been minimized.

Copy link
Collaborator Author

commented Aug 23, 2019

I'm going to leave creating a way to turn indexing on and off for a separate PR. I think the best way to do this is to allow the user to adjust select attributes on a given parameter's JSON object. For example, one could adjust the indexed attribute with this adjustment:

params.adjust({
    "standard_deduction": [{"indexed": false}]
})

Since this has wide-ranging implications for ParamTools, I'm going to tackle it by itself.

@hdoupe hdoupe merged commit 518a99f into master Aug 23, 2019

2 checks passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
continuous-integration/travis-ci/push The Travis CI build passed
Details

@hdoupe hdoupe deleted the indexing2 branch Aug 23, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
1 participant
You can’t perform that action at this time.