def test_tai_20_1term(): mml = makeham_mortality_functions.Makeham(a=0.00022, b=2.7E-6, c=1.124) a = mml.annuity(x=20, interest_rate=5, age_first_instalment=20 + 1, terms=10, fraction=1, w=130) assert 7.711382730455226 == pytest.approx(a, rel=1e-12)
def test_wlai_40_1term(): mml = makeham_mortality_functions.Makeham(a=0.00022, b=2.7E-6, c=1.124) a = mml.annuity(x=40, interest_rate=5, age_first_instalment=40 + 1, terms=np.inf, fraction=1, w=130) assert 17.457756571743005 == pytest.approx(a, rel=1e-12)
def test_tai_20_4term(): mml = makeham_mortality_functions.Makeham(a=0.00022, b=2.7E-6, c=1.124) a = mml.annuity(x=20, interest_rate=5, age_first_instalment=20 + 1 / 4, terms=10, fraction=4, w=130) assert 7.855310570588442 == pytest.approx(a, rel=1e-12)
def test_tad_40_1term(): mml = makeham_mortality_functions.Makeham(a=0.00022, b=2.7E-6, c=1.124) a = mml.annuity(x=40, interest_rate=5, age_first_instalment=40, terms=10, fraction=1, w=130) assert 8.086328661846537 == pytest.approx(a, rel=1e-12)
def test_wlai_40_4term(): mml = makeham_mortality_functions.Makeham(a=0.00022, b=2.7E-6, c=1.124) a = mml.annuity(x=40, interest_rate=5, age_first_instalment=40 + 1 / 4, terms=np.inf, fraction=4, w=130) assert 17.828905180633175 == pytest.approx(a, rel=1e-12)
def test_tai_80_1term(): mml = makeham_mortality_functions.Makeham(a=0.00022, b=2.7E-6, c=1.124) a = mml.annuity(x=80, interest_rate=5, age_first_instalment=80 + 1, terms=10, fraction=1, w=130) assert 6.1280362723202835 == pytest.approx(a, rel=1e-12)
def test_wlai_20_4term(): mml = makeham_mortality_functions.Makeham(a=0.00022, b=2.7E-6, c=1.124) a = mml.annuity(x=20, interest_rate=5, age_first_instalment=20 + 1 / 4, terms=np.inf, fraction=4, w=130) assert 19.337562859204613 == pytest.approx(a, rel=1e-12)
def test_tai_60_4term(): mml = makeham_mortality_functions.Makeham(a=0.00022, b=2.7E-6, c=1.124) a = mml.annuity(x=60, interest_rate=5, age_first_instalment=60 + 1 / 4, terms=10, fraction=4, w=130) assert 7.690789257141573 == pytest.approx(a, rel=1e-12)
def test_tad_80_4term(): mml = makeham_mortality_functions.Makeham(a=0.00022, b=2.7E-6, c=1.124) a = mml.annuity(x=80, interest_rate=5, age_first_instalment=80, terms=10, fraction=4, w=130) assert 6.538535827831598 == pytest.approx(a, rel=1e-12)
def test_tad_60_4term(): mml = makeham_mortality_functions.Makeham(a=0.00022, b=2.7E-6, c=1.124) a = mml.annuity(x=60, interest_rate=5, age_first_instalment=60, terms=10, fraction=4, w=130) assert 7.796128394417279 == pytest.approx(a, rel=1e-12)
def test_tai_60_1term(): mml = makeham_mortality_functions.Makeham(a=0.00022, b=2.7E-6, c=1.124) a = mml.annuity(x=60, interest_rate=5, age_first_instalment=60 + 1, terms=10, fraction=1, w=130) assert 7.534191594775955 == pytest.approx(a, rel=1e-12)
def test_tai_80_4term(): mml = makeham_mortality_functions.Makeham(a=0.00022, b=2.7E-6, c=1.124) a = mml.annuity(x=80, interest_rate=5, age_first_instalment=80 + 1 / 4, terms=10, fraction=4, w=130) assert 6.373414695745405 == pytest.approx(a, rel=1e-12)
def test_tai_40_4term(): mml = makeham_mortality_functions.Makeham(a=0.00022, b=2.7E-6, c=1.124) a = mml.annuity(x=40, interest_rate=5, age_first_instalment=40 + 1 / 4, terms=10, fraction=4, w=130) assert 7.840607131213686 == pytest.approx(a, rel=1e-12)
def test_wlad_20_1term(): mml = makeham_mortality_functions.Makeham(a=0.00022, b=2.7E-6, c=1.124) a = mml.annuity(x=20, interest_rate=5, age_first_instalment=20, terms=np.inf, fraction=1, w=130) assert 19.966393800426772 == pytest.approx(a, rel=1e-12)
def test_wlai_80_4term(): mml = makeham_mortality_functions.Makeham(a=0.00022, b=2.7E-6, c=1.124) a = mml.annuity(x=80, interest_rate=5, age_first_instalment=80 + 1 / 4, terms=np.inf, fraction=4, w=130) assert 7.917147603528528 == pytest.approx(a, rel=1e-12)
def test_tad_20_4term(): mml = makeham_mortality_functions.Makeham(a=0.00022, b=2.7E-6, c=1.124) a = mml.annuity(x=20, interest_rate=5, age_first_instalment=20, terms=10, fraction=4, w=130) assert 7.952250811733334 == pytest.approx(a, rel=1e-12)
def test_wlai_80_1term(): mml = makeham_mortality_functions.Makeham(a=0.00022, b=2.7E-6, c=1.124) a = mml.annuity(x=80, interest_rate=5, age_first_instalment=80 + 1, terms=np.inf, fraction=1, w=130) assert 7.548405606430032 == pytest.approx(a, rel=1e-12)
def test_wlai_60_4term(): mml = makeham_mortality_functions.Makeham(a=0.00022, b=2.7E-6, c=1.124) a = mml.annuity(x=60, interest_rate=5, age_first_instalment=60 + 1 / 4, terms=np.inf, fraction=4, w=130) assert 14.275011062804799 == pytest.approx(a, rel=1e-12)
def test_wlad_60_1term(): mml = makeham_mortality_functions.Makeham(a=0.00022, b=2.7E-6, c=1.124) a = mml.annuity(x=60, interest_rate=5, age_first_instalment=60, terms=np.inf, fraction=1, w=130) assert 14.904074300627276 == pytest.approx(a, rel=1e-12)
def test_life_insurance_129_1frac(): mml = makeham_mortality_functions.Makeham(a=0.00022, b=2.7E-6, c=1.124) a = mml.life_insurance(x=129, interest_rate=5, age_first_instalment=129, terms=np.inf, fraction=1, w=129) q_w = 1 - mml.S(x=129, t=1) assert 1 / (1 + .05) == pytest.approx(a, rel=1e-12)
def test_life_insurance_20_12frac_c(): mml = makeham_mortality_functions.Makeham(a=0.00022, b=2.7E-6, c=1.124) x0 = 20 + 2 / 12 a = mml.life_insurance(x=x0, interest_rate=5, age_first_instalment=x0, terms=np.inf, fraction=12, w=129) assert 0.05069999821147594 == pytest.approx(a, rel=1e-12)
def test_life_insurance_50_12frac_b(): mml = makeham_mortality_functions.Makeham(a=0.00022, b=2.7E-6, c=1.124) x0 = 50 + 1 / 12 a = mml.life_insurance(x=x0, interest_rate=5, age_first_instalment=x0, terms=np.inf, fraction=12, w=129) assert 0.19428541530458865 == pytest.approx(a, rel=1e-12)
def test_term_life_insurance_100_12frac(): mml = makeham_mortality_functions.Makeham(a=0.00022, b=2.7E-6, c=1.124) x0 = 100 a = mml.life_insurance(x=x0, interest_rate=5, age_first_instalment=x0, terms=np.inf, fraction=12, w=129) assert 0.8915840217595198 == pytest.approx(a, rel=1e-12)
def test_term_life_insurance_60_12frac(): mml = makeham_mortality_functions.Makeham(a=0.00022, b=2.7E-6, c=1.124) x0 = 60 a = mml.life_insurance(x=x0, interest_rate=5, age_first_instalment=x0, terms=np.inf, fraction=12, w=129) assert 0.29683037981657273 == pytest.approx(a, rel=1e-12)
def test_term_life_insurance_80_1frac(): mml = makeham_mortality_functions.Makeham(a=0.00022, b=2.7E-6, c=1.124) x0 = 80 a = mml.life_insurance(x=x0, interest_rate=5, age_first_instalment=x0, terms=np.inf, fraction=1, w=129) assert 0.592933066360474 == pytest.approx(a, rel=1e-12)
def test_life_insurance_129_12frac_b(): mml = makeham_mortality_functions.Makeham(a=0.00022, b=2.7E-6, c=1.124) x0 = 129 + 11 / 12 a = mml.life_insurance(x=x0, interest_rate=5, age_first_instalment=x0, terms=np.inf, fraction=12, w=129) assert 1.05**(-1 / 12) == pytest.approx(a, rel=1e-12)
def test_term2_life_insurance_20_1frac(): mml = makeham_mortality_functions.Makeham(a=0.00022, b=2.7E-6, c=1.124) x0 = 20 a = mml.life_insurance(x=x0, interest_rate=5, age_first_instalment=x0, terms=np.inf, fraction=1, w=129) assert 0.04921934283681906 == pytest.approx(a, rel=1e-12)
from exercisesLifeContingencies.survivalModels.someMortalityLaws import makeham_mortality_functions import scipy.integrate mml = makeham_mortality_functions.Makeham(a=0.0001, b=0.00030, c=1.075) ''' $\ax**[]{25:30}$ ''' i = 5 v = 1 / (1 + i / 100) x = 25 y = 30 w = 130 prob_discount = [ mml.S(x=x, t=t) * mml.S(x=y, t=t) * v**t for t in range(w - max(x, y) + 1) ] print('annuity:', sum(prob_discount)) ''' $\ax**[]{\overline{25:30}}$ ''' prob_discount_2 = [ (mml.S(x=x, t=t) + mml.S(x=y, t=t) - mml.S(x=x, t=t) * mml.S(x=y, t=t)) * v**t for t in range(w - max(x, y) + 1) ] print('annuity:', sum(prob_discount_2)) ''' $\ax**[]{25|30}=\ax**[]{30}-\ax**[]{25:30}$ ''' prob_discount_3 = [mml.S(x=y, t=t) * v**t for t in range(w - max(x, y) + 1)] print('annuity:', sum(prob_discount_3) - sum(prob_discount))
from exercisesLifeContingencies.survivalModels.someMortalityLaws import makeham_mortality_functions import numpy as np from essential_life import mortality_table, commutation_table 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)) '''
from exercisesLifeContingencies.survivalModels.someMortalityLaws import makeham_mortality_functions import numpy as np from essential_life import mortality_table, commutation_table 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.0001, b=0.0003, c=1.07) # mml = makeham_mortality_functions.Makeham(a=0.00022, b=2.7E-6, c=1.124) # mml = makeham_mortality_functions.Makeham(a=0.0001, b=0.00035, c=1.075) mml = makeham_mortality_functions.Makeham(a=0.00018, b=1.9E-6, c=1.124) interest_rate = 4 e0 = mml.moments_Tx() e70 = mml.moments_Tx(x=70) ''' Compute Life Table ''' w = 125 px = np.array([mml.S(x, t=1) for x in range(0, w)]) qx = 1 - px lt = mortality_table.MortalityTable(mt=list(np.append(0, qx))) w = len(px) ct = commutation_table.CommutationFunctions(i=interest_rate, g=0, mt=list(np.append(0, qx))) ''' lt.df_life_table().to_excel(excel_writer='makeham_' + str(w) + '.xlsx', sheet_name='makeham', index=False, freeze_panes=(1, 1))