-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add option for loading from dataframe * Improve flexibility of reforms * Versioning
- Loading branch information
1 parent
b3c4de1
commit dd6ac92
Showing
8 changed files
with
166 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
- bump: minor | ||
changes: | ||
changed: | ||
- Reform syntax to increase flexibility. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"# Reforms\n", | ||
"\n", | ||
"To define a reform, simply define a class inheriting from `Reform` with an `apply(self)` function. Inside it, `self` is the tax-benefit system attached to the simulation with loaded data `self.simulation: Simulation`. From this, you can run any kind of modification on the `Simulation` instance that you like- modify parameters, variable logic or even adjust simulation data." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 1, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"from policyengine_core.country_template import Microsimulation\n", | ||
"from policyengine_core.model_api import *\n", | ||
"\n", | ||
"baseline = Microsimulation()\n", | ||
"\n", | ||
"\n", | ||
"class reform(Reform):\n", | ||
" def apply(self):\n", | ||
" simulation = self.simulation\n", | ||
"\n", | ||
" # Modify parameters\n", | ||
"\n", | ||
" simulation.tax_benefit_system.parameters.taxes.housing_tax.rate.update(\n", | ||
" 20\n", | ||
" )\n", | ||
"\n", | ||
" # Modify simulation data\n", | ||
"\n", | ||
" salary = simulation.calculate(\"salary\", \"2022-01\")\n", | ||
"\n", | ||
" new_salary = salary * 1.1\n", | ||
"\n", | ||
" simulation.set_input(\"salary\", \"2022-01\", new_salary)\n", | ||
"\n", | ||
"\n", | ||
"reformed = Microsimulation(reform=reform)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 2, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/plain": [ | ||
"( value weight\n", | ||
" 0 110.0 1000000.0\n", | ||
" 1 0.0 1000000.0\n", | ||
" 2 220.0 1200000.0,\n", | ||
" value weight\n", | ||
" 0 100.0 1000000.0\n", | ||
" 1 0.0 1000000.0\n", | ||
" 2 200.0 1200000.0)" | ||
] | ||
}, | ||
"execution_count": 2, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"reformed.calculate(\"salary\", \"2022-01\"), baseline.calculate(\n", | ||
" \"salary\", \"2022-01\"\n", | ||
")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 4, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/plain": [ | ||
"( value weight\n", | ||
" 0 4000.0 1000000.0\n", | ||
" 1 6000.0 1200000.0,\n", | ||
" value weight\n", | ||
" 0 2000.0 1000000.0\n", | ||
" 1 3000.0 1200000.0)" | ||
] | ||
}, | ||
"execution_count": 4, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"reformed.calculate(\"housing_tax\", 2022), baseline.calculate(\n", | ||
" \"housing_tax\", 2022\n", | ||
")" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "base", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.9.19" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters