Created
December 4, 2018 22:35
-
-
Save benjello/49757898c1d83f21e34355555ed57cb8 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# -*- coding: utf-8 -*- | |
from openfisca_core.scenarios import AbstractScenario | |
from openfisca_country_template import CountryTaxBenefitSystem | |
scenario = AbstractScenario() | |
tax_benefit_system = CountryTaxBenefitSystem() | |
scenario.tax_benefit_system = tax_benefit_system | |
# Un scénario se base sur une configuration de base formé d'un cas-type de ménage/famille etc | |
test_case = { | |
'households': [ | |
{ | |
'children': [], | |
u'id': 0, | |
'parents': ['ind0'] | |
} | |
], | |
'persons': [ | |
{'id': 'ind0', 'salary': 1000} | |
] | |
} | |
# Qui peut varier selon plusieurs dimensions | |
# orthogonales | |
perpendicular_axes = [ | |
[ | |
{ | |
'count': 11, | |
'index': 0, | |
'max': 10000, | |
'min': 0, | |
'name': 'salary', | |
'period': "2018-01" | |
} | |
], | |
[ | |
{ | |
'count': 6, | |
'index': 0, | |
'max': 10000, | |
'min': 0, | |
'name': 'pension', | |
'period': "2018-01" | |
} | |
] | |
] | |
# ou parallèles | |
parallel_axes = [ | |
[ | |
{ | |
'count': 11, | |
'index': 0, | |
'max': 10000, | |
'min': 0, | |
'name': 'salary', | |
'period': "2018-01" | |
}, | |
{ | |
'count': 11, | |
'index': 0, | |
'max': 3000, | |
'min': 0, | |
'name': 'rent', | |
'period': "2018-01" | |
} | |
] | |
] | |
# Une fois le scénario initialisé, on peut initialiser une simulation | |
# (voire deux si on est dans le cas d'une réforme non décrite ici) et calculé les | |
scenario.init_from_test_case(period = 2018, test_case = test_case) | |
scenario.axes = perpendicular_axes | |
simulation = scenario.new_simulation() | |
salary = simulation.calculate("salary", "2018-01") | |
income_tax = simulation.calculate("income_tax", "2018-01") | |
rent = simulation.calculate("rent", "2018-01") | |
print("Perpendicalar axes: length of vectors") | |
print(len(income_tax)) | |
print("salary: {}".format(salary)) | |
print("income_tax: {}".format(income_tax)) | |
scenario.init_from_test_case(period = 2018, test_case = test_case) | |
scenario.axes = parallel_axes | |
simulation = scenario.new_simulation() | |
salary = simulation.calculate("salary", "2018-01") | |
income_tax = simulation.calculate("income_tax", "2018-01") | |
rent = simulation.calculate("rent", "2018-01") | |
print("Parallel axes: length of vectors") | |
print(len(income_tax)) | |
print("salary: {}".format(salary)) | |
print("rent: {}".format(rent)) | |
print("income_tax: {}".format(income_tax)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment