退休计划的人口预测。

pop-projection的Python项目详细描述


弹出投影

退休计划的人口预测,包括:

  • 员工(在职和退休人员)
  • 他们的配偶
  • 他们的孩子们

考虑到第0年年末的此类人口,我们计算出,在接下来的每一年(第1年、第2年、…、第100年,以及在该年年末),幸存、死亡并退出公司(仅限在职人员)和退休(仅限在职人员)的人数。除此之外,新的配偶,新的孩子,和新的活跃分子也产生使用给定的法律。

这些运动的规律是:

  • 死亡率定律(死亡率表)
  • 退出法则
  • 退休定律(事实上这条定律是确定的:在某个年龄退休,例如60岁)
  • 婚姻法
  • 出生法则
  • 置换定律

这些定律(替换定律除外)作为函数或两个元素的元组传递,第一个是函数,第二个是参数列表。这些参数的名称必须存在于数据文件的雇员、配偶或儿童的列的列表中(取决于法律)。见下文)。 如果该法律仅作为函数传递,则函数的签名中使用的参数的名称必须存在于数据文件的雇员、配偶或儿童的列的列表中(取决于法律)。见下文)。

替代法则作为功能被传递。

定律参数

  • 退出法则-->;参数名称在员工列列表中。
  • 退休法则-->;参数名称在员工列的列表中。
  • 婚姻法-->;参数名称在员工列的列表中。
  • 出生法则-->;参数名称在配偶列的列表中。
  • 置换定律有两个参数:
    • 一个DIC,按组存储每年的离职人数(年内退休、辞职或死亡的员工)
    • 出发年份

返回法律值

  • 辞职法则-->;员工在下一年年底前辞职的可能性。
  • 退休法-->;1如果员工将在下一年年底前退休,则为0。
  • 婚姻法-->;员工明年年底前结婚的可能性。
  • 出生法则-->;配偶(如果是女性)或其妻子在下一年年底前分娩的可能性。
  • 替换法则-->;要添加到人口中的员工列表。此列表中的每个员工都是一个DIC,具有关键字:“key”(用于唯一定义员工)、“number”和“data”(与除ID之外的员工列相对应的值列表)。

安装

pip install pop-projection

用法示例

import pop_projection.Effectifs as eff
import pop_projection.Actuariat as act
import pandas as pd

# Define law of retirement
def law_ret1(age, Year_employment):
    if Year_employment < 2002:
        if age+1 >= 55:
            return True
        else:
            return False
    if Year_employment >= 2002:
        if age+1 >= 60:
            return True
        else:
            return False

# Define law of reignation
def law_resignation_1(age, sex):
    if age+1 >= 50 :
        return 0
    if sex == 'female':
        if age+1 <= 30:
            return 0.02
        else:
            return 0.01
    if sex == 'male':
        if age+1 <= 30:
            return 0.02
        else:
            return 0.01



# Define law of marriage
def law_mar1(age, sexe, typeAgent):
    """
    Return the probability of getting maried  during the following year at a given age for a given sex

    """
    if sexe == 'male':
        if typeAgent=='active':
            if age >= 25 and age <= 54:
                return 0.095
            else :
                return 0
        else:
            return 0

    if sexe == 'female':
        if typeAgent=='active':
            if age >= 25 and age <= 54:
                return 0.15
            else :
                return 0
        else:
            return 0


# Define law of replacement   
def law_replacement1(departures_, year_):

    '''
        assumes departures_ is a dic storing number of departures by group of the year year_
        returns a list of dics having keys : key, number and data

    '''
    def nouveaux(g_):
        structure_nouveaux = {'1':[25,25,0.8],'2':[25,25,0.8],'3':[25,25,0.6],'4':[29,29,0.6],'5':[28,28,0.5,],
        '6':[28,28,0.5],'7':[33,33,0.5],'8':[38,38,0.5],'9':[38,38,0.5],'10':[47,47,0.5],'11':[49,49,0.5]}

        if str(g_) in structure_nouveaux:
            return structure_nouveaux[str(g_)]
        else:
            return [30, 30, 1.0]

    def taux_rempl(y, g_ = '0'):
        if y <= 3 :
            if str(g_) in ['1','2','3','5','6','7']:
                return 0.64
            else:
                return 1
        else:
            return 1

    new_employees = []

    for g in departures_:
        # add a male
        if nouveaux(g)[2] > 0:
            temp = {'key':'male_groupe_' + str(g) + 'year_' + str(year_), 
            'number':nouveaux(g)[2]*departures_[g]*taux_rempl(year_, g),'data':['active', 'male', 'not married', nouveaux(g)[0], year_,g,'01/01/'+str((2018+year_+1)),'31/12/'+str((2018+year_-nouveaux(g)[0]))]}
            new_employees.append(temp)

        # add a female
        if nouveaux(g)[2] < 1:
            temp = {'key':'female_groupe_' + str(g) + 'year_' + str(year_), 
            'number':(1-nouveaux(g)[2])*departures_[g]*taux_rempl(year_, g),'data':['active', 'female', 'not married', nouveaux(g)[1], year_,g,'01/01/'+str((2018+year_+1)),'31/12/'+str((2018+year_-nouveaux(g)[1]))]}
            new_employees.append(temp)

    return new_employees

# Path for input data
path ="./pop_projection/data/"

# Number of years to project
MAX_YEARS = 50

# Loading data
employees = pd.read_csv(path + "employees.csv",sep=";", decimal = ",")
spouses = pd.read_csv(path + "spouses.csv",sep=";", decimal = ",")
children = pd.read_csv(path + "children.csv",sep=";", decimal = ",")

# View existing mortality tables
print('Mortality tables : \n',list(act.mortality_tables.keys()))

# Add the 2009 usa table
table_usa_2009 = pd.read_csv("table_usa_2009.csv",sep=";", decimal = ",")
act.add_mortality_table('table_usa_2009', list(table_usa_2009['Lx']))

# Projection of population
numbers_ = eff.simulerEffectif(employees, spouses, children, 'table_usa_2009', MAX_YEARS, 
            law_retirement_= law_ret1, law_resignation_= law_resignation_1, 
            law_marriage_= (law_mar1, ['age', 'sex', 'type']), law_replacement_= law_replacement1)

# Global numbers
Effectifs = eff.globalNumbers(numbers_[0], numbers_[1], numbers_[2], MAX_YEARS)

# Print some lines
print(Effectifs.head(10))

# Export Effectifs
Effectifs.to_csv('Effectifs_python.csv', sep = ';', index=False, decimal=',')

#Number of actives leaving population : deaths, resignations, and new retired
Leaving = eff.leavingNumbers(numbers_[0], numbers_[4], MAX_YEARS)

#Print some lines
print(Leaving.head(10))

#Export Leaving
Leaving.to_csv('Sortants_python.csv', sep = ';', index=False, decimal=',')

#export projected employees
pd.DataFrame.from_dict(numbers_[0]).to_csv('employees_proj.csv', sep = ';', index=False, decimal=',')

#export projected spouses
pd.DataFrame.from_dict(numbers_[1]).to_csv('spouses_proj.csv', sep = ';', index=False, decimal=',')

#export projected children
pd.DataFrame.from_dict(numbers_[2]).to_csv('children_proj.csv', sep = ';', index=False, decimal=',')

其他示例:

Plotting Evolution of Ages pyramid over years

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java为什么hashmap对整数值求和   使用copyFromRealm发送副本时,从错误线程访问java领域异常   java NDK支持是一个实验性的特性,所有用例都还不支持。Android Studio中的错误?   Java从resultSet生成查询并执行新查询   youtube如何使用Java+Google数据API测量上传比特率   如何从Java调用Xtend代码?   在java中,如何清除每个方法中的字节[]数组以保护值不被内存转储?   java UTF8编码与Base64编码   (与java inorder一起提供的反应式处理和反应式反应器:MWIO.3)   带toString的java Building 9x9   java如何在GridLayout中根据手机屏幕对齐按钮?   将字符串值解析为整数时出现java错误   java activeMQ接收器倒带丢失?   jfree图表中范围标记标签的java包装文本   java Android播放列表查询不准确。。。?   当请求中的头{“Accept”:“application/octetstream”}出现错误时,java返回JSON   javanet。ucanaccess。jdbc。UcanaccessSQLException   java Hibernate注释用于自动增量,但如果在保存之前设置了值,则还应保存该值