lifetable.ijs

Script: ~addons/finance/finexec/actuariallife/lifetable.ijs
Contributor: William Szuch
Updated: 2023 03 17
Depend: ~addons/finance/finexec/qxtables/qxtools.ijs’
Definitions: loaded to locale base
Status: todo equations
Script source: lifetable.ijs

Definitions to calculate life table functions and survival factors.
Qx tables loaded to the locale base.
See: Qx_ALL for a list of names.
See: Qx_ALT for a list of Australian Life Tables.
All mortality tables start at age = 0.

Note:
(1) Dealing with Ages outside the range of the mortality table.
(2) Dealing with qx>1 if Qx table is scaled up.
use of ext5
Tables - try to make tacit
pxn,qxn - try to make into tacit
Plots

Equations:
NF

Definitions

D distDeathsYr, distDurLife, dx
E ex, exz
L lx, lxn, lxn1
N nyears
P plotdistDeathsYr, plotdistDurLife, px, pxn, pxn1
Q qx, qxn, qxn1

distDeathsYr (dyad)

Form: explicit
Distribution of the number of deaths in a year for a selected Qx table
and Age for 100,000 lives at Age.
1000 simulations

Example

   (ALT_2013_15_M)distDeathsYr(54)
   (ALT_2013_15_M)distDeathsYr(0)
   (ALT_2013_15_M)plotdistDeathsYr(54)
   (ALT_2013_15_M)plotdistDeathsYr(0)

distDurLife (dyad)

Form: explicit
Distribution of the duration of life for a selected Qx table and Age.
Number of simulations = 100,000 for distribution.

Note

Mortality table extended by 5 years.

Syntax

(Qx)distDurLife(Age)
Qx = name of qx table starting at age = 0
Age = integer age

Example

   (ALT_2013_15_M)distDurLife(54)
   (ALT_2013_15_M)distDurLife(0)
   (ALT_2013_15_M)plotdistDurLife(54)
   (ALT_2013_15_M)plotdistDurLife(0)
   (ALT_2013_15_M)plotdistDurLife(10;1)

dx (dyad)

Form: tacit
Number of deaths from Age to Age + 1
from lx(Age) lives at Age.

Note

lx(Age) is the number of lives surviving to Age from 100000 biths.

Syntax

(Qx)dx(Age)
Qx = name of qx table starting at age = 0
Age = integer ages

Example

   (ALT_2005_07_M)dx(0)
523
   (ALT_2005_07_M)dx(0 10 20 50)
523 9.93219 73.2663 288.278

ex (dyad)

Form: tacit
Calculate the complete expectation of life with extended Qx table.

Note

The complete expectation of life is the average number of
years lived by person aged x from age x.

The final value in the Qx table is extended by 5 years.

Syntax

(Qx)ex(Age)
Qx = name of Qx table starting at age = 0
Age= integer ages

Example

   (ALT_1960_62_M)ex(30 40 50 60 70)
 41.119 31.8354 23.1279 15.6059 9.77224
   (ALT_2009_11_F)ex(0 20 40 60)
 84.2052 64.6905 45.1089 26.414

exz (dyad)

Form: tacit
Calculate the complete expectation of life without extended Qx table.

Note

The complete expectation of life is the average number of
years lived by person aged x from age x.

The final value in the qx table has not been extended.
Same equation as for ex.

Syntax

(Qx)exz(Age)
Qx = name of Qx table starting at age = 0
Age  = integer ages

Example

   (ALT_1960_62_M)exz(30 40 50 60 70)
41.119 31.8354 23.1279 15.6059 9.77224
   (ALT_2009_11_F)exz(0 20 40 60)
84.1505 64.6354 45.0534 26.3563

lx (dyad)

Calculate the number of lives surviving to Age from 100,000 births for the
Qx selected table.
Qx tables start from Age = 0.

Syntax

(Qx)lx(Age)
Qx = name of Qx table starting at age = 0
Age = integer ages

Example

   (ALT_2009_11_F)lx(10)
99538.4
   (ALT_2009_11_F)lx(0 10 20 30 40)
100000 99538.4 99391.2 99111.3 98608.9

lxn (dyad)

Form: tacit
Extension of lxn1.
Multiple ages surviving for multiple periods in years
Calculate for multiple ages and periods surviving from 100,000
lives at each age for the selected (Qx) mortality table.
Qx tables start from age = 0.

Syntax

(Qx)lxn(Age;N)
Qx = name of Qx table starting at age = 0
Age = integer ages
N = integer periods

Example

   (ALT_2009_11_F)lxn(10;10)
99852.1
   (ALT_2009_11_F)lxn(40;10 20 30)
98789.6 96154.3 90253.2
   (ALT_2009_11_F)lxn(20 30 40;10)
99718.4 99493.2 98789.6
   (ALT_2009_11_F)lxn(20 40;0 10 20 30)
100000 99718.4 99212.9 98012.1
100000 98789.6 96154.3 90253.2

lxn1 (dyad)

Form: tacit
Calculate the number lives surviving to Age + N from 100,000 lives
at Age for the selected Qx table.
Qx tables start from age = 0.
(for one life) - same equation as lxn

Syntax

(Qx)lxn1(Age;N)
Qx = name of Qx table starting at age = 0
Age = integer age
N = interger duration in years

Example

  (ALT_2009_11_F)lxn1(10;10)
99852.1
   (ALT_2009_11_F)lxn1(0;10)
99538.4

nyears (dyad)

Form: explicit
Depend: oxn1
Calculate the number of years N of survival required
for a probability P.

Syntax

(Qx)nyears(Age;P)
Qx = name of qx table starting at age = 0
Age = integer age
P = probability of survival (0<P<1)

Example

  (ALT_2018_20_M)nyears(55;0.5)
31
  (ALT_2018_20_M)pxn(55;30 31)
0.517873 0.476785
  (ALT_2018_20_M)nyears(55;0.75)
23
  (ALT_2018_20_M)pxn(55;22 23)
0.766397 0.743153

plotdistDeathsYr (dyad)

Form: explicit
Depend: distDyingYr
Plot the pdf and cdf from distDeathsYr.

Syntax

(Qx)distDeathsYr(Age;[Y])
Qx = name of qx table starting at age = 0
Age = integer age
[Y] = 0 optinal = default - probability density functions (pdf)
    = 1 cumulative density function (cdf)

Example

   (ALT_2013_15_M)plotdistDeathsYr(54)
   (ALT_2013_15_M)plotdistDeathsYr(54;1)
   (ALT_2013_15_M)plotdistDeathsYr(0)
   (ALT_2013_15_M)plotdistDeathsYr(0;1)

plotdistDurLife (dyad)

Form: explicit
Depend: distDurLife
Plot the pdf and cdf from distDurLife.

Syntax

(Qx)distDurLife(Age;[Y])
Qx = name of qx table starting at age = 0
Age = integer age
[Y] = 0 optinal = default - probability density functions (pdf)
    = 1 cumulative density function (cdf)

Example

   (ALT_2013_15_M)plotdistDurLife(54)
   (ALT_2013_15_M)plotdistDurLife(54;1)
   (ALT_2013_15_M)plotdistDurLife(0)
   (ALT_2013_15_M)plotdistDurLife(0;1)

px (dyad)

Form: tacit
The probability of surviving a year for the selected Qx mortality table.

Qx tables start from age = 0.

Syntax

(Qx)px(Age)
Qx = name of Qx table starting at age = 0
Age = integer ages

Example

   (ALT_2009_11_F)px(10)
0.99993
   (ALT_2010_12_F)px(0 10 20 60)
0.99658 0.99993 0.99973 0.99593

pxn (dyad)

Form: explicit
Depend: boxtable
Extension of pxn1
The probability of a life surviving N years for the selected Qx table.
Qx tables start from age = 0.

Syntax

(Qx)pxn(Age;N)
Qx = name of Qx table starting at age = 0
Age = integer ages
N = integer period

Example

   (ALT_2009_11_F)pxn(40;10)
0.987896
   (ALT_2009_11_F)pxn(0 10 20;40)

pxn1 (dyad)

Form: tacit
The probability of a life surviving N years for the selected Qx table.
Qx tables start from age = 0.
(for one life) - same equation as pxn

Syntax

(Qx)pxn1(Age;N)
Qx = name of Qx table starting at age = 0
Age = integer age
N = integer period

Example

   (ALT_2009_11_F)pxn1(40;10)
0.987896
   (ALT_2009_11_F)pxn1(0;40)
0.986089
   (ALT_2009_11_F)pxn1(40;0)
1
   (ALT_2010_12_F)pxn1(65;10)
0.899431

qx (dyad)

Form: tacit
The probability of dying within a year for the selected Qx table.
Qx tables start from age = 0.

Syntax

(Qx)qx(Age)
Qx = name of Qx table starting at age = 0
Age = integer ages

Example

   (ALT_2009_11_F)qx(20)
0.00025
   (ALT_2010_12_F)qx(0 10 20 60)
0.00342 7e_5 0.00027 0.00407

qxn (dyad)

Form: tacit
Depend: boxtable
Extension of qxn1.
The probability for multiple ages dying with multiple periods
for the selected Qx table.

Qx tables start from age = 0.

Syntax

(Qx)qxn(Age;N)
Qx = name of Qx table starting at age = 0
Age = integer ages
N = integer periods in years

Example

  (ALT_2009_11_F)qxn(40;10)
0.012104
  (ALT_2009_11_F)qxne(40 50 60;10)
0.012104 0.0266759 0.0613706
  (ALT_2009_11_F)qxn(40;10 20 30)
0.012104 0.0384571 0.0974675
  (ALT_2009_11_F)qxn(20 30 40 50;10 20 30)
0.00281643 0.00787062 0.0198794
0.00506847  0.0171111 0.0433306
  0.012104  0.0384571 0.0974675
 0.0266759  0.0864094  0.241221

qxn1 (dyad)

Form: tacit
The probability of a life dying within N years for the selected Qx table.
Mortality tables start from age = 0.
(for one life) - same equation as qxn

Syntax

(Qx)qxn1(Age;N)
Qx = name of Qx table starting at age = 0
Age = integer age
N = integer period

Example

   (ALT_2009_11_F)qxn1(40;10)
0.012104
   (ALT_2009_11_F)qxn1(0;40)
0.0139106
   (ALT_2009_11_F)qxn1(40;0)
0
   (ALT_2010_12_F)qxn1(65;10)
0.100569