Skip to content

Commit

Permalink
allow flexible budget year end year
Browse files Browse the repository at this point in the history
  • Loading branch information
jdebacker committed Nov 23, 2024
1 parent 1afd3ca commit f761159
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 40 deletions.
2 changes: 1 addition & 1 deletion taxcalc/calculator.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def __init__(self, policy=None, records=None, verbose=False,
if self.__policy.current_year < self.__records.data_year:
self.__policy.set_year(self.__records.data_year)
if consumption is None:
self.__consumption = Consumption()
self.__consumption = Consumption(policy.nyrs)
elif isinstance(consumption, Consumption):
self.__consumption = copy.deepcopy(consumption)
else:
Expand Down
8 changes: 5 additions & 3 deletions taxcalc/consumption.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,16 @@ class instance: Consumption
"""

JSON_START_YEAR = Policy.JSON_START_YEAR
DEFAULT_NUM_YEARS = Policy.DEFAULT_NUM_YEARS
NUM_YEARS = Policy.NUM_YEARS
DEFAULTS_FILE_NAME = 'consumption.json'
DEFAULTS_FILE_PATH = os.path.abspath(os.path.dirname(__file__))

def __init__(self):
def __init__(self, nyrs=NUM_YEARS):
# put JSON contents of DEFAULTS_FILE_NAME into self._vals dictionary
super().__init__()
print("Consumption num years = ", nyrs)
self.initialize(Consumption.JSON_START_YEAR,
Consumption.DEFAULT_NUM_YEARS)
nyrs)

@staticmethod
def read_json_update(obj):
Expand Down
10 changes: 7 additions & 3 deletions taxcalc/growdiff.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,18 @@ class instance: GrowDiff
"""

JSON_START_YEAR = Policy.JSON_START_YEAR
DEFAULT_NUM_YEARS = Policy.DEFAULT_NUM_YEARS
NUM_YEARS = Policy.NUM_YEARS
DEFAULTS_FILE_NAME = 'growdiff.json'
DEFAULTS_FILE_PATH = os.path.abspath(os.path.dirname(__file__))

def __init__(self):
def __init__(self, nyrs=NUM_YEARS):
# Update defaults to user defined budget window
self.defaults = super().get_defaults()
label = self.defaults["schema"]["labels"]["year"]
label["validators"]["range"]["max"] = GrowDiff.JSON_START_YEAR + nyrs - 1
super().__init__()
self.initialize(GrowDiff.JSON_START_YEAR,
GrowDiff.DEFAULT_NUM_YEARS)
nyrs)

@staticmethod
def read_json_update(obj, topkey):
Expand Down
22 changes: 12 additions & 10 deletions taxcalc/parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,19 +102,12 @@ def __init__(self, start_year=None, num_years=None, last_known_year=None,
self.DEFAULTS_FILE_NAME
)

# def get_defaults(self):
"""
Method to allow for the defaults to be modified.
"""
label = self.default["schema"]["labels"]["year"]
label["validators"]["range"]["max"] = 2074#year_to_extend
return self.defaults

last_budget_year = start_year + num_years - 1
if last_known_year is None:
self._last_known_year = start_year
else:
assert last_known_year >= start_year
assert last_known_year <= self.LAST_BUDGET_YEAR
assert last_known_year <= last_budget_year
self._last_known_year = last_known_year

self._removed_params = removed or self.REMOVED_PARAMS
Expand All @@ -129,8 +122,17 @@ def __init__(self, start_year=None, num_years=None, last_known_year=None,
kwargs["initial_state"] = {
"year": start_year or self.JSON_START_YEAR
}
# Update defaults to user defined budget window
self.defaults = super().get_defaults()
label = self.defaults["schema"]["labels"]["year"]
label["validators"]["range"]["max"] = start_year + num_years - 1
super().__init__(**kwargs)

# def get_defaults(self):
# label = self.defaults["schema"]["labels"]["year"]
# label["validators"]["range"]["max"] = 2074
# return self.defaults

def adjust(
self, params_or_path, print_warnings=True, raise_errors=True, **kwargs
):
Expand Down Expand Up @@ -827,4 +829,4 @@ def is_paramtools_format(params: Union[TaxcalcReform, ParamToolsAdjustment]):
else:
# Not doing a specific check to see if the value is a list
# since it could be a list or just a scalar value.
return True
return True
29 changes: 6 additions & 23 deletions taxcalc/policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,8 @@ class instance: Policy
JSON_START_YEAR = 2013 # remains the same unless earlier data added
LAST_KNOWN_YEAR = 2025 # last year for which indexed param vals are known
# should increase LAST_KNOWN_YEAR by one every calendar year
LAST_BUDGET_YEAR = 2074 # last extrapolation year
# should increase LAST_BUDGET_YEAR by one every calendar year
DEFAULT_NUM_YEARS = LAST_BUDGET_YEAR - JSON_START_YEAR + 1
DEFAULT_LAST_BUDGET_YEAR = 2034 # last extrapolation year
NUM_YEARS = DEFAULT_LAST_BUDGET_YEAR - JSON_START_YEAR + 1

# NOTE: the following three data structures use internal parameter names:
# (1) specify which Policy parameters have been removed or renamed
Expand Down Expand Up @@ -81,11 +80,9 @@ class instance: Policy
# (3) specify which Policy parameters are wage (rather than price) indexed
WAGE_INDEXED_PARAMS = ['SS_Earnings_c', 'SS_Earnings_thd']

def __init__(self, gfactors=None, **kwargs):
def __init__(self, gfactors=None, last_budget_year=DEFAULT_LAST_BUDGET_YEAR, **kwargs):
# put JSON contents of DEFAULTS_FILE_NAME into self._vals dictionary
super().__init__()
# print(self.__dict__)
# self._vals["schema"]["labels"]["year"]["validators"]["range"]["max"] = 2074
# handle gfactors argument
if gfactors is None:
self._gfactors = GrowFactors()
Expand All @@ -95,27 +92,13 @@ def __init__(self, gfactors=None, **kwargs):
raise ValueError('gfactors is not None or a GrowFactors instance')
# read default parameters and initialize
syr = Policy.JSON_START_YEAR
nyrs = Policy.DEFAULT_NUM_YEARS
self.nyrs = last_budget_year - syr + 1
self._inflation_rates = None
self._wage_growth_rates = None
self.initialize(syr, nyrs, Policy.LAST_KNOWN_YEAR,
self.initialize(syr, self.nyrs, Policy.LAST_KNOWN_YEAR,
Policy.REMOVED_PARAMS,
Policy.REDEFINED_PARAMS,
Policy.WAGE_INDEXED_PARAMS, **kwargs)
print("Defaults = ", self.defaults)
# json_params = self.get_defaults()
# label = json_params["schema"]["labels"]["year"]
# label["validators"]["range"]["max"] = 2074
# return self.defaults
# json_params["schema"]["labels"]["year"]["validators"]["range"]["max"] = 2074
# self.defaults = json_params
self.initialize(syr, nyrs, Policy.LAST_KNOWN_YEAR,
Policy.REMOVED_PARAMS,
Policy.REDEFINED_PARAMS,
Policy.WAGE_INDEXED_PARAMS, **kwargs)
# quit()
print("Num years = ", nyrs)
# self.defaults = self.get_defaults()

@staticmethod
def tmd_constructor(growfactors_path): # pragma: no cover
Expand Down Expand Up @@ -191,4 +174,4 @@ def set_rates(self):

self._wage_growth_rates = self._gfactors.wage_growth_rates(
self.start_year, self.end_year
)
)

0 comments on commit f761159

Please sign in to comment.