Beispiel #1
0
def menage_enfant_seulement(year = 2013):
    simulation = ScenarioSimulation()
    simulation.set_config(year = year,
                          nmen = 10,
                          maxrev = 0,
                          x_axis= 'sali')
    print simulation.scenario
Beispiel #2
0
def run_simulation(apply_reform=False, reforme=False,
                    conj = False, kids = 0, sal_conj=False, year=2011):

    simulation = ScenarioSimulation()
    simulation.set_config(year = year, nmen = 1001,
                    x_axis = 'sali', maxrev = 10000, reforme = reforme,
                    mode ='bareme', same_rev_couple = False)
    simulation.set_param()

    if sal_conj:
        conj = True

    if conj:
        simulation.scenario.addIndiv(1, datetime(1975,1,1).date(), 'vous', 'part')
        if sal_conj:
            simulation.scenario.indiv[1].update({'sali': simulation.P.cotsoc.gen.smig})

        if kids > 0:
            for n in range(1,kids+1):
                simulation.scenario.addIndiv(n+1, datetime(2000,1,1).date(), 'pac', 'enf')

    print simulation.scenario
    if apply_reform:
        simulation.P.ir.reforme.exemption.active = 1
        simulation.P.cotsoc.gen.smig = 320
        simulation.P_default.cotsoc.gen.smig = 320

    return simulation
Beispiel #3
0
def menage_sans_enfant(year = 2013):
    simulation = ScenarioSimulation()
    simulation.set_config(year = year,
                          nmen = 10,
                          maxrev = 100000,
                          x_axis= 'sali')
    print simulation.scenario
    
    
    simulation.scenario.addIndiv(1, datetime.date(1975,1,1), 'conj','part')
Beispiel #4
0
def test_case_reform(year):
    """
    A test case with reform
    """
    simulation = ScenarioSimulation()
    simulation.set_config(year=year, reforme=True, nmen=1)
    # Adding a husband/wife on the same tax sheet (foyer)

    simulation.set_param()
    test_case = simulation.scenario

    sal_mensuel = 1000
    for i in range(10):
        test_case.indiv[0].update({"sal" + str(i): sal_mensuel * 12})

    test_case.indiv[0].update({"nb_trim_val": 50})
    test_case.indiv[0].update({"age": 54})
    simulation.set_param()

    print simulation.P_default
    param = simulation.P
    # param.pension.rsna.taux_ann_base = .03
    param.pension.rsna.age_dep_anticip = 55

    df = simulation.get_results_dataframe()
    print df.to_string()
Beispiel #5
0
def couple_38ans_avec_3enfants(year = 2013):
    simulation = ScenarioSimulation()
    simulation.set_config(year=year,
					nmen=1,
					maxrev = 500000,
                          x_axis= 'sali',
                          )
    print simulation.scenario
    simulation.scenario.addIndiv(1, datetime(1975,1,1).date(), 'conj', 'part')
    simulation.scenario.addIndiv(2, datetime(2000,1,1).date(), 'pac1', 'enf1')
    simulation.scenario.addIndiv(3, datetime(2005,1,1).date(), 'pac2', 'enf2')
    simulation.scenario.addIndiv(4, datetime(2010,1,1).date(), 'pac3', 'enf3')
Beispiel #6
0
def complete_2012_param(P):
    # Hack to get rid of missing parameters in 2012
    dummy_simulation = ScenarioSimulation()

    dummy_simulation.set_config(year = 2012-1, nmen = 1, reforme = False, mode ='castype',
        decomp_file="decomp_contrib.xml")
    dummy_simulation.set_param()

    P.fam = dummy_simulation.P.fam
    P.minim = dummy_simulation.P.minim
    P.al = dummy_simulation.P.al
    P.ir.crl = dummy_simulation.P.ir.crl
    P.isf = dummy_simulation.P.isf
Beispiel #7
0
def test_case_reform(year):
    """
    A test case with reform
    """
    simulation = ScenarioSimulation()
    simulation.set_config(year=year, reforme=True, nmen=1)
    # Adding a husband/wife on the same tax sheet (foyer)

    simulation.set_param()
    test_case = simulation.scenario

    sal_mensuel = 1000
    for i in range(10):
        test_case.indiv[0].update({"sal" + str(i): sal_mensuel * 12})

    test_case.indiv[0].update({"nb_trim_val": 50})
    test_case.indiv[0].update({"age": 54})
    simulation.set_param()

    print simulation.P_default
    param = simulation.P
    # param.pension.rsna.taux_ann_base = .03
    param.pension.rsna.age_dep_anticip = 55

    df = simulation.get_results_dataframe()
    print df.to_string()
def get_brut_from_net(net,
                      type_sal=0,
                      hsup=0,
                      csg_rempl=0,
                      rev='sal',
                      year=2011):

    from openfisca_core.simulations import ScenarioSimulation
    import openfisca_france
    openfisca_france.init_country()

    simulation = ScenarioSimulation()
    simulation.set_config(year=2011, nmen=2, x_axis="sali", maxrev=100)
    simulation.set_param()
    simulation.compute()

    net = [net]

    _defaultP = simulation.P
    if rev == 'sal':
        output = _salbrut_from_salnet(net, hsup, type_sal, _defaultP)
    elif rev == 'cho':
        output = _chobrut_from_chonet(net, csg_rempl, _defaultP)
    elif rev == 'rst':
        output = _rstbrut_from_rstnet(net, csg_rempl, _defaultP)

    return output
Beispiel #9
0
def test_case(year, save=False):

    country = 'france'
    salaires_nets = 30000
    nmen = 3
    nmax = 1

    for reforme in [False, True]:
        simulation = ScenarioSimulation()
        simulation.set_config(year=year,
                              reforme=reforme,
                              nmen=nmen,
                              maxrev=salaires_nets * nmax,
                              x_axis='sali')

        # Adding a husband/wife on the same tax sheet (foyer)
        simulation.scenario.addIndiv(1, datetime.date(1975, 1, 1), 'conj',
                                     'part')
        #     simulation.scenario.addIndiv(2, datetime(2000,1,1).date(), 'pac', 'enf')
        #     simulation.scenario.addIndiv(3, datetime(2000,1,1).date(), 'pac', 'enf')

        # Loyers set statut d'occupation
        simulation.scenario.menage[0].update({"loyer": 2000})
        simulation.scenario.menage[0].update({"so": 4})

        simulation.set_param()
        simulation.P.ir.autre.charge_loyer.active = 1
        simulation.P.ir.autre.charge_loyer.plaf = 1000
        simulation.P.ir.autre.charge_loyer.plaf_nbp = 0
        print simulation.P
        print type(simulation.P)
        reduc = 0
        print simulation.P.ir.bareme
        print simulation.P.ir.bareme.nb
        for i in range(2, simulation.P.ir.bareme.nb):
            simulation.P.ir.bareme.setSeuil(
                i, simulation.P.ir.bareme.seuils[i] * (1 - reduc))

        print simulation.P.ir.bareme
        print simulation.P.ir.bareme.nb

        if simulation.reforme is True:
            df = simulation.get_results_dataframe(difference=True)
        else:
            df = simulation.get_results_dataframe()
        print df.to_string()

        # Save example to excel
        if save:
            destination_dir = "c:/users/utilisateur/documents/"
            if reforme:
                fname = destination_dir + "Trannoy_reforme_new_diff.%s" % "xlsx"
                print "Saving " + fname
                df.to_excel(fname, sheet_name="difference")
            else:
                fname = destination_dir + "Trannoy_reforme_new.%s" % "xlsx"
                print "Saving " + fname
                df.to_excel(fname, sheet_name="Trannoy")
Beispiel #10
0
def case_study(year = 2013):

    # Creating a case_study household with one individual whose taxable income (salaire imposable, sali
    # varies from 0 to maxrev = 100000 in nmen = 3 steps
    simulation = ScenarioSimulation()
    simulation.set_config(year = year,
                          reforme = True,
                          nmen = 11,
                          maxrev = 100000,
                          x_axis = 'sali')

    print simulation.
    # Adding a husband/wife on the same tax sheet (ie foyer, as conj) and of course same family (as part)
    simulation.scenario.addIndiv(1, datetime(1975, 1, 1).date(), 'conj', 'part')

    # Adding 3 kids on the same tax sheet and family
    simulation.scenario.addIndiv(2, datetime(2001, 1, 1).date(), 'pac', 'enf')
    simulation.scenario.addIndiv(3, datetime(2002, 1, 1).date(), 'pac', 'enf')
    simulation.scenario.addIndiv(4, datetime(2003, 1, 1).date(), 'pac', 'enf')

    # Set legislative parameters
    simulation.set_param()

    # Some prestation can be disabled (herethe aefa prestation) by uncommenting the following line
    # simulation.disable_prestations( ['aefa'])

    # Performing a parameterical reform (inspect openifsca-country.param.param.xml)
    # Lower the part in the quotient familial for the third child from 1 to .5

    print 'default value for P.ir.quotient_familial.enf2 : %s \n' % simulation.P.ir.quotient_familial.enf2
    simulation.P.ir.quotient_familial.enf2 = 0
    print 'reform value for P.ir.quotient_familial.enf2 : %s \n' % simulation.P.ir.quotient_familial.enf2


    # Compute the pandas dataframe of the household case_study
    df = simulation.get_results_dataframe(default = True)
    print df.to_string()

    # Save example to excel
    # destination_dir = "c:/users/utilisateur/documents/"
    # fname = "Example_%s.%s" %(str(yr), "xls")
    # df.to_excel(destination_dir = "c:/users/utilisateur/documents/" + fname)

    df_reform = simulation.get_results_dataframe()
    print df_reform.to_string()

    # Many other variables are accessible
    # Input variables
    print 'list of input variables : %s \n' % simulation.input_var_list
    # Getting the value of some input variables
    print simulation.input_table.table['so']

    # Output variables
    print 'list of output variables : %s \n' % simulation.output_var_list
    print simulation.output_table.table['ir_plaf_qf']
    print simulation.output_table_default.table['ir_plaf_qf']
Beispiel #11
0
def couple_38ans_avec_3enfants(year=2013):
    simulation = ScenarioSimulation()
    simulation.set_config(
        year=year,
        nmen=1,
        maxrev=500000,
        x_axis='sali',
    )
    print simulation.scenario
    simulation.scenario.addIndiv(1,
                                 datetime(1975, 1, 1).date(), 'conj', 'part')
    simulation.scenario.addIndiv(2,
                                 datetime(2000, 1, 1).date(), 'pac1', 'enf1')
    simulation.scenario.addIndiv(3,
                                 datetime(2005, 1, 1).date(), 'pac2', 'enf2')
    simulation.scenario.addIndiv(4,
                                 datetime(2010, 1, 1).date(), 'pac3', 'enf3')
def get_alloc(maxrev = 10000, conj = False, nbenf = 0, zone_apl = 1, loyer_mensuel = 500, nmen = 51):

    # Creating a case_study household with one individual whose taxable income (salaire imposable, sali
    # varies from 0 to maxrev = 100000 in nmen = 3 steps
    simulation = ScenarioSimulation()
    simulation.set_config(year = 2013,
                          nmen = 11,
                          maxrev = maxrev,
                          x_axis = 'sali')


    scenario = simulation.scenario
    if conj:
    # Adding a husband/wife on the same tax sheet (ie foyer, as conj) and of course same family (as part)
        scenario.addIndiv(1, datetime.date(1975, 1, 1), 'conj', 'part')

    for i in range(nbenf):
    # Adding 3 kids on the same tax sheet and family
        scenario.addIndiv(2 + nbenf, datetime.date(2001, 1, 1), 'pac', 'enf')

    # Add caracteristics of menage
    scenario.menage[0]['loyer'] = loyer_mensuel
    scenario.menage[0]['zone_apl'] = zone_apl

    # Set legislative parameters
    simulation.set_param()

    # Compute the pandas dataframe of the household case_study
    df = simulation.get_results_dataframe()
    df2 = df.transpose()[['Salaires imposables', 'Prestations logement']]
    return df2
def get_couple_results_dataframe(sali_vous_maxrev=12 * 4000,
                                 sali_conj=12 * 2000,
                                 nmen=11):

    # Creating a case_study household with one individual whose taxable income (salaire imposable, sali
    # varies from 0 to maxrev = 100000 in nmen = 3 steps
    simulation = ScenarioSimulation()
    simulation.set_config(year=2013,
                          nmen=nmen,
                          maxrev=sali_vous_maxrev,
                          x_axis='sali')

    # Adding a husband/wife on the same tax sheet (ie foyer, as conj) and of course same family (as part)
    simulation.scenario.addIndiv(1, datetime.date(1975, 1, 1), 'conj', 'part')
    simulation.scenario.indiv[1]['sali'] = sali_conj

    # Set legislative parameters
    simulation.set_param()

    df = simulation.get_results_dataframe()

    df2 = df.transpose()[['Salaires imposables', u'Impôt sur le revenu']]
    df2['Salaires imposables vous'] = df2['Salaires imposables'] - sali_conj
    df2['Salaires imposables conj'] = sali_conj

    return df2
def modify_parameters(simulation = None):

    if simulation is None:
        simulation = ScenarioSimulation()
        simulation.set_config(year = 2013)
        simulation.set_param()

    for _P in [simulation.P, simulation.P_default]:

        sal = build_sal(_P)
        pat = build_pat(_P)

        _P.cotsoc.__dict__['cotisations_patronales'] = CompactNode()
        _P.cotsoc.__dict__['cotisations_salariales'] = CompactNode()

        for cotisation_name, bareme_dict in {'cotisations_patronales' : pat, 'cotisations_salariales': sal}.iteritems():
            for category in bareme_dict:
                if category in CAT._nums:
                    _P.cotsoc.__dict__[cotisation_name].__dict__[category] = bareme_dict[category]
def test_nonsal_famille():
    """
    test pour un couple de fonctionnaire
    """
    tests_list = [
# Couple de microentrepreneur
               {"year" : 2013,
              "input_vars":
                    {
                     "birth": datetime.date(1940, 1, 1),
                     "activite": 3,
                     "rsti" : 12500,
                    },
              "output_vars" :
                     {
                     "rst" : 12500,
                    }
              },
                  ]

    passed = True
    for test in tests_list:
        year = test["year"]
        simulation = ScenarioSimulation()
        simulation.set_config(year = test["year"], nmen = 1)
        simulation.set_param()
        test_case = simulation.scenario
        test_case.addIndiv(1, datetime.date(1975, 1, 1), 'conj', 'part')

        for variable, value in test['input_vars'].iteritems():
                if variable in ['activite', 'birth', 'rsti']:
                    test_case.indiv[0].update({variable: value})
                    test_case.indiv[1].update({variable: value})
                else:
                    print variable
                    assert False
        print test_case

        for variable, value in test['output_vars'].iteritems():
            df = simulation.get_results_dataframe(index_by_code = True)
            if variable in df.columns:
                val = df.loc[variable][0]
            else:
                val = simulation.output_table.table[variable][0]
            to_test = abs(val - value)
            if True:  # not (to_test < 1):
                print "Il y a une différence : ", to_test
                print "Pour le scénario", test['input_vars']
                print year
                print variable
                print "OpenFisca :", val
                print "Real value :", value , "\n \n"
                print df.to_string()

                print simulation.input_table.table.transpose().to_string()

    assert passed, "Test failed for some variables"
def test_isf_celib():
    """
    test pour un célibataire
    """
    # Comparaison avec la fiche de paie IPP calculé avec une cotisation transport correspondant à Paris ((.026)
    # alors qu'Openfisca la cacule pour Lyon (.0175)
    tests_list = [
        #   Célibataires (pas de supplément familial de traitement
        {
            "year": 2011,
            "input_vars": {
                "sali": 50000,
                "b1bc": 5000,
                "b1ab": 2500000,
                "b2nf": 7000,
            },
            "output_vars": {
                "irpp": 7889,
                "tot_impot": 2144 + 9389,
                "isf_inv_pme": 3500,
            }
        },
    ]

    passed = True
    for test in tests_list:
        year = test["year"]
        simulation = ScenarioSimulation()
        simulation.set_config(year=test["year"], nmen=1)
        simulation.set_param()

        test_case = simulation.scenario
        for variable, value in test['input_vars'].iteritems():
            if variable in ['zone_apl']:
                test_case.menage[0].update({variable: value})
            else:
                test_case.indiv[0].update({variable: value})

        df = simulation.get_results_dataframe(index_by_code=True)
        for var, value in test['output_vars'].iteritems():

            if var in df.columns:
                val = df.loc[var][0]
            else:
                val = simulation.output_table.table[var][0]

            test_assertion = abs(abs(val) - value) < 1
            #            expression = "Test failed for variable %s on year %i and case %s: \n OpenFisca value : %s \n Real value : %s \n" % (variable, year, test['input_vars'], abs(computed_value), value)

            if not test_assertion:
                print year
                print var
                print "OpenFisca :", val
                print "Real value :", value
                passed = False

    assert passed, "Test failed for some variables"
def test_case(year, save = False):

    country = 'france'
    salaires_nets = 30000
    nmen = 3
    nmax = 1

    for reforme in [False, True]:
        simulation = ScenarioSimulation()
        simulation.set_config(year = year,
                              reforme = reforme,
                              nmen = nmen,
                              maxrev = salaires_nets * nmax,
                              x_axis = 'sali')

        # Adding a husband/wife on the same tax sheet (foyer)
        simulation.scenario.addIndiv(1, datetime.date(1975, 1, 1), 'conj', 'part')
    #     simulation.scenario.addIndiv(2, datetime(2000,1,1).date(), 'pac', 'enf')
    #     simulation.scenario.addIndiv(3, datetime(2000,1,1).date(), 'pac', 'enf')

        # Loyers set statut d'occupation
        simulation.scenario.menage[0].update({"loyer": 2000})
        simulation.scenario.menage[0].update({"so": 4})

        simulation.set_param()
        simulation.P.ir.autre.charge_loyer.active = 1
        simulation.P.ir.autre.charge_loyer.plaf = 1000
        simulation.P.ir.autre.charge_loyer.plaf_nbp = 0
        print simulation.P
        print type(simulation.P)
        reduc = 0
        print simulation.P.ir.bareme
        print len(simulation.P.ir.bareme.thresholds)
        for i in range(2, len(simulation.P.ir.bareme.thresholds)):
            simulation.P.ir.bareme.setSeuil(i, simulation.P.ir.bareme.thresholds[i] * (1 - reduc))

        print simulation.P.ir.bareme
        print len(simulation.P.ir.bareme.thresholds)

        if simulation.reforme is True:
            df = simulation.get_results_dataframe(difference = True)
        else:
            df = simulation.get_results_dataframe()
        print df.to_string()

        # Save example to excel
        if save:
            destination_dir = "c:/users/utilisateur/documents/"
            if reforme:
                fname = destination_dir + "Trannoy_reforme_new_diff.%s" % "xlsx"
                print "Saving " + fname
                df.to_excel(fname, sheet_name = "difference")
            else:
                fname = destination_dir + "Trannoy_reforme_new.%s" % "xlsx"
                print "Saving " + fname
                df.to_excel(fname, sheet_name = "Trannoy")
def get_couple_with_child_results_datatframe(sali_vous = 0, sali_conj = 0):
    simulation = ScenarioSimulation()
    simulation.set_config(year = 2013,
                          nmen = 1)

    # Adding a husband/wife on the same tax sheet (ie foyer, as conj) and of course same family (as part)
    simulation.scenario.addIndiv(1, datetime.date(1975, 1, 1), 'conj', 'part')

    # Adding 1 kids on the same tax sheet and family
    simulation.scenario.addIndiv(2, datetime.date(1993, 1, 1), 'pac', 'enf')

    # Changing the revenu of the parents
    scenario = simulation.scenario
    scenario.indiv[0]['sali'] = sali_vous
    scenario.indiv[1]['sali'] = sali_conj

    # Set the number of major kids in the
    scenario.declar[0]['nbJ'] = 1

    # Set legislative parameters
    simulation.set_param()

    # Compute the pandas dataframe of the household case_study
    df = simulation.get_results_dataframe()
    return df
def get_couple_results_dataframe(sali_vous_maxrev = 12 * 4000, sali_conj = 12 * 4000, nmen = 11):

    # Creating a case_study household with one individual whose taxable income (salaire imposable, sali
    # varies from 0 to maxrev = 100000 in nmen = 11 steps
    simulation = ScenarioSimulation()
    simulation.set_config(year = 2013,
                          nmen = nmen,
                          maxrev = sali_vous_maxrev,
                          x_axis = 'sali')

    # Adding a husband/wife on the same tax sheet (ie foyer, as conj) and of course same family (as part)
    simulation.scenario.addIndiv(1, datetime.date(1975, 1, 1), 'conj', 'part')
    simulation.scenario.indiv[1]['sali'] = sali_conj

    # Set legislative parameters
    simulation.set_param()

    df = simulation.get_results_dataframe()

    df2 = df.transpose()[[u'Salaires imposables', u'Impôt sur le revenu']]
    df2[u'Salaires imposables vous'] = df2[u'Salaires imposables'] - sali_conj
    df2[u'Salaires imposables conj'] = sali_conj
    df2.rename(columns = {u'Impôt sur le revenu' : u'Impôt sur le revenu déclaration commune'},
               inplace = True) 

    df2 = df2.drop(u'Salaires imposables', axis=1)

    return df2
Beispiel #20
0
def test_af2():

    for yr in range(2006, 2010):
        print yr
        simulation = ScenarioSimulation()
        simulation.set_config(year = yr,
                              nmen = 2,
                              maxrev = 100000,
                              x_axis = 'sali')
        # Adding a husband/wife on the same tax sheet (foyer)
        simulation.scenario.addIndiv(1, datetime.date(1975, 1, 1),
                                     'conj', 'part')
        simulation.scenario.addIndiv(2, datetime.date(1975, 2, 2),
                                     'conj', 'part')
        simulation.set_param()
        # Adding children on the same tax sheet (foyer)
        simulation.scenario.addIndiv(3, datetime.date(2000, 1, 1),
                                     'pac', 'enf')
        simulation.scenario.addIndiv(4, datetime.date(2000, 1, 1),
                                     'pac', 'enf')
        df = simulation.get_results_dataframe(index_by_code = True)
#        print df.loc["af"][0]
#        print af_2enf[yr]
#        print type(df.loc["af"][0])
#        print type(af_2enf[yr])
#        print abs(df.loc["af"][0] - af_2enf[yr]) < 1e-3
        assert abs(df.loc["af"][0] - af_2enf[yr]) < 1e-3
Beispiel #21
0
def case_study(year = 2013):

    # Creating a case_study household with one individual whose taxable income (salaire imposable, sali
    # varies from 0 to maxrev = 100000 in nmen = 3 steps

    simulation = ScenarioSimulation()

    simulation.set_config(year = 2013,
                          nmen = 11,
                          maxrev = 10000,
                          x_axis = 'sali')

    print simulation.scenario

    simulation.scenario.addIndiv(1, datetime.date(1975, 1, 1), 'conj', 'part')

    print simulation.scenario

    simulation.set_param()  # Va chercher la legislation par défaut

    df = simulation.get_results_dataframe()

    print df.to_string()

    print simulation.input_table.table.to_string()
    print simulation.output_table.table.to_string()
Beispiel #22
0
def case_study(year=2013):
    #simulation est une classe , Scenariosimulation  est une instance, on a instancier "simulation"
    #on a mainteant fait simulation.set_congif pour modifier les attributs. on lui a dit de prendre l'année 2013
    #avec year=year. reforme = true. Nmen est le nombre de ménage. Maxrev est le salaire imposable de la première personne déclaré.
    # Ici tu prends que deux menage et on fait varier les salaire. Simulation.set.param est la legislation par défaut.

    simulation = ScenarioSimulation()
    simulation.set_config(year=year, nmen=2, maxrev=500000, x_axis='sali')
    simulation.set_param()
    df = simulation.get_results_dataframe()
    print df.to_string()
Beispiel #23
0
def case_study(year = 2013):
    
    simulation = ScenarioSimulation()
    simulation.set_config(year = year,
                          nmen = 20, 
                          maxrev = 20000,
                          x_axis = 'sali')
    scenario = simulation.scenario
    simulation.set_param() #legislation#
    scenario = simulation.scenario
    simulation.set_param()
    df = simulation.get_results_dataframe(index_by_code=True)

    print df.info()
    print df.to_string()
Beispiel #24
0
def test_case(year):
    simulation = ScenarioSimulation()
    simulation.set_config(year = year, reforme=False, nmen = 2, maxrev = 19296, x_axis = 'sali')

    simulation.scenario.addIndiv(1, datetime(2000,1,1).date(), 'pac', 'enf')
    simulation.scenario.addIndiv(2, datetime(2000,1,1).date(), 'pac', 'enf')
#    simulation.scenario.indiv[0]["alr"] = 2107
#    simulation.scenario.indiv[0]["alr_decl"] = False
    simulation.scenario.indiv[0]['caseT'] = True
    simulation.set_param()
    simulation.disable_prestations(["asf", "majo_rsa","api"])
    # A the aefa prestation can be disabled by uncommenting the following line
    # simulation.disable_prestations( ['aefa'])
    df = simulation.get_results_dataframe()
    print df.to_string()
Beispiel #25
0
def test_nonsal_famille():
    """
    test pour un couple de fonctionnaire
    """
    tests_list = [
        # Couple de microentrepreneur
        {
            "year": 2013,
            "input_vars": {
                "ebic_impv": 20000,
                "ebic_impv_c": 10000,
            },
            "output_vars": {
                "rev_microsocial": (20000 + 10000) - (2820 + 1410),
                "microsocial": 200 + 100,
            }
        },
    ]

    passed = True
    for test in tests_list:
        year = test["year"]
        simulation = ScenarioSimulation()
        simulation.set_config(year=test["year"], nmen=1)
        simulation.set_param()
        test_case = simulation.scenario
        test_case.addIndiv(1, datetime.date(1975, 1, 1), 'conj', 'part')

        for variable, value in test['input_vars'].iteritems():
            if variable in ['ebic_impv', 'ebic_imps', 'ebnc_impo']:
                test_case.indiv[0].update({variable: value})
            elif variable in ['ebic_impv_c', 'ebic_imps_c', 'ebnc_impo_c']:
                test_case.indiv[1].update({variable[:-2]: value})
            else:
                print variable
                assert False

        for variable, value in test['output_vars'].iteritems():
            df = simulation.get_results_dataframe(index_by_code=True)
            if variable in df.columns:
                val = df.loc[variable][0]
            else:
                val = simulation.output_table.table[variable][0]
            to_test = abs(val - value)
            if not (to_test < 1):
                print "Il y a une différence : ", to_test
                print "Pour le scénario", test['input_vars']
                print year
                print variable
                print "OpenFisca :", val
                print "Real value :", value, "\n \n"

    assert passed, "Test failed for some variables"
Beispiel #26
0
def case_study(year = 2013):
    simulation = ScenarioSimulation()  #on instancie on prends une instance de ScenarioSimulation, on prends un exemple de cette classe là
    simulation.set_config(year = year, 
                    nmen = 4, #nombre de ménages
                    maxrev = 10000, 
                    x_axis = 'sali')#salaire imposable (une seule personne dans le ménage)
    simulation.set_param()#prends les paramètres par défaut de la législation
    df = simulation.get_results_dataframe() #renvoie la dataframe avec tout calculé
    print df.to_string()
Beispiel #27
0
def test_case(year):

    simulation = ScenarioSimulation()
    simulation.set_config(year=year, reforme=False, nmen=4, maxrev=25 * 9 * 12 * 3, x_axis="sal0")
    # Adding a husband/wife on the same tax sheet (foyer)

    simulation.set_param()
    df = simulation.get_results_dataframe()
    print df.to_string()
Beispiel #28
0
def case_study(year=2013):
    simulation = ScenarioSimulation(
    )  #on instancie on prends une instance de ScenarioSimulation, on prends un exemple de cette classe là
    simulation.set_config(
        year=year,
        nmen=500,  #nombre de ménages
        maxrev=100000,
        x_axis='sali')  #salaire imposable (une seule personne dans le ménage)
    simulation.set_param()  #prends les paramètres par défaut de la législation
    df = simulation.get_results_dataframe(
    )  #renvoie la dataframe avec tout calculé
    #print df.to_string()
    return df
Beispiel #29
0
def test_case(year):

    simulation = ScenarioSimulation()
    simulation.set_config(year=year,
                          reforme=False,
                          nmen=4,
                          maxrev=25 * 9 * 12 * 3,
                          x_axis='sal0')
    # Adding a husband/wife on the same tax sheet (foyer)

    simulation.set_param()
    df = simulation.get_results_dataframe()
    print df.to_string()
def test_nonsal_celib():
    """
    test pour un célibataire
    """
    tests_list = [
             {"year" : 2013,
              "input_vars":
                    {
                     "activite": 3,
                     "rsti" : 12500,
                    },
              "output_vars" :
                     {
                      "rst": 12500,
                    }
              },
            ]

    passed = True
    for test in tests_list:
        year = test["year"]
        simulation = ScenarioSimulation()
        simulation.set_config(year = test["year"], nmen = 1)
        simulation.set_param()

        test_case = simulation.scenario
        for variable, value in test['input_vars'].iteritems():
                if variable in ['rsti']:
                    test_case.indiv[0].update({variable: value})
                else:
                    print variable
                    assert False

        for variable, value in test['output_vars'].iteritems():
            df = simulation.get_results_dataframe(index_by_code = True)
            if variable in df.columns:
                val = df.loc[variable][0]
            else:
                val = simulation.output_table.table[variable][0]
            to_test = abs(val - value)
            if True:  # not (to_test < 1):
                print "Il y a une différence : ", to_test
                print "Pour le scénario", test['input_vars']
                print year
                print variable
                print "OpenFisca :", val
                print "Real value :", value , "\n \n"
                print df.to_string()

    assert passed, "Test failed for some variables"
def get_child_results_datatframe(pension_alimentaire=0):
    simulation = ScenarioSimulation()
    simulation.set_config(year=2013, nmen=1)

    scenario = simulation.scenario

    # Set the number of major kids in the
    scenario.declar[0]['alr'] = pension_alimentaire
    # Set legislative parameters
    simulation.set_param()

    # Compute the pandas dataframe of the household case_study
    df = simulation.get_results_dataframe()
    return df
Beispiel #32
0
def test_nonsal_famille():
    """
    test pour un couple de fonctionnaire
    """
    tests_list = [
# Couple de microentrepreneur
               {"year" : 2013,
              "input_vars":
                    {
                     "ebic_impv" : 20000,
                      "ebic_impv_c" : 10000,
                    },
              "output_vars" :
                     {
                      "rev_microsocial": (20000 + 10000) - (2820 + 1410), 
                      "microsocial" : 200 + 100,
                    }
              },
                  ]
    
    passed = True
    for test in tests_list:
        year = test["year"]
        simulation = ScenarioSimulation()
        simulation.set_config(year = test["year"], nmen = 1)
        simulation.set_param()
        test_case = simulation.scenario
        test_case.addIndiv(1, datetime.date(1975, 1, 1), 'conj', 'part')
        
        for variable, value in test['input_vars'].iteritems():
                if variable in ['ebic_impv', 'ebic_imps', 'ebnc_impo']:
                    test_case.indiv[0].update({variable: value})
                elif variable in ['ebic_impv_c', 'ebic_imps_c', 'ebnc_impo_c']:
                    test_case.indiv[1].update({variable[:-2]: value})
                else:
                    print variable
                    assert False

        for variable, value in test['output_vars'].iteritems():
            df = simulation.get_results_dataframe(index_by_code = True)
            if variable in df.columns:
                val = df.loc[variable][0]
            else:
                val = simulation.output_table.table[variable][0]
            to_test = abs(val - value)
            if not (to_test < 1):
                print "Il y a une différence : ", to_test
                print "Pour le scénario", test['input_vars']
                print year
                print variable
                print "OpenFisca :", val
                print "Real value :", value , "\n \n"

    assert passed, "Test failed for some variables"
Beispiel #33
0
def test_case_study(year = 2013, verbose = False):
    '''
    Tests that _salbrut which computes "salaire brut" from "imposable" yields an amount compatbe
    with the one obtained from running openfisca satrting with a "salaire brut"
    '''

    for type_sal_category in ['prive_non_cadre', 'prive_cadre']:  # , 'public_titulaire_etat']:
        simulation = ScenarioSimulation()
        maxrev = 50000
        simulation.set_config(year = year, reforme = False, nmen = 11, maxrev = maxrev, x_axis = 'salbrut')
        simulation.scenario.indiv[0]['salbrut'] = maxrev
        simulation.scenario.indiv[0]['type_sal'] = CAT[type_sal_category]
        if type_sal_category == 'public_titulaire_etat':
            from openfisca_france.model.cotisations_sociales.travail import TAUX_DE_PRIME
            simulation.scenario.indiv[0]['primes'] = TAUX_DE_PRIME * maxrev

        simulation.set_param()

        # The aefa prestation can be disabled by uncommenting the following line:
        # simulation.disable_prestations( ['aefa'])
        df = simulation.get_results_dataframe(index_by_code = True)

        from openfisca_france.model.inversion_revenus import _salbrut_from_salnet
        df_b2n = df.transpose()
        if verbose:

            print df_b2n.to_string()

        salnet = df_b2n['salnet'].get_values()
        hsup = simulation.input_table.table['hsup'].get_values()
        type_sal = simulation.input_table.table['type_sal'].get_values()
        primes = simulation.input_table.table['hsup'].get_values()

        defaultP = simulation.P_default
        from pandas import DataFrame
        df_n2b = DataFrame({'salnet': salnet, 'salbrut' : _salbrut_from_salnet(salnet, hsup, type_sal, defaultP) })

        if verbose:
            print df_n2b.to_string()


        for var in ['salnet', 'salbrut']:
            passed = ((df_b2n[var] - df_n2b[var]).abs() < .01).all()

            if (not passed) or type_sal_category in ['public_titulaire_etat']:
                print (df_b2n / 12).to_string()
                print (df_n2b / 12).to_string()

            assert passed, "difference in %s for %s" % (var, type_sal_category)
Beispiel #34
0
def test_bareme(x_axis="sali"):
    """
    Use to test and debug bareme mode test-case
    """

    yr = 2012
    # Changes in individualized characteristics
    # salaires: sali
    # retraites: choi
    # intérêts: f2ee intpfl; f2tr intb
    # dividendes: f2da divplf; f2dc divb
    # foncier  f4ba fon (micro foncier f4be)


    maxrev = 500000
    year = 2012
    simulation = ScenarioSimulation()

    # Changes in individualized caracteristics
    # salaires: sali
    # retraites: choi
    # intérêts: f2ee intpfl; f2tr intb
    # dividendes: f2da divplf; f2dc divb
    # foncier  f4ba fon (micro foncier f4be)

    simulation.set_config(year = yr, nmen = 101, x_axis = x_axis, maxrev=maxrev,
                          reforme = False, mode ='bareme', decomp_file="decomp_contrib.xml")
    simulation.set_param()
    # Hack to get rid of missing parameters in 2012
    if yr == 2012:
        complete_2012_param(simulation.P)


    test_case = simulation.scenario

    if SHOW_OPENFISCA:
        app = QApplication(sys.argv)
        win = ApplicationWindow()
        ax = win.mplwidget.axes
        title ="Barème openfisca"
        ax.set_title(title)
        graph_x_axis = simulation.get_varying_revenues(x_axis)
        draw_simulation_bareme(simulation, ax, graph_x_axis = graph_x_axis, legend = True, position = 4)
        win.resize(1400,700)
        win.mplwidget.draw()
        win.show()

    if EXPORT:
        win.mplwidget.print_figure(DESTINATION_DIR + title + '.png')

    if ax:
        del ax
    del simulation
    sys.exit(app.exec_())
Beispiel #35
0
def test_case(year):

    country = 'france'
    salaires_nets = 50000
    nmen = 100 #nombre de ménages que je fait varier

    for reforme in [False, True]: #fais tourner un fois pour faux et une fois pour vrai
        #print reforme
        simulation = ScenarioSimulation()
        simulation.set_config(year = year,
                              reforme = reforme,
                              nmen = nmen,
                              maxrev = salaires_nets,
                              x_axis = 'sali')

        # Adding a husband/wife on the same tax sheet (foyer)
        simulation.scenario.addIndiv(1, datetime.date(1975, 1, 1), 'conj', 'part')
    #     simulation.scenario.addIndiv(2, datetime(2000,1,1).date(), 'pac', 'enf')
    #     simulation.scenario.addIndiv(3, datetime(2000,1,1).date(), 'pac', 'enf')

        # Loyers set statut d'occupation
        simulation.scenario.menage[0].update({"loyer": 2000}) #fixe les variables au niveau du ménage
        simulation.scenario.menage[0].update({"so": 4}) #

        simulation.set_param() #va chercher des params de la législation
        simulation.P.ir.autre.charge_loyer.active = 1  #simulation.p est un attribu de simulation
        simulation.P.ir.autre.charge_loyer.plaf = 1000
        simulation.P.ir.autre.charge_loyer.plaf_nbp = 0
        #print simulation.P #montre ce qui est écrit dans param.xml
        reduc = 0
        #print simulation.P.ir.bareme #change le barème de l'impot sur le revenu
        #print simulation.P.ir.bareme.nb #nb de tranche du brarème de l'impot
        for i in range(2, simulation.P.ir.bareme.nb):
            simulation.P.ir.bareme.setSeuil(i, simulation.P.ir.bareme.seuils[i] * (1 - reduc)) #a partir de la 2nd tranche réduit les seuils des barèmes

        #print simulation.P.ir.bareme #nouvea barème
        #print simulation.P.ir.bareme.nb

        if simulation.reforme is True:
            df = simulation.get_results_dataframe(default = True , difference = False) # prends la différence(argument de la fonction getresultdataframe
            return df
        else:
            df = simulation.get_results_dataframe()
Beispiel #36
0
def test_case(year):
    simulation = ScenarioSimulation()
    simulation.set_config(year = year, reforme=False, nmen = 3, maxrev = 12*400, x_axis = 'sali')
    # Adding a husband/wife on the same tax sheet (foyer)
    simulation.scenario.addIndiv(1, datetime(1975,1,1).date(), 'conj', 'part')

    simulation.scenario.addIndiv(2, datetime(2000,1,1).date(), 'pac', 'enf')
    simulation.scenario.addIndiv(3, datetime(2000,1,1).date(), 'pac', 'enf')

    simulation.set_param()
    df = simulation.get_results_dataframe()
    print df.to_string()
Beispiel #37
0
def test_case(year):
    simulation = ScenarioSimulation()
    simulation.set_config(year = year, reforme = False,
                    nmen = 3, maxrev = 100000, x_axis = 'sali')
    # Adding a husband/wife on the same tax sheet (foyer)
    simulation.scenario.addIndiv(1, datetime(1975, 1, 1).date(), 'conj', 'part')
    simulation.set_param()

    # A the aefa prestation can be disabled by uncommenting the following line
    # simulation.disable_prestations( ['aefa'])
    df = simulation.get_results_dataframe()
    print df.to_string()
def check_test_case(year = 2013):
    simulation = ScenarioSimulation()
    simulation.set_config(year = year, nmen = 2, maxrev = 2000, reforme = False, x_axis = 'sali')
#    simulation.scenario.indiv[0]['sali'] = 16207
#    # Add husband/wife on the same tax sheet (foyer)
#    simulation.scenario.addIndiv(1, datetime.date(1975, 1, 1), 'conj', 'part')
    simulation.set_param()

    # The aefa prestation can be disabled by uncommenting the following line:
    # simulation.disable_prestations( ['aefa'])
    df = simulation.get_results_dataframe()
    print df.to_string().encode('utf-8')
def check_test_case(year=2013):
    simulation = ScenarioSimulation()
    simulation.set_config(year=year,
                          nmen=2,
                          maxrev=2000,
                          reforme=False,
                          x_axis='sali')
    #    simulation.scenario.indiv[0]['sali'] = 16207
    #    # Add husband/wife on the same tax sheet (foyer)
    #    simulation.scenario.addIndiv(1, datetime.date(1975, 1, 1), 'conj', 'part')
    simulation.set_param()

    # The aefa prestation can be disabled by uncommenting the following line:
    # simulation.disable_prestations( ['aefa'])
    df = simulation.get_results_dataframe()
    print df.to_string().encode('utf-8')
Beispiel #40
0
def test_case(year, save = False):

    country = 'france'
    salaires_nets = 1120.43*12
    nmen = 20
    nmax = 3

    for reforme in [False, True]:
        simulation = ScenarioSimulation()
        simulation.set_config(year = year, 
                              param_file = param_file,
                              reforme=reforme,
                              nmen = nmen,
                              maxrev = salaires_nets*nmax,
                              x_axis = 'sali')
        
        # Adding a husband/wife on the same tax sheet (foyer)
        simulation.scenario.addIndiv(1, datetime.date(1975,1,1), 'conj', 'part') 
    #     simulation.scenario.addIndiv(2, datetime(2000,1,1).date(), 'pac', 'enf')
    #     simulation.scenario.addIndiv(3, datetime(2000,1,1).date(), 'pac', 'enf')
        
        # Loyers set statut d'occupation
        simulation.scenario.menage[0].update({"loyer": 1120.43/3}) 
        simulation.scenario.menage[0].update({"so": 4})
    
        simulation.set_param()
        simulation.P.ir.autre.charge_loyer.active = 1
        simulation.P.ir.autre.charge_loyer.plaf = 1000
        simulation.P.ir.autre.charge_loyer.plaf_nbp = 0 
    
        reduc = 0
        print simulation.P.ir.bareme
        print simulation.P.ir.bareme.nb
        for i in range(2, simulation.P.ir.bareme.nb):
            simulation.P.ir.bareme.setSeuil(i, simulation.P.ir.bareme.seuils[i]*(1-reduc) )
    
        print simulation.P.ir.bareme
        print simulation.P.ir.bareme.nb
    
        df = simulation.get_results_dataframe()
        print df.to_string()
        
        #Save example to excel
        if save:
            destination_dir = "c:/users/utilisateur/documents/"
            fname = "Trannoy_reforme.%s" %"xls"    
            
            if reforme:
                df.to_excel(destination_dir  + fname, sheet_name="difference")
            else:
                df.to_excel(destination_dir  + fname, sheet_name="Trannoy")
def test_case(year):
    simulation = ScenarioSimulation()
    simulation.set_config(year=year,
                          reforme=False,
                          nmen=11,
                          maxrev=12000,
                          x_axis='salaire_imposable')
    # Adding a husband/wife on the same tax sheet (foyer)
    simulation.scenario.addIndiv(1, datetime.date(1975, 1, 1), 'conj', 'part')
    simulation.scenario.addIndiv(2, datetime.date(2000, 1, 1), 'pac', 'enf')
    simulation.scenario.addIndiv(3, datetime.date(2000, 1, 1), 'pac', 'enf')

    simulation.set_param()
    simulation.P.impot_revenu.reforme.exemption.active = 1

    df = simulation.get_results_dataframe()
    print df.to_string()
Beispiel #42
0
def test_case(year):
    simulation = ScenarioSimulation()
    simulation.set_config(year=year,
                          reforme=False,
                          nmen=3,
                          maxrev=12 * 400,
                          x_axis='sali')
    # Adding a husband/wife on the same tax sheet (foyer)
    simulation.scenario.addIndiv(1,
                                 datetime(1975, 1, 1).date(), 'conj', 'part')

    simulation.scenario.addIndiv(2, datetime(2000, 1, 1).date(), 'pac', 'enf')
    simulation.scenario.addIndiv(3, datetime(2000, 1, 1).date(), 'pac', 'enf')

    simulation.set_param()
    df = simulation.get_results_dataframe()
    print df.to_string()
Beispiel #43
0
def case_study(year = 2013) :
#simulation est une classe , Scenariosimulation  est une instance, on a instancier "simulation"
#on a mainteant fait simulation.set_congif pour modifier les attributs. on lui a dit de prendre l'année 2013
#avec year=year. reforme = true. Nmen est le nombre de ménage. Maxrev est le salaire imposable de la première personne déclaré.
# Ici tu prends que deux menage et on fait varier les salaire. Simulation.set.param est la legislation par défaut.

    simulation = ScenarioSimulation()
    simulation.set_config(year = year,
                          nmen = 2,
                          maxrev = 500000,
                          x_axis= 'sali')
    simulation.set_param()
    df = simulation.get_results_dataframe()
    print df.to_string()
Beispiel #44
0
def test_case(year):
    simulation = ScenarioSimulation()
    simulation.set_config(year=year,
                          reforme=False,
                          nmen=3,
                          maxrev=1180 * 12,
                          x_axis='sali')
    # Adding a husband/wife on the same tax sheet (foyer)
    simulation.scenario.addIndiv(1,
                                 datetime(1975, 1, 1).date(), 'conj', 'part')
    simulation.scenario.addIndiv(2, datetime(2000, 1, 1).date(), 'pac', 'enf')
    simulation.scenario.addIndiv(3, datetime(2000, 1, 1).date(), 'pac', 'enf')
    simulation.set_param()

    # A the aefa prestation can be disabled by uncommenting the following line
    # simulation.disable_prestations( ['aefa'])
    df = simulation.get_results_dataframe()
    print df.to_string()
def test_case_study(year = 2013, verbose = False):
    '''
    Tests that _salbrut which computes "salaire brut" from "imposable" yields an amount compatbe
    with the one obtained from running openfisca satrting with a "salaire brut"
    '''

    for type_sal_category in ['prive_non_cadre', 'prive_cadre']:  # , 'public_titulaire_etat']:
        simulation = ScenarioSimulation()
        maxrev = 24000
        simulation.set_config(year = year, reforme = False, nmen = 11, maxrev = maxrev, x_axis = 'salbrut')
        simulation.scenario.indiv[0]['salbrut'] = maxrev
        simulation.scenario.indiv[0]['type_sal'] = CAT[type_sal_category]
        if type_sal_category == 'public_titulaire_etat':
            from openfisca_france.model.cotisations_sociales.travail import TAUX_DE_PRIME
            simulation.scenario.indiv[0]['primes'] = TAUX_DE_PRIME * maxrev

        simulation.set_param()

        # The aefa prestation can be disabled by uncommenting the following line:
        # simulation.disable_prestations( ['aefa'])
        df = simulation.get_results_dataframe(index_by_code = True)

        from openfisca_france.model.inversion_revenus import _salbrut
        df_b2i = df.transpose()
        if verbose:

            print df_b2i.to_string()

        sali = df_b2i['sal'].get_values()
        hsup = simulation.input_table.table['hsup'].get_values()
        type_sal = simulation.input_table.table['type_sal'].get_values()
        primes = simulation.input_table.table['hsup'].get_values()

        defaultP = simulation.P_default
        from pandas import DataFrame
        df_i2b = DataFrame({'sal': sali, 'salbrut' : _salbrut(sali, hsup, type_sal, defaultP) })

        if verbose:
            print df_i2b.to_string()


        for var in ['sal', 'salbrut']:
            passed = ((df_b2i[var] - df_i2b[var]).abs() < .01).all()

            if (not passed) or type_sal_category in ['public_titulaire_etat']:
                print (df_b2i / 12).to_string()
                print (df_i2b / 12).to_string()

            assert passed, "difference in %s for %s" % (var, type_sal_category)
Beispiel #46
0
def case_study(year = 2013):
    
    simulation = ScenarioSimulation()
    simulation.set_config(year = 2013, 
                          nmen = 2,
                          maxrev = 10000,
                          x_axis = 'sali')
    simulation.set_param()
    df = simulation.get_results_datafram()
    print df.to_string()
    
    if_name_**'__main__' 
    
    
    case_study_()
def get_child_results_datatframe(pension_alimentaire = 0):
    simulation = ScenarioSimulation()
    simulation.set_config(year = 2013,
                          nmen = 1)

    scenario = simulation.scenario

    # Set the number of major kids in the
    scenario.declar[0]['alr'] = pension_alimentaire
    # Set legislative parameters
    simulation.set_param()

    # Compute the pandas dataframe of the household case_study
    df = simulation.get_results_dataframe()
    return df
def test_case_study(year = 2013, verbose = False):
    for type_sal_category in ['prive_non_cadre', 'prive_cadre', 'public_titulaire_etat']:

        simulation = ScenarioSimulation()
        maxrev = 24000
        simulation.set_config(year = year, reforme = False, nmen = 1, x_axis = 'salbrut')
        # Add husband/wife on the same tax sheet (foyer).
    #    simulation.scenario.addIndiv(1, datetime.date(1975, 1, 1), 'conj', 'part')
        simulation.scenario.indiv[0]['salbrut'] = maxrev
        simulation.scenario.indiv[0]['type_sal'] = CAT[type_sal_category]
        if type_sal_category == 'public_titulaire_etat':
            from openfisca_france.model.cotisations_sociales.travail import TAUX_DE_PRIME
            simulation.scenario.indiv[0]['primes'] = TAUX_DE_PRIME * maxrev

        simulation.set_param()

        # The aefa prestation can be disabled by uncommenting the following line:
        # simulation.disable_prestations( ['aefa'])
        df = simulation.get_results_dataframe(index_by_code = True)


        from openfisca_france.model.cotisations_sociales.travail import _salbrut
        df_b2i = df.transpose()
        if verbose:

            print df_b2i.to_string()

        sali = df_b2i['sal'].get_values()
        hsup = simulation.input_table.table['hsup'].get_values()
        type_sal = simulation.input_table.table['type_sal'].get_values()
        primes = simulation.input_table.table['hsup'].get_values()

        defaultP = simulation.P_default
        from pandas import DataFrame
        df_i2b = DataFrame({'sal': sali, 'salbrut' : _salbrut(sali, hsup, type_sal, defaultP) })

        if verbose:
            print df_i2b.to_string()


        for var in ['sal', 'salbrut']:
            test = ((df_b2i[var] - df_i2b[var]).abs() < .01).all()

            if (not test) or type_sal_category in ['public_titulaire_etat']:
                print (df_b2i / 12).to_string()
                print (df_i2b / 12).to_string()

            assert test, "difference in %s for %s" % (var, type_sal_category)
Beispiel #49
0
def get_vous_results_dataframe(sali_single_maxrev=12 * 4000, nmen=11):

    simulation = ScenarioSimulation()
    simulation.set_config(year=2013,
                          nmen=nmen,
                          maxrev=sali_single_maxrev,
                          x_axis='sali')

    # Set legislative parameters
    simulation.set_param()

    df = simulation.get_results_dataframe()

    df2 = df.transpose()[[u'Salaires imposables', u'Impôt sur le revenu']]
    df2.rename(columns={u'Salaires imposables': u'Salaires imposables vous'},
               inplace=True)
    df2.rename(columns={u'Impôt sur le revenu': u'Impôt sur le revenu vous'},
               inplace=True)
    return df2
Beispiel #50
0
def complete_2012_param(P):
    # Hack to get rid of missing parameters in 2012
    dummy_simulation = ScenarioSimulation()

    dummy_simulation.set_config(year=2012 - 1,
                                nmen=1,
                                reforme=False,
                                mode='castype',
                                decomp_file="decomp_contrib.xml")
    dummy_simulation.set_param()

    P.fam = dummy_simulation.P.fam
    P.minim = dummy_simulation.P.minim
    P.al = dummy_simulation.P.al
    P.ir.crl = dummy_simulation.P.ir.crl
    P.isf = dummy_simulation.P.isf
Beispiel #51
0
def case_study2(year=2013):
    simulation = ScenarioSimulation(
    )  #on instancie on prends une instance de ScenarioSimulation, on prends un exemple de cette classe là
    simulation.set_config(
        year=year,
        nmen=8,  #nombre de ménages
        maxrev=10000,
        x_axis='sali')  #salaire imposable (une seule personne dans le ménage)
    #print simulation.scenario

    simulation.scenario.addIndiv(1, datetime.date(1975, 1, 1), 'conj', 'part')

    simulation.set_param()  #prends les paramètres par défaut de la législation
    df = simulation.get_results_dataframe(
        index_by_code=True)  #renvoie la dataframe avec tout calculé

    print df.to_string()
    #print df.transpose()['logt']

    a = df.loc['sal']
    print a
Beispiel #52
0
def test_af2b():
    for yr in range(2006, 2010):
        simulation = ScenarioSimulation()
        simulation.set_config(year=yr, nmen=2, maxrev=100000, x_axis='sali')
        # Adding a husband/wife on the same tax sheet (foyer)
        simulation.scenario.addIndiv(1, datetime.date(1975, 1, 1), 'conj',
                                     'part')
        simulation.scenario.addIndiv(2, datetime.date(1975, 2, 2), 'conj',
                                     'part')
        simulation.set_param()
        # Adding children on the same tax sheet (foyer)
        simulation.scenario.addIndiv(3, datetime.date(1992, 1, 1), 'pac',
                                     'enf')
        simulation.scenario.addIndiv(4, datetime.date(1990, 1, 1), 'pac',
                                     'enf')
        df = simulation.get_results_dataframe(index_by_code=True)
        #        print df.loc["af"][0]
        #        print af_2enf[yr]
        #        print type(df.loc["af"][0])
        #        print type(af_2enf[yr])
        #        print abs(df.loc["af"][0] - af_2enf[yr]) < 1e-3
        assert abs(df.loc["af"][0] - af_2enfb[yr]) < 1e-3
Beispiel #53
0
def test_cho_rst(year = 2013, verbose = False):
    '''
    Tests that _chobrut which computes "chômage brut" from "imposable" yields an amount compatbe
    with the one obtained from running openfisca satrting with a "chômage brut"
    '''
    remplacement = {'cho' : 'chobrut', 'rst': 'rstbrut'}

    for var, varbrut in remplacement.iteritems():
        simulation = ScenarioSimulation()
        maxrev = 24000
        simulation.set_config(year = year, reforme = False, nmen = 11, maxrev = maxrev, x_axis = varbrut)
        simulation.set_param()
        df = simulation.get_results_dataframe(index_by_code = True)

        from openfisca_france.model.inversion_revenus import _chobrut
        df_b2i = df.transpose()
        if verbose:
            print df_b2i.to_string()

            vari = df_b2i[var].get_values()
            csg_rempl = vari * 0 + 1

            defaultP = simulation.P_default
            from pandas import DataFrame
            df_i2b = DataFrame({var: vari, varbrut : _chobrut(vari, csg_rempl, defaultP) })

            if verbose:
                print df_i2b.to_string()


            for variable in [var, varbrut]:
                passed = ((df_b2i[variable] - df_i2b[variable]).abs() < .01).all()

                if (not passed):
                    print (df_b2i / 12).to_string()
                    print (df_i2b / 12).to_string()

                assert passed, "difference in %s " % (var)
Beispiel #54
0
def case_study(year=2013):

    # Creating a case_study household with one individual whose taxable income (salaire imposable, sali
    # varies from 0 to maxrev = 100000 in nmen = 3 steps

    simulation = ScenarioSimulation()

    simulation.set_config(year=2013, nmen=11, maxrev=10000, x_axis='sali')

    print simulation.scenario

    simulation.scenario.addIndiv(1, datetime.date(1975, 1, 1), 'conj', 'part')

    print simulation.scenario

    simulation.set_param()  # Va chercher la legislation par défaut

    df = simulation.get_results_dataframe()

    print df.to_string()

    print simulation.input_table.table.to_string()
    print simulation.output_table.table.to_string()
def get_couple_without_child_results_datatframe(sali_vous=0,
                                                sali_conj=0,
                                                pension_alimentaire=0):
    simulation = ScenarioSimulation()
    simulation.set_config(year=2013, nmen=1)

    # Adding a husband/wife on the same tax sheet (ie foyer, as conj) and of course same family (as part)
    simulation.scenario.addIndiv(1, datetime.date(1975, 1, 1), 'conj', 'part')

    # Changing the revenu of the parents
    scenario = simulation.scenario
    scenario.indiv[0]['sali'] = sali_vous
    scenario.indiv[1]['sali'] = sali_conj

    # Set the number of major kids in the
    scenario.declar[0]['f6gi'] = pension_alimentaire

    # Set legislative parameters
    simulation.set_param()

    # Compute the pandas dataframe of the household case_study
    df = simulation.get_results_dataframe()
    return df
def run_simulation(apply_reform=False,
                   reforme=False,
                   conj=False,
                   kids=0,
                   sal_conj=False,
                   year=2011):

    simulation = ScenarioSimulation()
    simulation.set_config(year=year,
                          nmen=1001,
                          x_axis='salaire_imposable',
                          maxrev=10000,
                          reforme=reforme,
                          mode='bareme',
                          same_rev_couple=False)
    simulation.set_param()

    if sal_conj:
        conj = True

    if conj:
        simulation.scenario.addIndiv(1, datetime.date(1975, 1, 1), 'vous',
                                     'part')
        if sal_conj:
            simulation.scenario.indiv[1].update({
                'salaire_imposable':
                simulation.P.cotisations_sociales.gen.smig
            })

        if kids > 0:
            for n in range(1, kids + 1):
                simulation.scenario.addIndiv(n + 1, datetime.date(2000, 1, 1),
                                             'pac', 'enf')

    print simulation.scenario
    if apply_reform:
        simulation.P.impot_revenu.reforme.exemption.active = 1
        simulation.P.cotisations_sociales.gen.smig = 320
        simulation.P_default.cotisations_sociales.gen.smig = 320

    return simulation
Beispiel #57
0
def modify_parameters(simulation=None):

    if simulation is None:
        simulation = ScenarioSimulation()
        simulation.set_config(year=2013)
        simulation.set_param()

    for _P in [simulation.P, simulation.P_default]:

        sal = build_sal(_P)
        pat = build_pat(_P)

        _P.cotsoc.__dict__['cotisations_patronales'] = CompactNode()
        _P.cotsoc.__dict__['cotisations_salariales'] = CompactNode()

        for cotisation_name, bareme_dict in {
                'cotisations_patronales': pat,
                'cotisations_salariales': sal
        }.iteritems():
            for category in bareme_dict:
                if category in CAT._nums:
                    _P.cotsoc.__dict__[cotisation_name].__dict__[
                        category] = bareme_dict[category]