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.
First, import the input data from input.py. Open model.py.
Import:
Fill in the code:
# model.py
from input import _____, _____
Task: Insert the correct variable names.
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:
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:
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:
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: