# 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:

${\mathit{P}}_{\mathit{x},\mathit{n},\mathit{SA}}^{\mathsf{g}}≔\mathit{SA}\cdot \left(\frac{{\mathit{A}}_{\mathit{x},\mathit{n}}+\mathit{\gamma }\cdot {\mathit{a}}_{\mathit{x},\mathit{n}}}{\left(\mathrm{1}-\mathit{\beta }\right)\cdot {\mathit{a}}_{\mathit{x},\mathit{n}}}\right):\mathit{x}\in \mathbb{N};\mathit{n}\in \mathbb{N};\mathit{SA}\in \mathbb{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.

• 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).

On top of the left pane push the plus sign and select Module:

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

### Import the mortality table with the two genders

Download this CSV

Once you have the file, create a new Table in the Commutation calculations module.

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

Click on Upload than choose local file to upload the mortality table CSV.

Select Use first row as header in layout option and set the data domains (types) as on the following figure:

Mortality table schema with genders

Note

After upload you can edit 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 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 $\mathit{a},\mathit{b},\mathit{c},\mathit{someVariable}$
variables with embellishments x^^->, x^^^, x^^~ $\stackrel{\to }{\mathit{x}},\stackrel{^}{\mathit{x}},\stackrel{~}{\mathit{x}}$
indexed variables a^^~_{x,n} ${\stackrel{~}{\mathit{a}}}_{\mathit{x},\mathit{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 ${\stackrel{~}{\mathit{a}}}_{\mathit{x},\mathit{n}}$ , defines $\stackrel{~}{\mathit{a}}$ as an indexed variable with two index variables $\mathit{x},\mathit{y}$ . These x and y are actually separate variables that will need to be set for the variable ${\stackrel{~}{\mathit{a}}}_{\mathit{x},\mathit{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 $\stackrel{~}{\mathit{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 ${\mathit{l}}_{\mathit{x}}$ and ${\mathit{l}}_{\mathit{x}+\mathrm{1}}$.
• x behaves like a named parameter that is passed in when asking for a value of ${\mathit{d}}_{\mathit{x}}$,
• you can use x on the right side to ask for the value of ${\mathit{l}}_{\mathit{x}}$.
• Following the semicolon you describe (all) index parameters. In this case you specify that x is a natural number $\mathbb{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 $\in$, e.g. to say s is element of S you would write $\mathit{s}\in \mathit{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: $⟨\mathrm{2},\mathrm{6},\mathrm{10},\mathrm{14},\mathrm{18},\mathrm{20}⟩$

#### Referring to tables in formulas

In order to refer to values of 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 table you defined.

In the case of a 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.

• Create a new workbook, name it: Blended L table
• Import Commutation calculations module
• Add ${\mathit{L}}_{\mathsf{blended}}$ as a formula
• Click Run all
• Click on the arrow next to the Result label and choose Table view.

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.

## 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 table in the Commutation calculations module (upper right plus icon with the dropdown, select Table/Upload).

• Name: L
• Description: Genderless Mortality table

Click on local file and upload the mortality table CSV.

Select the Use first row as header option.

Setting data domains

### 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 add documentation by clicking on the plus sign and choosing markdown option in dropdown.

#### The discount formula

$\mathit{v}=\frac{\mathrm{1}}{\mathrm{1}+\mathit{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

${\mathit{l}}_{\mathit{x}}≔\left({\left(\mathit{lx}\right)}_{\mathsf{count}}|\mathit{lx}\in \mathsfit{L}\wedge {\left(\mathit{lx}\right)}_{\mathsf{age}}=\mathit{x}\right):\mathit{x}\in \mathbb{N}$

Source:

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


#### Deaths at age x

${\mathit{d}}_{\mathit{x}}≔{\mathit{l}}_{\mathit{x}}-{\mathit{l}}_{\mathit{x}+\mathrm{1}}:\mathit{x}\in \mathbb{N}$

Source:

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


${\mathit{C}}_{\mathit{x}}≔{\mathit{d}}_{\mathit{x}}{\mathit{v}}^{\mathit{x}+\mathrm{1}}:\mathit{x}\in \mathbb{N}$

Source:

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


#### Discounted lives

${\mathit{D}}_{\mathit{x}}≔{\mathit{l}}_{\mathit{x}}{\mathit{v}}^{\mathit{x}}:\mathit{x}\in \mathbb{N}$

Source:

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


#### Age cap

$\mathit{\omega }=\mathrm{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

${\mathit{M}}_{\mathit{x}}≔\sum _{\mathit{j}=\mathit{x}}^{\mathit{\omega }}{\mathit{C}}_{\mathit{j}}:\mathit{x}\in \mathbb{N}$

Source:

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


#### Cumulated discounted lives after x

${\mathit{N}}_{\mathit{x}}≔\sum _{\mathit{j}=\mathit{x}}^{\mathit{\omega }}{\mathit{D}}_{\mathit{j}}:\mathit{x}\in \mathbb{N}$

Source:

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


#### Produce commutation number sequence

$\mathit{CN}=⟨\left(\mathit{x},{\mathit{l}}_{\mathit{x}},{\mathit{d}}_{\mathit{x}},{\mathit{C}}_{\mathit{x}},{\mathit{D}}_{\mathit{x}},{\mathit{M}}_{\mathit{x}},{\mathit{N}}_{\mathit{x}}\right)|\mathit{x}=\mathrm{0},\mathrm{\dots },\mathrm{card}\mathsfit{L}-\mathrm{1}⟩$

Source:

### Export the the calculation output

The last step in this workflow is to evaluate the expression and export the variable $\mathit{CN}$ as CSV.

• Create a new workbook, name it: Commutation calculations
• Import the Commutation calculations module
• i is an input variable and set it to an interest rate of your choice, e.g.1.5
• CN is an output variable
• Click Run all
• Click on the arrow next to the Result label and choose Table view

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.

You could choose to use the basic functions ${\mathit{M}}_{\mathit{x}},{\mathit{N}}_{\mathit{x}},{\mathit{D}}_{\mathit{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 Table in the “Commutation calculations”.

• Name: C
• Description: Commutation numbers

Click on local file to upload the mortality table CSV.

Select the Use first row as header option and set column domains (types) as on the following figure:

Commutation table schema

### 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

${\mathit{D}}_{\mathit{x}}≔\left({\left(\mathit{el}\right)}_{\mathsf{Dx}}|\mathit{el}\in \mathsfit{C}\wedge {\left(\mathit{el}\right)}_{\mathsf{age}}=\mathit{x}\right):\mathit{x}\in \mathbb{N}$

Source:

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


#### Cumulated discounted deaths after age x

${\mathit{M}}_{\mathit{x}}≔\left({\left(\mathit{el}\right)}_{\mathsf{Mx}}|\mathit{el}\in \mathsfit{C}\wedge {\left(\mathit{el}\right)}_{\mathsf{age}}=\mathit{x}\right):\mathit{x}\in \mathbb{N}$

Source:

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


#### Cumulated discounted lives after x

${\mathit{N}}_{\mathit{x}}≔\left({\left(\mathit{el}\right)}_{\mathsf{Nx}}|\mathit{el}\in \mathsfit{C}\wedge {\left(\mathit{el}\right)}_{\mathsf{age}}=\mathit{x}\right):\mathit{x}\in \mathbb{N}$

Source:

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


#### Fixed term annuity with entry age and term

${\mathit{a}}_{\mathit{x},\mathit{n}}≔\frac{{\mathit{N}}_{\mathit{x}}-{\mathit{N}}_{\mathit{x}+\mathit{n}}}{{\mathit{D}}_{\mathit{x}}}:\mathit{x}\in \mathbb{N};\mathit{n}\in \mathbb{N}$

Source:

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


#### Net single premium whole life

${\mathit{A}}_{\mathit{x},\mathit{n}}≔\frac{{\mathit{M}}_{\mathit{x}}-{\mathit{M}}_{\mathit{x}+\mathit{n}}}{{\mathit{D}}_{\mathit{x}}}:\mathit{x}\in \mathbb{N};\mathit{n}\in \mathbb{N}$

Source:

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


#### Net Premium for Sum Assured

${\mathit{P}}_{\mathit{x},\mathit{n},\mathit{SA}}≔\mathit{SA}\cdot \frac{{\mathit{A}}_{\mathit{x},\mathit{n}}}{{\mathit{a}}_{\mathit{x},\mathit{n}}}:\mathit{x}\in \mathbb{N};\mathit{n}\in \mathbb{N};\mathit{SA}\in \mathbb{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

$\mathit{P}=\mathrm{round}{\mathit{P}}_{\mathit{x},\mathit{n},\mathit{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

• Create a new workbook, name it: Premium calculations
• Import Basic Actuarial Calculations module