← Back to Cashflow Modelling in Python

Survival rate & Expected benefit

Fantastic work on the input data! Now we will get to the core - creating model variables.

In this lesson, you will create variables needed to calculate the actuarial present value.

Import data

First, import the input data from input.py. Open model.py.

Import:

  • policy - policy data,
  • interest_rate - monthly interest rate.

Fill in the code:

# model.py

from input import _____, _____

Task: Insert the correct variable names.

Probability of survival for t months

Let's notice that we have already modelled probability of survival in the last chapter for the Term Life model. Such a situation will be common in actuarial modelling - there will be logic that can be used across multiple models.

Create a variable survival_rate(t) that calculates the probability of surviving t months.

Use a recursive formula:

\[ \text{survival_rate(t)} = {}_tp_x = {}_{t-1}p_x \cdot (1-q_{x+t-1}) \]

Assume:

  • for t = 0, survival = 1,
  • the monthly death probability is constant and equals policy.get("mortality_rate").

Fill in the function:

# model.py

@variable()
def survival_rate(t):
    if t == 0:
        return 1
    else:
        q = policy.get("_____")
        return survival_rate(t - 1) * (1 - _____)

Task:

  • Fill in the name of the mortality attribute.
  • Think how to express survival over t periods.

Expected benefit

Define a variable expected_benefit(t) - the expected benefit paid in month t.

Use the following formula:

\( \text{expected_benefit(t)} = B \cdot {}_{t}p_x \)

Remember that:

  • for t = 0 and after the term ends, the benefit is 0,
  • \( B \) is policy.get("benefit"),
  • annuity's term is stored in policy.get("remaining_term").

Fill in the code:

# model.py

@variable()
def expected_benefit(t):
    if t == 0 or t > policy.get("_____"):
        return 0
    else:
        B = policy.get("_____")
        return B * _____

Task:

  • Fill in remaining_term and benefit.
  • Use the correct model variable for probability of survival.
  Next