Skip to content

Commit

Permalink
Fix cnrps
Browse files Browse the repository at this point in the history
  • Loading branch information
benjello committed Nov 18, 2024
1 parent 8cf9292 commit 49d7c5c
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 78 deletions.
100 changes: 100 additions & 0 deletions openfisca_tunisia_pension/regimes/cnrps.py
Original file line number Diff line number Diff line change
@@ -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
78 changes: 0 additions & 78 deletions openfisca_tunisia_pension/variables/cnrps.py

This file was deleted.

0 comments on commit 49d7c5c

Please sign in to comment.