Getting Started with Actuarial Math (Life insurance)

This getting started provides a short overview on how to implement some actuarial math models focusing on mortality and premium related calculations.

This tutorial has a worked out sample project counterpart which you can check out (login to your workspace and clone a project from the Life Insurance sample) to see how you can take these concepts and create actual pricing services that can be integrated by developers/IT into applications.

During this exercise we will get from mortality tables to formulas that calculate premium, fron there with some cost parameters you can easily get to calculate premiums like the one below:

P x , n , SA g SA A x , n + γ a x , n 1 β a x , n : x N ; n N ; SA R

Mortality table

The first task to solve will be the calculation of a genderless mortality table from one that has mortality statistics for two (for now:) genders: male and female.

Overview of the task:

  • start with an empty project
  • create a module for the commutation number calculations
  • import the mortality table with the two genders
  • create the formula to read from this table and prepare the sequence containing the blended gender calculations
  • export the the calculation output as a CSV

Create an empty project

In your workspace create a new project, make sure you are selecting the Empty Project option and not any of the samples.

Create a module for commutation number calculations

Once you created your project select “Model” on the left navigation (this is also the current default when you open a project).

Resist to push the New button in the middle, push the New with the dropdown icon on the upper left corner instead and select new Module:

  • name: Commutation calculations
  • description: “Commutation number calculations and mortality tables”

Import the mortality table with the two genders

First you can download the sample mortality table from the link below:

Download this CSV

Once you have the file, create a new Parameter Table in the “Commutation calculations” module (upper left new button with the dropdown, select Parameter Table).

  • Name: LwG
  • Description: Mortality table with two gender (male, female)

Click on import file and choose file to upload the mortality table CSV.

Check the First row contains column names option and fill in the column domains (types) as on the following figure:

../_images/lwg-param-table-schema.png

Mortality table schema with genders

Note

You can return to editing parameter tables (and formulas) by clicking on them in the list view

Create the formula producing the genderless mortality table

The formula creating the target table is quite simple, but before diving into that, here is a short introduction on some of the related language topics.

The topics we will address are:

  • variables
  • collections and ranges
  • referring to parameter tables in formulas

Variables

In contrast to most languages Formulative offers variable names that can express usual mathematical notations. These are called embellishments. Some examples of both simple and decorated variables:

Example variable names
Description Source Rendering
simple variables a, b, c, someVariable a , b , c , someVariable
variables with embellishments x^^->, x^^^, x^^~ x , x ^ , x ~
indexed variables a^^~_{x,n} a ~ x , n

The first set of samples show names you are probably used to.

The second set of variable names show you how to express some embellishments. You can find more on this topic in the language reference: Identifiers. These are special constructs that allow you to use native mathematical notations within your models. Even though they look special they behave just like conventional variables.

The last set of variables, indexed variables are special. You can think of indexed variables like function definitions with parameters. The one above a ~ x , n , defines a ~ as an indexed variable with two index variables x , y . These x and y are actually separate variables that will need to be set for the variable a ~ x , n to take a value. The formula setting a value to this variable can then refer to x and y as parameters when determining the value of a ~ .

Let’s take an example from the commutation calculations:

d_x := l_x - l_{x+1} : x (- %N

The above shows an indexed variable formula calculating the number of deceased at some age x.

  • The indexed variable d_x also refers to other indexed variables (l_x).
  • On the right side of the assignment you need to pass in actual values to indexed variable references l x and l x + 1 .
  • x behaves like a named parameter that is passed in when asking for a value of d x ,
  • you can use x on the right side to ask for the value of l x .
  • Following the semicolon you describe (all) index parameters. In this case you specify that x is a natural number N .

Collections and ranges

Similar to other high-level languages and frameworks like R or Python (Pandas) you can easily create ranges (enumeration of values). When creating a range of values you need to make two decisions:

  1. the type of collection you want to use
  2. the values you want the enumeration to have.

For example to make a simple set of numbers you could write this formula:

S = {{1,2,3,4,5}}

This defines a collection of type Set with 5 number values. (more on collections here Lists )

You can then refer to elements of this set with the element of operator , e.g. to say s is element of S you would write s S

You can also design various patterns for incrementing values like this:

Seq = {<1,3,...,10>}

The above will create a sequence this time with numbers from 1 to 10 incremented by 2 (the language recognises your pattern). You can find more on iterations here: Ranges & Repeats.

Taking this one step further the formula below assigns a variable to the above list of numbers and maps an expression to each element in succession (iteration).

Seq_'fromItem = {< i*2 | i = 1,3,...,10 >}

The above creates a similar sequence but applies an expression to each element. Thus the result sequence is: 2 , 6 , 10 , 14 , 18 , 20

Referring to parameter tables in formulas

In order to refer to values of parameter tables you can use the @ sign. For example to refer to the values of the previously created mortality table you would use this identifier reference @LwG. The engine will set the reference to the parameter table you defined.

In the case of a parameter table both the values and the collection type (relational table) are preset.

Genderless mortality table formula

After this detour into the language, let’s get on to the formula.

In the “Commutation calculations” module create a new formula:

  • title: Blended Mortality table

Source:

L_'blended = {< ( (l)_'age, (l)_'male * 0.75 + (l)_'female * 0.25 ) | l (- @LwG >}

Some explanations of the above:

  • l (- @LwG declares that l is element of the LwG parameter table
  • (l)_'age, (l)_'male, (l)_'female are references to the fields of one row of the parameter table (l)
  • the map operator “|” maps each row of the parameter table to the expression on the left
  • the result is sequence constructed by the sequence construction literals: {< >}

Export the the calculation output

The last step in this workflow is to evaluate the expression and export the variable :math:L_'blended as CSV.

  • Click Evaluate
  • Create a new Configuration, name it: Blended L table
  • Add the Commutation calculations module to the Modules list.
  • Click Add Variable
  • Select L blended
  • Click Calculate
  • Click on the Eye icon next to the output variable L blended
  • Select the CSV tab and click Download to get the result as a CSV

You might notice that the result is not sorted. Clone the sample “Life Insurance” project to see how sorting can be done. The language tutorial also describes the sorting tropic.

../_images/evaluate-l-blended.png

Commutation calculations

In this task you will develop the formulas required to generate a set of commutation numbers that can be used to do premium calculations.

Commutation numbers are a tool designed when computations were more expensive as shortcuts to cut down the number of repetitive calculation required for pricing. While these days you could do without them, since many actuaries used and still use them, we show how to set up a basic set of calculations.

Prerequisites

In order for these formulas to work, you will need the genderless Lx table created in the previous step. While you could use your own export we provide one that you can use to upload the required data.

Download the blended mortality table from this link Download this CSV

Once you have the file, create a new Parameter Table in the “Commutation calculations” module (upper left new button with the dropdown, select Parameter Table).

  • Name: L
  • Description: Genderless Mortality table

Click on import file and choose file to upload the mortality table CSV.

Check the First row contains column names option and fill in the column domains (types) as on the following figure:

../_images/l-param-table-schema.png

Mortality table schema with genders

Click Import to do the actual import.

Create the formulas

Navigate to the Commutation calculations module and create the formulas shown below. Each formula shows the rendered view and the source you can copy-paste into the formula source editor. We will leave the documentation to you.

Note

You can edit documentation by clicking on the Documentation tab on the formula source editor.

The discount formula

v = 1 1 + i

Source:

v = 1 / {1 + i}
Explanation

The formula references variable i. For the sake of brevity we will set it as input when doing the calculations. You could also create a table and do a lookup.

The expected number of survivors at age x

l x lx count | lx L lx age = x : x N

Source:

l_x := ((lx)_'count | lx (- @L /\ (lx)_'age = x) : x (- %N

Deaths at age x

d x l x l x + 1 : x N

Source:

d_x := l_x - l_{x+1} : x (- %N

Discounted dead

C x d x v x + 1 : x N

Source:

C_x := d_x v^{x+1} : x (- %N

Discounted lives

D x l x v x : x N

Source:

D_x := l_x v^x : x (- %N

Age cap

ω = 100

Source:

\omega = 100
Explanation

We could get the max of the lx table as well, we leave this to you for this exercise.

Cumulated discounted deaths after age x

M x j = x ω C j : x N

Source:

M_x := {+}__{j=x}^^{\omega} C_j : x (- %N

Cumulated discounted lives after x

N x j = x ω D j : x N

Source:

N_x := {+}__{j=x}^^\omega D_j : x (- %N

Produce commutation number sequence

CN = x , l x , d x , C x , D x , M x , N x | x = 0 , , card L 1

Source:

CN = {< (x, l_x, d_x, C_x, D_x, M_x, N_x) | x = 0, ..., $card @L - 1 >}
Explanation

This formula refers to the above commutation indexed variables and creates a sequence {<…>} $card @L returns the cardinality (the number of rows) in the L table. The x index variable will then be iterated from 0 to length of table -1 and passed in to the commutation formulas.

Export the the calculation output

The last step in this workflow is to evaluate the expression and export the variable :math:CN as CSV.

  • Click Evaluate
  • Create a new Configuration, name it: Commutation calculations
  • Add the Commutation calculations module to the Modules list.
  • Click Add Variable
  • Select CN and i
    • Set CN as output variable
    • Set i as input variable and set it to an interest rate of your choice, e.g.``1.5``
  • Click Calculate
  • Click on the Eye icon next to the output variable CN
  • Select the CSV tab and click Download to get the result as a CSV

You might notice that the result is not sorted. Clone the sample “Life Insurance” project to see how sorting can be done. The language tutorial also describes the sorting tropic.

Premium Calculation

You could choose to use the basic functions M x , N x , D x etc. directly or use the commutation table we generated in the previous task. In order to build on the previous task we will now build functions that use the commutation table.

Prerequisites

Create a new Module and name it Basic Actuarial Calculations. All work in this task will be done in this module, so we assume you navigated to it.

In order for these formulas to work, you will need the commutation table created in the previous step. While you could use your own CSV export we provide one, that you can use to upload the required data.

Download the commutation table from this link Download this CSV

Once you have the file, create a new Parameter Table in the “Commutation calculations” module (upper left new button with the dropdown, select Parameter Table).

  • Name: C
  • Description: Commutation numbers

Click on import file and choose file to upload the mortality table CSV.

Check the First row contains column names option and fill in the column domains (types) as on the following figure:

../_images/commutation-table-schema.png

Commutation table schema

Click Import to do the actual import.

Create the formulas

Navigate to the Basic Actuarial Calculations module and create the formulas shown below. Each formula shows the rendered view and the source you can copy-paste into the formula source editor. We will leave the documentation to you.

Notice that we will repeat the commutation table value producing formulas but instead of doing the calculations, they will do a lookup on the Commutation Table C.

Discounted lives

D x el Dx | el C el age = x : x N

Source:

D_x := ((el)_'Dx | el (- @C /\ (el)_'age = x) : x (- %N

Cumulated discounted deaths after age x

M x el Mx | el C el age = x : x N

Source:

M_x := ((el)_'Mx | el (- @C /\ (el)_'age = x) : x (- %N

Cumulated discounted lives after x

N x el Nx | el C el age = x : x N

Source:

N_x := ((el)_'Nx | el (- @C /\ (el)_'age = x) : x (- %N

Fixed term annuity with entry age and term

a x , n N x N x + n D x : x N ; n N

Source:

a_{x, n} := { N_x - N_{x+n} } / D_x : x (- %N; n (- %N

Net single premium whole life

A x , n M x M x + n D x : x N ; n N

Source:

A_{x,n} := { M_x - M_{x+n} } / D_x : x (- %N; n (- %N

Net Premium for Sum Assured

P x , n , SA SA A x , n a x , n : x N ; n N ; SA R

Source:

P_{x,n,SA} := SA * { A_{x,n} / a_{x,n} } : x (- %N; n (- %N; SA (- %R

Call the Net Premium with the variables x, n, SA

P = round P x , n , SA

Source:

P = $round P_{x,n,SA}
Explanation

This formula is required to “call” the indexed variable definitions and it will round the result.

Evaluate the net premium formula

Now comes the fun part, we can actually see what premium is calculated. In order to do that

  • Click Evaluate
  • Create a new Configuration, name it: Premium calculations
  • Add the Premium calculations module to the Modules list.
  • Click Add Variable
  • Select SA, x, n, P
    • Set SA, x, n as input variables and set the variables to some meaningful values (see attached screen below)
    • Set P as output variable
  • Click Calculate

You should see a result similar to this:

../_images/evaluation-premium-calculation-result.png