Example #1
0
 def data_avpf(self, data):
     # TODO: move to an other place in set_config or in PensionData
     data_avpf = PensionData(data.workstate, data.sali, data.info_ind)
     data_avpf.sali = imput_sali_avpf(data_avpf, code_avpf, self.P_longit)
     if compare_destinie:
         smic_long = self.P_longit.common.smic_proj
         year_avpf = (data_avpf.workstate != 0)
         data_avpf.sali = multiply(year_avpf, smic_long)
     return data_avpf
Example #2
0
def load_pensipp_data(pensipp_path,
                      yearsim,
                      first_year_sal,
                      selection_id=False):
    try:
        info, info_child, salaire, statut = load_from_csv(
            pensipp_comparison_path)
    except:
        print(" Les données sont chargées à partir du Rdata et non du csv")
        info, info_child, salaire, statut = load_from_Rdata(
            pensipp_comparison_path, to_csv=True)
    if max(info.loc[:, 'sexe']) == 2:
        info.loc[:, 'sexe'] = info.loc[:, 'sexe'].replace(1, 0)
        info.loc[:, 'sexe'] = info.loc[:, 'sexe'].replace(2, 1)
    info.loc[:, 'agem'] = (yearsim - info['t_naiss']) * 12
    info.drop('t_naiss', axis=1, inplace=True)
    select_id_depart = (info.loc[:, 'agem'] == 12 * 63)
    id_selected = select_id_depart[select_id_depart == True].index
    if selection_id:
        id_selected = selection_id
    ix_selected = [int(ident) - 1 for ident in id_selected]
    sali = salaire.iloc[ix_selected, :]
    workstate = statut.iloc[ix_selected, :]
    info_child_ = _child_by_age(info_child, yearsim, id_selected)
    nb_pac = count_enf_pac(info_child_, info.index)
    info_ind = info.iloc[ix_selected, :]
    info_ind.loc[:, 'nb_pac'] = nb_pac
    data = PensionData.from_arrays(workstate, sali, info_ind)
    data_bounded = data.selected_dates(first=first_year_sal, last=yearsim)
    # TODO: commun declaration for codes and names regimes : Déclaration inapte (mais adapté à Taxipp)
    array_enf = count_enf_by_year(data_bounded.workstate, info_ind, info_child)
    dict_regime = {
        'FP': [5, 6],
        'RG': [3, 4, 1, 2, 9, 8, 0],
        'RSI': [7]
    }  #On met les inactifs/chomeurs/avpf ou préretraité au RG
    # ajoute les variables d'enfants pour info_ind
    rec = data_bounded.info_ind
    newdtype = [('nb_enf_' + name, '<i8')
                for name in dict_regime] + [('nb_enf_all', '<i8')]
    newdtype = np.dtype(rec.dtype.descr + newdtype)
    print newdtype
    info_ind = np.empty(rec.shape, dtype=newdtype)
    for field in rec.dtype.fields:
        info_ind[field] = rec[field]
    # rempli les colonnes nb_enf
    for name_reg, code_reg in dict_regime.iteritems():
        nb_enf_regime = (array_enf *
                         data_bounded.workstate.isin(code_reg)).sum(axis=1)
        info_ind['nb_enf_' + name_reg] = nb_enf_regime
        info_ind['nb_enf_all'] += nb_enf_regime


#         data_bounded.info_ind['nb_enf_' + name_reg] = nb_enf_regime
#         nb_enf_all += nb_enf_regime
#     info_ind.loc[:,'nb_enf'] = nb_enf_all
#print sum(nb_enf_all -  info_ind.loc[:,'nb_born'])
#print info_ind.loc[15478, ['nb_born', 'nb_enf', 'nb_enf_RG', 'nb_enf_FP', 'nb_enf_RSI']]
    data_bounded.info_ind = info_ind
    return data_bounded
Example #3
0
def run_pension(context, yearleg, time_step='year', to_check=False, output='pension', cProfile=False):
    ''' run PensionSimulation after having converted the liam context in a PenionData
        - note there is a selection '''
    sali = context['longitudinal']['sali']
    workstate = context['longitudinal']['workstate']
    # calcul de la date de naissance au bon format
    datesim = context['period']
    age_year = context['agem'] // 12
    age_month = context['agem'] % 12 + 1
    naiss_year = datesim // 100 - age_year
    naiss_month = datesim % 100 - age_month + 1
    naiss = pd.Series(naiss_year * 100 + naiss_month)
    naiss = naiss.map(lambda t: dt.date(t // 100, t % 100, 1))

    info_ind = pd.DataFrame({'index':context['id'], 'agem': context['agem'],'naiss': naiss, 'sexe' : context['sexe'],
                              'nb_enf_all': context['nb_enf'], 'nb_pac': context['nb_pac'], 'nb_enf_RG': context['nb_enf_RG'],
                              'nb_enf_RSI': context['nb_enf_RSI'], 'nb_enf_FP': context['nb_enf_FP'], 'tauxprime': context['tauxprime']})
    info_ind = info_ind.to_records(index=False)
    # TODO: filter should be done in liam
    if output == 'dates_taux_plein':
        # But: déterminer les personnes partant à la retraite avec préselection des plus de 55 ans
        #TODO: faire la préselection dans Liam
        info_ind = info_ind[(info_ind['agem'] > 55 * 12)]

    if output == 'pension':
        info_ind = info_ind[context['to_be_retired']] #TODO: filter should be done in yaml

    workstate = workstate.loc[workstate['id'].isin(info_ind.index), :].copy()
    workstate.set_index('id', inplace=True)
    workstate.sort_index(inplace=True)
    sali = sali.loc[sali['id'].isin(info_ind.index), :].copy()
    sali.set_index('id', inplace=True)
    sali.sort_index(inplace=True)
    sali.fillna(0, inplace=True)
    yearleg = context['period'] // 100
    if yearleg > 2009: #TODO: remove
        yearleg = 2009
    data = PensionData.from_arrays(workstate, sali, info_ind)
    param = PensionParam(yearleg, data)
    legislation = PensionLegislation(param)
    simul_til = PensionSimulation(data, legislation)
    if cProfile:
        result_til_year = simul_til.profile_evaluate(yearleg, to_check=to_check, output=output)
    else:
        result_til_year = simul_til.evaluate(yearleg, to_check=to_check, output=output)
    if output == 'dates_taux_plein':
        # Renvoie un dictionnaire donnant la date de taux plein par régime (format numpy) et l'index associé
        return result_til_year
    elif output == 'pension':
        result_to_liam = output_til_to_liam(output_til=result_til_year,
                                            index_til=info_ind.index,
                                            context_id=context['id'])
        return result_to_liam.astype(float)
Example #4
0
def load_pensipp_data(pensipp_path, yearsim, first_year_sal, selection_id=False):
    try:
        info, info_child, salaire, statut = load_from_csv(pensipp_comparison_path)
    except:
        print (" Les données sont chargées à partir du Rdata et non du csv")
        info, info_child, salaire, statut = load_from_Rdata(pensipp_comparison_path, to_csv=True)
    if max(info.loc[:, "sexe"]) == 2:
        info.loc[:, "sexe"] = info.loc[:, "sexe"].replace(1, 0)
        info.loc[:, "sexe"] = info.loc[:, "sexe"].replace(2, 1)
    info.loc[:, "agem"] = (yearsim - info["t_naiss"]) * 12
    info.drop("t_naiss", axis=1, inplace=True)
    select_id_depart = info.loc[:, "agem"] == 12 * 63
    id_selected = select_id_depart[select_id_depart == True].index
    if selection_id:
        id_selected = selection_id
    ix_selected = [int(ident) - 1 for ident in id_selected]
    sali = salaire.iloc[ix_selected, :]
    workstate = statut.iloc[ix_selected, :]
    info_child_ = _child_by_age(info_child, yearsim, id_selected)
    nb_pac = count_enf_pac(info_child_, info.index)
    info_ind = info.iloc[ix_selected, :]
    info_ind.loc[:, "nb_pac"] = nb_pac
    data = PensionData.from_arrays(workstate, sali, info_ind)
    data_bounded = data.selected_dates(first=first_year_sal, last=yearsim)
    # TODO: commun declaration for codes and names regimes : Déclaration inapte (mais adapté à Taxipp)
    array_enf = count_enf_by_year(data_bounded.workstate, info_ind, info_child)
    dict_regime = {
        "FP": [5, 6],
        "RG": [3, 4, 1, 2, 9, 8, 0],
        "RSI": [7],
    }  # On met les inactifs/chomeurs/avpf ou préretraité au RG
    # ajoute les variables d'enfants pour info_ind
    rec = data_bounded.info_ind
    newdtype = [("nb_enf_" + name, "<i8") for name in dict_regime] + [("nb_enf_all", "<i8")]
    newdtype = np.dtype(rec.dtype.descr + newdtype)
    print newdtype
    info_ind = np.empty(rec.shape, dtype=newdtype)
    for field in rec.dtype.fields:
        info_ind[field] = rec[field]
    # rempli les colonnes nb_enf
    for name_reg, code_reg in dict_regime.iteritems():
        nb_enf_regime = (array_enf * data_bounded.workstate.isin(code_reg)).sum(axis=1)
        info_ind["nb_enf_" + name_reg] = nb_enf_regime
        info_ind["nb_enf_all"] += nb_enf_regime
    #         data_bounded.info_ind['nb_enf_' + name_reg] = nb_enf_regime
    #         nb_enf_all += nb_enf_regime
    #     info_ind.loc[:,'nb_enf'] = nb_enf_all
    # print sum(nb_enf_all -  info_ind.loc[:,'nb_born'])
    # print info_ind.loc[15478, ['nb_born', 'nb_enf', 'nb_enf_RG', 'nb_enf_FP', 'nb_enf_RSI']]
    data_bounded.info_ind = info_ind
    return data_bounded
Example #5
0
def get_pension(context, yearleg):
    """ return a PensionSimulation """
    sali = context["longitudinal"]["sali"]
    workstate = context["longitudinal"]["workstate"]
    # calcul de la date de naissance au bon format
    datesim = context["period"]
    datesim_in_month = 12 * (datesim // 100) + datesim % 100
    datenaiss_in_month = datesim_in_month - context["agem"]
    naiss = 100 * (datenaiss_in_month // 12) + datenaiss_in_month % 12 + 1
    naiss = pd.Series(naiss)
    naiss = pd.Series(naiss).map(lambda t: dt.date(t // 100, t % 100, 1))

    info_ind = pd.DataFrame(
        {
            "index": context["id"],
            "agem": context["agem"],
            "naiss": naiss,
            "sexe": context["sexe"],
            "nb_enf_all": context["nb_enf"],
            "nb_pac": context["nb_pac"],
            "nb_enf_RG": context["nb_enf_RG"],
            "nb_enf_RSI": context["nb_enf_RSI"],
            "nb_enf_FP": context["nb_enf_FP"],
            "tauxprime": context["tauxprime"],
        }
    )
    info_ind = info_ind.to_records(index=False)

    workstate = workstate.loc[workstate["id"].isin(info_ind.index), :].copy()
    workstate.set_index("id", inplace=True)
    workstate.sort_index(inplace=True)
    sali = sali.loc[sali["id"].isin(info_ind.index), :].copy()
    sali.set_index("id", inplace=True)
    sali.sort_index(inplace=True)
    sali.fillna(0, inplace=True)

    data = PensionData.from_arrays(workstate, sali, info_ind)
    param = PensionParam(yearleg, data)
    legislation = PensionLegislation(param)
    simulation = PensionSimulation(data, legislation)
    simulation.set_config()
    return simulation
Example #6
0
    sexe = data['sexi'][0] == 2
    nb_enf = data['nbenf'][0]
    return workstate, sali, sexe, nb_enf


agem = (2009-1954 + 0.5)*12
naiss = dt.date(1954, 6, 1)
info_ind['agem'] = agem
info_ind['naiss'] = naiss
info_ind['tauxprime'] = 0
for i in range(nb_scenarios):
    work_i, sali_i, sexe, nb_enf = load_case(i+1) # Attention déclage dans la numérotaiton qui ne commence pas à zeros
    sali[i,:] = sali_i
    workstate[i,:] = work_i
    info_ind.loc[i,['sexe','nb_enf','nb_pac',
                    'nb_enf_RG','nb_enf_RSI','nb_enf_FP']] = [sexe, nb_enf, nb_enf,
                                                                           nb_enf, nb_enf, nb_enf]

#TODO: know why nbenf is often NaN and not 0.
info_ind.fillna(0, inplace=True)
data = PensionData.from_arrays(workstate, sali, info_ind, dates)

param = PensionParam(201001, data)
legislation = PensionLegislation(param)
simulation = PensionSimulation(data, legislation)
trim = simulation.profile_evaluate(output='trimesters_wages')
result_til_year = simulation.profile_evaluate(to_check=True)

pdb.set_trace()