"perc" optional variable

84 views
Skip to first unread message

Eduardo Almeida

unread,
Mar 6, 2021, 10:14:55 PM3/6/21
to openactuarial

Hello

I think that instead of replacing the last element in the list when the "perc" variable is different from 100, the code is appending a new element equals to 1000, that means we are adding a new age that doesn't exist to the table.

Concerning the Actuarial and MortalityTable classes, I have the following observation:

Instead of

for val in mt[1:]:
    if end_val < 1000.0:
        end_val = val * perc / 100
        self.qx.append(end_val)

if perc != 100:
    self.qx.append(1000)

It should be:

for val in mt[1:]:
    if end_val < 1000.0:
        end_val = val * perc / 100
        self.qx.append(end_val)

# Replace the last element instead of appending a new one
if perc != 100:
    #self.qx.append(1000)
    self.qx[-1] = 1000

Or (needs testing):

# Multiply every element in the list by "perc / 100" except for the first element
self.qx[-1:] = [val * (perc / 100) for val in mt[1:]]
# Replace the last element in the list by 1000
self.qx[-1] = 1000

"""
It could be

self.qx[-1:] = [val * (perc / 100) for val in mt[1:] if val != 1000]
self.qx.append(1000)

but we would have extra logic here
"""

Regards,

Eduardo



Reply all
Reply to author
Forward
0 new messages