diff --git a/openfisca_tunisia_pension/regimes/cnrps.py b/openfisca_tunisia_pension/regimes/cnrps.py new file mode 100644 index 0000000..47cc34e --- /dev/null +++ b/openfisca_tunisia_pension/regimes/cnrps.py @@ -0,0 +1,100 @@ +'''Régime de la Caisse nationale de retraite et de prévoyance sociale (CNRPS).''' + + +from openfisca_core.model_api import * + + +from openfisca_tunisia_pension.entities import Individu +from openfisca_tunisia_pension.regimes.regime import AbstractRegimeEnAnnuites + + +import functools +from numpy import ( + apply_along_axis, + logical_not as not_, + maximum as max_, + vstack, + ) + +from openfisca_tunisia_pension.variables.helpers import mean_over_k_largest, pension_generique + + +class RegimeCNRPS(AbstractRegimeEnAnnuites): + name = 'Régime des salariés non agricoles' + variable_prefix = 'cnrps' + parameters_prefix = 'cnrps' + + class salaire_reference(Variable): + value_type = float + entity = Individu + label = 'Salaires de référence du régime de la CNRPS' + definition_period = YEAR + + def formula(individu, period): + '''3 dernières rémunérations ou les 2 plus élevées sur demande.''' + n = 40 + k = 2 + mean_over_largest = functools.partial(mean_over_k_largest, k = k) + moyenne_2_salaires_plus_eleves = apply_along_axis( + mean_over_largest, + axis = 0, + arr = vstack([ + individu('regime_name_salaire_de_base', period = year) + for year in range(period.start.year, period.start.year - n, -1) + ]), + ) + p = 3 + moyenne_3_derniers_salaires = sum( + individu('regime_name_salaire_de_base', period = year) + for year in range(period.start.year, period.start.year - p, -1) + ) / p + + salaire_refererence = max_( + moyenne_3_derniers_salaires, + moyenne_2_salaires_plus_eleves + ) + return salaire_refererence + + class pension(Variable): + value_type = float + entity = Individu + label = 'Pension des affiliés au régime des salariés non agricoles' + definition_period = YEAR + + def formula(individu, period, parameters): + duree_assurance = individu('regime_name_duree_assurance', period = period) + salaire_reference = individu('regime_name_salaire_reference', period = period) + age = individu('age', period = period) + + cnrps = parameters(period).retraite.regime_name + taux_annuite_base = cnrps.taux_annuite_base + taux_annuite_supplementaire = cnrps.taux_annuite_supplementaire + duree_stage = cnrps.stage_derog + age_eligible = cnrps.age_dep_anticip + periode_remplacement_base = cnrps.periode_remplacement_base + plaf_taux_pension = cnrps.plaf_taux_pension + smig = parameters(period).marche_travail.smig_48h + + pension_min_sup = cnrps.pension_minimale.sup + pension_min_inf = cnrps.pension_minimale.inf + + stage = duree_assurance > 4 * duree_stage + pension_minimale = ( + stage * pension_min_sup + not_(stage) * pension_min_inf + ) + montant = pension_generique( + duree_assurance, + salaire_reference, + taux_annuite_base, + taux_annuite_supplementaire, + duree_stage, + age_eligible, + periode_remplacement_base, + plaf_taux_pension, + ) + # eligibilite + eligibilite_age = age > age_eligible + eligibilite = stage * eligibilite_age * (salaire_reference > 0) + # plafonnement + montant_pension_percu = max_(montant, pension_minimale * smig) + return eligibilite * montant_pension_percu diff --git a/openfisca_tunisia_pension/variables/cnrps.py b/openfisca_tunisia_pension/variables/cnrps.py deleted file mode 100644 index dec0cc0..0000000 --- a/openfisca_tunisia_pension/variables/cnrps.py +++ /dev/null @@ -1,78 +0,0 @@ -import functools -from numpy import ( - apply_along_axis, - logical_not as not_, - maximum as max_, - vstack, - ) - -from openfisca_core.model_api import * -from openfisca_tunisia_pension.entities import Individu -from openfisca_tunisia_pension.variables.helpers import mean_over_k_largest, pension_generique - - -class cnrps_salaire_reference(Variable): - value_type = float - entity = Individu - label = 'Salaire de référence de la CNRPS' - definition_period = YEAR - - def formula(individu, period): - # TODO: gérer le nombre d'année n - # TODO: plafonner les salaires à 6 fois le smig de l'année d'encaissement - n = 10 - mean_over_largest = functools.partial(mean_over_k_largest, k = n) - salaire_refererence = apply_along_axis( - mean_over_largest, - axis = 0, - arr = vstack([ - individu('salaire', period = year) - for year in range(period.start.year, period.start.year - n, -1) - ]), - ) - return salaire_refererence - - -class cnrps_pension(Variable): - value_type = float - entity = Individu - label = 'Pension des affiliés au régime des salariés non agricoles' - definition_period = YEAR - - def formula(individu, period, parameters): - duree_assurance = individu('duree_assurance', period = period) - salaire_reference = individu('rsna_salaire_reference', period = period) - age = individu('age', period = period) - - rsna = parameters(period).retraite.rsna - taux_annuite_base = rsna.taux_annuite_base - taux_annuite_supplementaire = rsna.taux_annuite_supplementaire - duree_stage = rsna.stage_derog - age_eligible = rsna.age_dep_anticip - periode_remplacement_base = rsna.periode_remplacement_base - plaf_taux_pension = rsna.plaf_taux_pension - smig = parameters(period).marche_travail.smig_48h - - pension_min_sup = rsna.pension_minimale.sup - pension_min_inf = rsna.pension_minimale.inf - - stage = duree_assurance > 4 * duree_stage - pension_minimale = ( - stage * pension_min_sup + not_(stage) * pension_min_inf - ) - montant = pension_generique( - duree_assurance, - salaire_reference, - taux_annuite_base, - taux_annuite_supplementaire, - duree_stage, - age_eligible, - periode_remplacement_base, - plaf_taux_pension, - ) - # eligibilite - eligibilite_age = age > age_eligible - eligibilite = stage * eligibilite_age * (salaire_reference > 0) - # plafonnement - montant_pension_percu = max_(montant, pension_minimale * smig) - return eligibilite * montant_pension_percu