This notebook illustrates the key concepts of OpenFisca that you will find in the documentation.
Do some imports.
from pprint import pprint # data pretty printer
from openfisca_core.simulation_builder import SimulationBuilder
from openfisca_france import FranceTaxBenefitSystem
Initialize the French Tax and Benefit system: it launches the entire legislation.
tax_benefit_system = FranceTaxBenefitSystem()
Initialize a test case: first step to give a persons situations for which you want to calculate taxes or benefits.
Here we start with the persons: we have one parent and two children.
TEST_CASE = {
'individus': {
'parent1': {
'age': {'2015-01': 30},
'salaire_de_base': {'2015': 20000}
},
'enfant1': {
'age': {'2015-01': 12}
},
'enfant2': {
'age': {'2015-01': 18}
}
}
}
Define the role of those persons as members of foyers_fiscaux
(tax households), menages
(social households) and familles
(families) groups.
These groups come with the tax and benefit system.
TEST_CASE['foyers_fiscaux'] = {
'foyer_fiscal1': {
'declarants': ['parent1'],
'personnes_a_charge': ['enfant1', 'enfant2']
}
}
TEST_CASE['menages'] = {
'menage1': {
'personne_de_reference': ['parent1'],
'enfants': ['enfant1', 'enfant2']
}
}
TEST_CASE['familles'] = {
'famille1': {
'parents': ['parent1'],
'enfants': ['enfant1', 'enfant2']
}
}
# display full test case
pprint(TEST_CASE)
{'familles': {'famille1': {'enfants': ['enfant1', 'enfant2'], 'parents': ['parent1']}}, 'foyers_fiscaux': {'foyer_fiscal1': {'declarants': ['parent1'], 'personnes_a_charge': ['enfant1', 'enfant2']}}, 'individus': {'enfant1': {'age': {'2015-01': 12}}, 'enfant2': {'age': {'2015-01': 18}}, 'parent1': {'age': {'2015-01': 30}, 'salaire_de_base': {'2015': 20000}}}, 'menages': {'menage1': {'enfants': ['enfant1', 'enfant2'], 'personne_de_reference': ['parent1']}}}
And use this test case to create a simulation: the OpenFisca frame for calculating taxes or benefits.
simulation_builder = SimulationBuilder()
simulation = simulation_builder.build_from_entities(tax_benefit_system, TEST_CASE)
Calculate a variable: af
(family allowance) for example.
simulation.calculate('af', '2015-01')
array([129.99], dtype=float32)
A reform represents a modified version of the real Tax and Benefit legislation*
Reforms are gather in the module Reform
of OpenFisca.
You have then to import the module extension corresponding to the reform of your concern.
Here we choose the fiscal reform of Landais, Piketty and Saez on the income tax ( http://www.revolution-fiscale.fr/la-reforme-proposee ).
It is already implemented in OpenFisca under the name landais_piketty_saez
.
from openfisca_france.reforms import landais_piketty_saez
Create a modified version of the tax and benefit system, affected by the changes introduced by the reform
reform = landais_piketty_saez.landais_piketty_saez(tax_benefit_system)
Create the test case you want to test.
REFORM_TEST_CASE = {
'individus': {
'parent1': {
'age': {'2013-01': 40},
'salaire_de_base': {'2013': 50000}
}
},
'foyers_fiscaux': {
'foyer_fiscal1': {
'declarants': ['parent1']
}
},
'menages': {
'menage1': {
'personne_de_reference': ['parent1'],
}
},
'familles': {
'famille1': {
'parents': ['parent1'],
}
}
}
With the reform:
# Indicate that you want to perfom the reform on this test case
simulation_builder = SimulationBuilder()
# Simulate the reform
reform_simulation = simulation_builder.build_from_entities(reform, REFORM_TEST_CASE)
# Choose the variable you want to calcul : here the disposable income, "revenu_disponible"
reform_simulation.calculate('revenu_disponible', '2013')
array([14256.885], dtype=float32)
Without the reform: the baseline (counterfactual)
# Indicate that you want to perfom the standard system on the same test case
simulation_builder = SimulationBuilder()
baseline_simulation = simulation_builder.build_from_entities(tax_benefit_system, REFORM_TEST_CASE)
# Choose the variable you want to calcul
baseline_simulation.calculate('revenu_disponible', '2013')
array([34682.22], dtype=float32)
%%javascript
$.getScript('https://kmahelona.github.io/ipython_notebook_goodies/ipython_notebook_toc.js')