7676 },
7777 {
7878 "cell_type" : " code" ,
79- "execution_count" : 2 ,
79+ "execution_count" : null ,
8080 "metadata" : {
8181 "execution" : {
8282 "iopub.execute_input" : " 2025-09-15T18:56:46.860827Z" ,
8585 "shell.execute_reply" : " 2025-09-15T18:56:46.865211Z"
8686 }
8787 },
88- "outputs" : [
89- {
90- "name" : " stdout" ,
91- "output_type" : " stream" ,
92- "text" : [
93- " Reform defined successfully\n "
94- ]
95- }
96- ],
97- "source" : [
98- " def create_aei_reform():\n " ,
99- " \"\"\"\n " ,
100- " Creates a PolicyEngine reform that adds the California AEI rebate base variables.\n " ,
101- " \n " ,
102- " Returns:\n " ,
103- " Reform: PolicyEngine reform with ca_aei_rebate_base variables\n " ,
104- " \"\"\"\n " ,
105- " \n " ,
106- " class household_fpg(Variable):\n " ,
107- " value_type = float\n " ,
108- " entity = Household\n " ,
109- " label = \" Household's federal poverty guideline\"\n " ,
110- " definition_period = YEAR\n " ,
111- " unit = USD\n " ,
112- " \n " ,
113- " def formula(household, period, parameters):\n " ,
114- " n = household(\" household_size\" , period)\n " ,
115- " state_group = household(\" state_group_str\" , period)\n " ,
116- " p_fpg = parameters(period).gov.hhs.fpg\n " ,
117- " p1 = p_fpg.first_person[state_group]\n " ,
118- " pn = p_fpg.additional_person[state_group]\n " ,
119- " return p1 + pn * (n - 1)\n " ,
120- " \n " ,
121- " class ca_aei_rebate_base_tax_unit(Variable):\n " ,
122- " value_type = float\n " ,
123- " entity = TaxUnit\n " ,
124- " label = \" California AEI rebate base (tax unit version)\"\n " ,
125- " unit = USD\n " ,
126- " definition_period = YEAR\n " ,
127- " defined_for = StateCode.CA\n " ,
128- " \n " ,
129- " def formula(tax_unit, period, parameters):\n " ,
130- " # Use tax unit's own AGI\n " ,
131- " income = tax_unit(\" adjusted_gross_income\" , period)\n " ,
132- " fpg = tax_unit(\" tax_unit_fpg\" , period)\n " ,
133- " income_to_fpg_ratio = where(fpg > 0, income / fpg, np.inf)\n " ,
134- " \n " ,
135- " # Phase-out parameters\n " ,
136- " PHASEOUT_START = 1.5 # 150% FPG\n " ,
137- " PHASEOUT_END = 1.75 # 175% FPG\n " ,
138- " PHASEOUT_WIDTH = PHASEOUT_END - PHASEOUT_START\n " ,
139- " \n " ,
140- " # Phase-out calculation\n " ,
141- " excess = max_(income_to_fpg_ratio - PHASEOUT_START, 0)\n " ,
142- " phaseout_percentage = min_(1, excess / PHASEOUT_WIDTH)\n " ,
143- " \n " ,
144- " return where(\n " ,
145- " income_to_fpg_ratio <= PHASEOUT_END,\n " ,
146- " fpg * (1 - phaseout_percentage),\n " ,
147- " 0\n " ,
148- " )\n " ,
149- " \n " ,
150- " class ca_aei_rebate_base(Variable):\n " ,
151- " value_type = float\n " ,
152- " entity = Household\n " ,
153- " label = \" California AEI rebate base\"\n " ,
154- " unit = USD\n " ,
155- " definition_period = YEAR\n " ,
156- " \n " ,
157- " def formula(household, period, parameters):\n " ,
158- " # Sum AGI from all tax units in the household\n " ,
159- " income = household.sum(household.members.tax_unit(\" adjusted_gross_income\" , period))\n " ,
160- " fpg = household(\" household_fpg\" , period)\n " ,
161- " income_to_fpg_ratio = where(fpg > 0, income / fpg, np.inf)\n " ,
162- " \n " ,
163- " # Phase-out parameters\n " ,
164- " PHASEOUT_START = 1.5 # 150% FPG\n " ,
165- " PHASEOUT_END = 1.75 # 175% FPG\n " ,
166- " PHASEOUT_WIDTH = PHASEOUT_END - PHASEOUT_START\n " ,
167- " \n " ,
168- " # Phase-out calculation\n " ,
169- " excess = max_(income_to_fpg_ratio - PHASEOUT_START, 0)\n " ,
170- " phaseout_percentage = min_(1, excess / PHASEOUT_WIDTH)\n " ,
171- " \n " ,
172- " return where(\n " ,
173- " income_to_fpg_ratio <= PHASEOUT_END,\n " ,
174- " fpg * (1 - phaseout_percentage),\n " ,
175- " 0\n " ,
176- " )\n " ,
177- " \n " ,
178- " class AEIReform(Reform):\n " ,
179- " def apply(self):\n " ,
180- " self.update_variable(household_fpg)\n " ,
181- " self.update_variable(ca_aei_rebate_base_tax_unit)\n " ,
182- " self.update_variable(ca_aei_rebate_base)\n " ,
183- " \n " ,
184- " return AEIReform\n " ,
185- " \n " ,
186- " print(\" Reform defined successfully\" )"
187- ]
88+ "outputs" : [],
89+ "source": "def create_aei_reform():\n \"\"\"\n Creates a PolicyEngine reform that adds the California AEI rebate base variables.\n \n Returns:\n Reform: PolicyEngine reform with ca_aei_rebate_base variables\n \"\"\"\n \n class household_fpg(Variable):\n value_type = float\n entity = Household\n label = \"Household's federal poverty guideline\"\n definition_period = YEAR\n unit = USD\n\n def formula(household, period, parameters):\n n = household(\"household_size\", period)\n state_group = household(\"state_group_str\", period)\n p_fpg = parameters(period).gov.hhs.fpg\n p1 = p_fpg.first_person[state_group]\n pn = p_fpg.additional_person[state_group]\n return p1 + pn * (n - 1)\n \n class ca_aei_rebate_base_tax_unit(Variable):\n value_type = float\n entity = TaxUnit\n label = \"California AEI rebate base (tax unit version)\"\n unit = USD\n definition_period = YEAR\n defined_for = StateCode.CA\n\n def formula(tax_unit, period, parameters):\n # Use tax unit's own AGI\n income = tax_unit(\"adjusted_gross_income\", period)\n fpg = tax_unit(\"tax_unit_fpg\", period)\n income_to_fpg_ratio = where(fpg > 0, income / fpg, np.inf)\n\n # Phase-out parameters\n PHASEOUT_START = 1.5 # 150% FPG\n PHASEOUT_END = 1.75 # 175% FPG\n phaseout_width = PHASEOUT_END - PHASEOUT_START\n\n # Phase-out calculation\n excess = max_(income_to_fpg_ratio - PHASEOUT_START, 0)\n phaseout_percentage = min_(1, excess / phaseout_width)\n\n return where(\n income_to_fpg_ratio <= PHASEOUT_END,\n fpg * (1 - phaseout_percentage),\n 0\n )\n\n class ca_aei_rebate_base(Variable):\n value_type = float\n entity = Household\n label = \"California AEI rebate base\"\n unit = USD\n definition_period = YEAR\n\n def formula(household, period, parameters):\n # Sum AGI from all tax units in the household\n income = household.sum(household.members.tax_unit(\"adjusted_gross_income\", period))\n fpg = household(\"household_fpg\", period)\n income_to_fpg_ratio = where(fpg > 0, income / fpg, np.inf)\n\n # Phase-out parameters\n PHASEOUT_START = 1.5 # 150% FPG\n PHASEOUT_END = 1.75 # 175% FPG\n phaseout_width = PHASEOUT_END - PHASEOUT_START\n\n # Phase-out calculation\n excess = max_(income_to_fpg_ratio - PHASEOUT_START, 0)\n phaseout_percentage = min_(1, excess / phaseout_width)\n\n return where(\n income_to_fpg_ratio <= PHASEOUT_END,\n fpg * (1 - phaseout_percentage),\n 0\n )\n\n class AEIReform(Reform):\n def apply(self):\n self.update_variable(household_fpg)\n self.update_variable(ca_aei_rebate_base_tax_unit)\n self.update_variable(ca_aei_rebate_base)\n \n return AEIReform\n\nprint(\"Reform defined successfully\")"
18890 },
18991 {
19092 "cell_type" : " markdown" ,
569471 },
570472 "nbformat" : 4 ,
571473 "nbformat_minor" : 4
572- }
474+ }
0 commit comments