import pandas as pd
[docs]
def load_mortality_table_from_csv(filename: str, column: str):
df = pd.read_csv(filename)
qx = df.loc[:, column].values.tolist()
return qx
[docs]
class CommutationFunctions:
[docs]
def __init__(self, mortality_table, interest_rate):
self.qx = mortality_table
self.i = interest_rate
self.lx = []
self.dx = []
self.cx = []
self.mx = []
v = 1 / (1 + self.i)
w = len(self.qx)
# define lx and Dx
for x in range(0, w):
if x == 0:
self.lx.append(1000000)
else:
self.lx.append(self.lx[x - 1] * (1 - self.qx[x - 1]))
self.dx.append(v**x * self.lx[x])
# define cx
for x in range(0, w):
if x == w or x == w - 1:
self.cx.append(0)
else:
self.cx.append(v ** (x + 1) * (self.lx[x] - self.lx[x + 1]))
# define mx
for m in range(0, w):
self.mx.append(sum(self.cx[m:-1]))
[docs]
def calculate_eti_duration(
qx: list,
issue_age: int,
interest_rate: float,
face_amount: float,
surrender_value: float,
):
cf = CommutationFunctions(mortality_table=qx, interest_rate=interest_rate)
# solve for the eti_duration based on the nsp value at each year from the issue_age
nsp = []
for i in range(1, 120 - issue_age):
nsp_z = (
face_amount
* (cf.mx[issue_age] - cf.mx[issue_age + i])
/ cf.dx[issue_age + i]
)
nsp.append(nsp_z)
if nsp_z >= surrender_value:
break # break here
year = max(0, len(nsp) - 1)
# linear interpolation method
days = int(365.00 * (surrender_value - nsp[year - 1]) / (nsp[year] - nsp[year - 1]))
# round up method. if more than half a day then make it to the next day
days = round(days + 0.5)
return {
"Year": year,
"Days": days,
}