def create_udd_multidecrement_table(self):
        lst_w = [t.w for t in self.unidecrement_tables.values()]
        max_w = max(lst_w)
        for k_t, t in self.unidecrement_tables.items():
            copy_tables = self.unidecrement_tables.copy()
            del copy_tables[k_t]
            qx = []
            for i_q, q in enumerate(t.qx):
                factor_to_apply = 1
                for k_t2, t2 in copy_tables.items():
                    factor_to_apply *= (1 -
                                        .5 * t2.tqx(i_q, t=1, method='udd'))
                qx.append(q * factor_to_apply)
            # append the first age to the vector of qx
            qx = [0] + qx
            # prepare the table with the probabilities, considering the value of qw=1 or qw=0
            self.multidecrement_tables[k_t] = mt.MortalityTable(
                mt=qx, last_q=t.last_q)

        # compute the net table, that is the multidecrement qx's and all the remaining fields in a mortality table
        qx = []
        for x in range(max_w + 1):
            q = 0
            for k_t, t in self.multidecrement_tables.items():
                q += t.tqx(x=x, t=1, method='udd')
            qx.append(q)

        # append the first age to the vector of qx
        qx = [0] + qx
        self.net_table = mt.MortalityTable(mt=qx, last_q=1)
Beispiel #2
0
__author__ = "PedroCR"

import pytest

from essential_life import mortality_table as mt, mortality_table, commutation_table, annuities
from soa_tables import read_soa_table_xml as rst
from toDelete.mortality_tables_old import TV7377, GRF95

lt_tv7377 = mortality_table.MortalityTable(mt=TV7377)
lt_grf95 = mortality_table.MortalityTable(mt=GRF95)

soa_TV7377 = rst.SoaTable('../../soa_tables/TV7377.xml')
soa_GRF95 = rst.SoaTable('../../soa_tables/GRF95.xml')
mt_GRF95 = mt.MortalityTable(mt=soa_GRF95.table_qx)
mt_TV7377 = mt.MortalityTable(mt=soa_TV7377.table_qx)


def test_ax():
    i = 2
    g = 1
    m = 1
    x = 45
    method = 'udd'
    cf_grf95 = commutation_table.CommutationFunctions(i=i,
                                                      g=g,
                                                      mt=soa_GRF95.table_qx)
    cf_tv7377 = commutation_table.CommutationFunctions(i=i,
                                                       g=g,
                                                       mt=soa_TV7377.table_qx)

    a_grf = annuities.ax(mt=mt_GRF95, x=x, i=i, g=g, m=m, method=method)
import matplotlib.pyplot as plt
import os
import sys

this_py = os.path.split(sys.argv[0])[-1][:-3]
mml = makeham_mortality_functions.Makeham(a=0.00022, b=2.7E-6, c=1.124)

t = np.linspace(0, 100, 1000 + 1)
x_s = [0, 20, 50, 80]
'''
Compute Life Table and commutation table
'''
interest_rate = 5
px = np.array([mml.S(x, t=1) for x in range(0, 130 + 1)])
qx = 1 - px
lt = mortality_table.MortalityTable(mt=list(np.append(0, qx)))
lt.df_life_table().to_excel(excel_writer='makeham' + '.xlsx',
                            sheet_name='makeham',
                            index=False,
                            freeze_panes=(1, 1))
ct = commutation_table.CommutationFunctions(i=interest_rate,
                                            g=0,
                                            mt=list(np.append(0, qx)))
ct.df_commutation_table().to_excel(excel_writer='makeham' + '_comm' + '.xlsx',
                                   sheet_name='makeham',
                                   index=False,
                                   freeze_panes=(1, 1))
'''
annuities
'''
Beispiel #4
0
__author__ = "PedroCR"

from essential_life import mortality_table as mt, annuities
from soa_tables import read_soa_table_xml as rst

soa_TV7377 = rst.SoaTable('../soa_tables/TV7377.xml')
soa_GRF95 = rst.SoaTable('../soa_tables/GRF95.xml')
mt_GRF95 = mt.MortalityTable(mt=soa_GRF95.table_qx)
mt_TV7377 = mt.MortalityTable(mt=soa_TV7377.table_qx)

a1 = annuities.ax(mt=mt_GRF95, x=45, i=2, g=0, m=1)
a2 = annuities.aax(mt=mt_GRF95, x=45, i=2, g=0, m=1)
print(a1)
print(a2)
Beispiel #5
0
from soa_tables import read_soa_table_xml as rst
from essential_life import mortality_table, commutation_table

this_py = os.path.split(sys.argv[0])[-1][:-3]


def parse_table_name(name):
    return name.replace(' ', '').replace('/', '')


table_names = ['TV7377', 'GRF95', 'GRM95']
interest_rate = 6
mt_lst = [
    rst.SoaTable('../../soa_tables/' + name + '.xml') for name in table_names
]
lt_lst = [mortality_table.MortalityTable(mt=mt.table_qx) for mt in mt_lst]
ct_lst = [
    commutation_table.CommutationFunctions(i=interest_rate,
                                           g=0,
                                           mt=mt.table_qx) for mt in mt_lst
]
ages = np.linspace(start=20, stop=40, num=5, dtype=int)
'''
Prepare the solution for Equal Instalments
'''
capital = 100000
terms = 25
ac = annuities_certain.Annuities_Certain(interest_rate=interest_rate,
                                         frequency=1)
ac_certain = ac.annuity_immediate(terms=terms)
equal_instalments_dict = {
import pandas as pd

from soa_tables import read_soa_table_xml as rst
from essential_life import mortality_table, commutation_table
import matplotlib.pyplot as plt

table_names = ['TV7377', 'GRF95', 'GRM95']
interest_rate = 4
name = table_names[0]
mt = rst.SoaTable('../../soa_tables/' + name + '.xml')
lt = mortality_table.MortalityTable(mt=mt.table_qx)
ct = commutation_table.CommutationFunctions(i=interest_rate,
                                            g=0,
                                            mt=mt.table_qx)

lx = 1000
frequency = 1
first_instalment_at = 5
number_of_instalments = 1000
premium_instalments = 5
instalment = 10000
dict_annuity = {'x': 50, 'n': 1000, 'm': 1, 'defer': first_instalment_at}
renda_premium = ct.naax(x=dict_annuity['x'], n=premium_instalments)
full_liability = ct.t_naax(x=dict_annuity['x'], n=dict_annuity['n'], m=dict_annuity['m'], defer=dict_annuity['defer']) * \
                 instalment * lx
premium1 = full_liability / lx / renda_premium

i = interest_rate / 100
dict_liability = {
    't': [],
    'x': [],
Beispiel #7
0
from soa_tables import read_soa_table_xml as rst
from disability_tables import disability_tables as dt
from turnover_tables import turnover_tables as tt
from essential_life import mortality_table as mt, age
from essential_life.multidecrement_table import MultiDecrementTable as mdt
from present_value_future_term_cost import pvftc
from matplotlib import pyplot as plt

soa_TV7377 = rst.SoaTable('../soa_tables/TV7377.xml')
soa_GRF95 = rst.SoaTable('../soa_tables/GRF95.xml')
ekv80 = dt.EVK_80
ekv80_70 = dt.EVK_80_ext_70
pcr1 = tt.pcr_turnover
pcr2 = tt.pcr_turnover_65

mt_GRF95 = mt.MortalityTable(mt=soa_GRF95.table_qx)
mt_TV7377 = mt.MortalityTable(mt=soa_TV7377.table_qx)
dt_ekv80 = mt.MortalityTable(mt=ekv80, last_q=0)
tt_pcr = mt.MortalityTable(mt=pcr1, last_q=0)

tables_unidecrement = {'mortality': mt_TV7377, 'disability': dt_ekv80, 'turnover': tt_pcr}

tables_multidecrement = mdt(dict_tables=tables_unidecrement)
tables_multidecrement.create_udd_multidecrement_table()

dict_dates = {'date_of_birth': '1977-03-12', 'date_of_entry': '1997-05-15'}
date_of_valuation = '2019-12-31'

dates_for_term_cost = age.Age(date1=dict_dates['date_of_birth'], date2=dict_dates['date_of_birth']).date_inc_years(55)
age_term_cost_years = dates_for_term_cost.age_act()
pvfb_d = pvftc.PVTermCost(date_of_valuation=date_of_valuation, date_of_birth=dict_dates['date_of_birth'],
this_py = os.path.split(sys.argv[0])[-1][:-3]


def parse_table_name(name):
    return name.replace(' ', '').replace('/', '')


dif_age = 3
l0 = 100000

table_names = ['TV7377', 'GRF95', 'GRM95']
mt_lst = [
    rst.SoaTable('../../../soa_tables/' + name + '.xml')
    for name in table_names
]
lt_lst = [mortality_table.MortalityTable(mt=mt.table_qx) for mt in mt_lst]

lt_q_min_xy = []
lt_q_max_xy = []

table_names_min_max = []
for idx_lt, lt in enumerate(lt_lst):
    l = [
        1 - lt.tpx(x=x, t=1) * lt.tpx(x=x + dif_age, t=1)
        for x in range(lt.w - dif_age + 1)
    ]
    l.insert(0, 0)
    lt_q_min_xy.append(l)
    table_names_min_max.append(table_names[idx_lt] + ' joint life xy')
    l = [
        lt.tqx(x=x, t=1) * lt.tqx(x=x + dif_age, t=1)
    np.array(t.table_qx[1:]) / (1 - np.array(t.table_qx[1:])) for t in mt_lst
]
mux_cfm = [-np.log(1 - np.array(t.table_qx[1:])) for t in mt_lst]

alpha = 0.95
beta = 0.001
qx_changed = [
    list(1 - (1 - np.array(t.table_qx[1:]))**alpha * np.exp(-beta))
    for idx_t, t in enumerate(mt_lst)
]
[
    qx_changed[idx_t].insert(0, mt_lst[idx_t].table_qx[0])
    for idx_t, t in enumerate(mt_lst)
]

lt_lst = [mortality_table.MortalityTable(mt=mt) for mt in qx_changed]
ct_lst = [
    commutation_table.CommutationFunctions(i=4, g=0, mt=mt)
    for mt in qx_changed
]

for idx, lt in enumerate(lt_lst):
    name = parse_table_name(mt_lst[idx].name) + '_riskChange'
    lt.df_life_table().to_excel(excel_writer=name + '.xlsx',
                                sheet_name=name,
                                index=False,
                                freeze_panes=(1, 1))
    ct_lst[idx].df_commutation_table().to_excel(excel_writer=name + '_comm' +
                                                '.xlsx',
                                                sheet_name=name,
                                                index=False,
Beispiel #10
0
# author: PedroCR #
from soa_tables import read_soa_table_xml as rst
from essential_life import mortality_table, commutation_table

mt_TV7377 = rst.SoaTable('../soa_tables/TV7377.xml')
mt_GRF95 = rst.SoaTable('../soa_tables/GRF95.xml')
mt_GRM95 = rst.SoaTable('../soa_tables/GRM95.xml')

lt_tv7377 = mortality_table.MortalityTable(mt=mt_TV7377.table_qx)
lt_gRF95 = mortality_table.MortalityTable(mt=mt_GRF95.table_qx)
lt_gRM95 = mortality_table.MortalityTable(mt=mt_GRM95.table_qx)

cf_tv7377 = commutation_table.CommutationFunctions(i=1.4,
                                                   g=1,
                                                   mt=mt_TV7377.table_qx)
cf_grf95 = commutation_table.CommutationFunctions(i=1.4,
                                                  g=1,
                                                  mt=mt_GRF95.table_qx)
cf_grm95 = commutation_table.CommutationFunctions(i=1.4,
                                                  g=1,
                                                  mt=mt_GRM95.table_qx)

print(cf_tv7377.df_commutation_table())
print(cf_tv7377.t_aax(55, m=1, defer=(67 - 55)))
print(cf_grm95.t_aax(55, m=1, defer=(67 - 55)))
print(cf_grf95.t_aax(55, m=1, defer=(67 - 55)))
Beispiel #11
0
# author: PedroCR #
from toDelete.mortality_tables_old import TV7377, GKM95_lx_15
from essential_life import mortality_table, commutation_table

lt_tv7377 = mortality_table.MortalityTable(mt=TV7377)
lt_gkm95 = mortality_table.MortalityTable(data_type='l', mt=GKM95_lx_15)

cf_tv7377 = commutation_table.CommutationFunctions(i=2, g=1.5, mt=TV7377)
print(cf_tv7377.df_commutation_table())

# test to probabilities
p = lt_gkm95.tpx(x=50, t=5)
q = lt_gkm95.tqx(x=50, t=5)
print(p)
print(q)
print(p + q)
print(lt_gkm95.msn)

print(lt_gkm95.lx_udd(25.5))
print(lt_gkm95.lx_cfm(25.5))
print(lt_gkm95.lx_bal(25.5))

print(lt_gkm95.t_nqx(x=25.5, t=5.2, n=2.3, method='cfm'))
print(lt_gkm95.msn)

print('Insurances')
print(cf_tv7377.nEx(30, 350))
print(cf_tv7377.Ax(cf_tv7377.w), '=', cf_tv7377.msn[-1])
print(cf_tv7377.Ax(150), '=', cf_tv7377.msn[-1])

print(cf_tv7377.Ax_(30), '=', cf_tv7377.msn[-1])