def qx12_fd_m(self): values = [''] for step in range(self.step_size, self.step_until, self.step_size): values.append( look_for_in_df(self.df, 'qx_m', step) + look_for_in_df(self.df, 'qx2_m', step) - look_for_in_df(self.df, 'qx_m', step) * look_for_in_df(self.df, 'qx2_m', step)) self.df['qx12_fd_m'] = values
def index_infl_m(self): values = [1] result = 1 for step in range(self.step_size, self.step_until, self.step_size): result *= (1 + look_for_in_df(self.df, 'forw_infl_m', step)) values.append(result) self.df['index_infl_m'] = values
def part_percent_m(self): values = [''] for step in range(self.step_size, self.step_until, self.step_size): values.append( 1 - pow(1 - look_for_in_df(self.df, 'part_percent', step), 1 / 12)) self.df['part_percent_m'] = values
def index_infl_m_ren_exp(self): values = [1] result = 1 for step in range(self.step_size, self.step_until, self.step_size): result *= (1 + look_for_in_df(self.df, 'forw_infl_m_ren_exp', step)) values.append(result) self.df = self.df.assign(index_infl_m_ren_exp=values)
def disc_factor_m(self): values = [1] last_value = values[0] for step in range(self.step_size, self.step_until, self.step_size): values.append(last_value / (1 + look_for_in_df(self.df, 'spot_rate_m', step))) last_value = values[step] self.df['disc_factor_m'] = values
def look_for(self, category, line=None, index=None, label=None): """ searching input tables :param category: column names, text :param line: number begins with 1 for non-indexed rows :param index: number begins with 0 for non-indexed rows :param label: text for indexed rows :return: the value for a given category and index/line/label """ result = "Not found" if line: result = look_for_in_df(self.df, category, line - 1) elif index or index == 0: result = look_for_in_df(self.df, category, index) elif label: result = look_for_in_df(self.df, category, label) return result
def paidup_percent(self, policy_number, persistency): values = [''] for step in range(self.step_size, self.step_until, self.step_size): values.append( persistency.look_for( str( math.floor( look_for_in_df(self.df, 'month', step - 1) / 12)), label=(self.product_assumptions.look_for( self.lps_ass_key, label=self.policies.look_for( 'product', line=policy_number)), 'PUP')) / 100) self.df['paidup_percent'] = values
def surr_value(self, policy_number, surrpenalties, fund): if self.product_features.look_for( 'surr value (y/n)', label=self.policies.look_for('product', line=policy_number)) == 0: pass else: values = [] for step in range(self.step_size - 1, self.step_until, self.step_size): values.append(1 - surrpenalties.look_for( str(math.floor( look_for_in_df(self.df, 'month', step) / 12)), label=self.policies.look_for('product', line=policy_number), ) / 100 * (fund.df['capital_fund_value'][step] + fund.df['accumulation_account'][step])) self.df['surr_percent'] = values
def count_live(self, policy_number): count_live = [1.0] last_count_live = count_live[0] count_death = [''] count_surrender = [''] count_paidup = [''] count_critical_illness = [''] count_maturity = [''] for step in range(self.step_size, self.step_until, self.step_size): if self.product_features.look_for('joint life (y/n)', label=self.policies.look_for( 'product', line=policy_number)) == 1: count_death.append( last_count_live * (1 - look_for_in_df(self.df, 'surr_percent_m', step) * self.surrender_timing) * (1 - look_for_in_df(self.df, 'paidup_percent_m', step) * self.surrender_timing) * look_for_in_df(self.df, 'qx12_fd_m', step)) count_surrender.append( last_count_live * (1 - look_for_in_df(self.df, 'qx12_fd_m', step) * self.surrender_timing) * (1 - look_for_in_df(self.df, 'paidup_percent_m', step) * self.surrender_timing) * look_for_in_df(self.df, 'surr_percent_m', step)) elif self.product_features.look_for('joint life (y/n)', label=self.policies.look_for( 'product', line=policy_number)) == 2: count_death.append( last_count_live * (1 - look_for_in_df(self.df, 'surr_percent_m', step) * self.surrender_timing) * (1 - look_for_in_df(self.df, 'paidup_percent_m', step) * self.surrender_timing) * look_for_in_df(self.df, 'qx12_sd_m', step)) count_surrender.append( last_count_live * (1 - look_for_in_df(self.df, 'qx12_sd_m', step) * self.surrender_timing) * (1 - look_for_in_df(self.df, 'paidup_percent_m', step) * self.surrender_timing) * look_for_in_df(self.df, 'surr_percent_m', step)) else: count_death.append( last_count_live * (1 - look_for_in_df(self.df, 'surr_percent_m', step) * self.surrender_timing) * (1 - look_for_in_df(self.df, 'paidup_percent_m', step) * self.surrender_timing) * look_for_in_df(self.df, 'qx_m', step)) count_surrender.append( last_count_live * (1 - look_for_in_df(self.df, 'qx_m', step) * self.surrender_timing) * (1 - look_for_in_df(self.df, 'paidup_percent_m', step) * self.surrender_timing) * look_for_in_df(self.df, 'surr_percent_m', step)) count_paidup.append( last_count_live * (1 - look_for_in_df(self.df, 'surr_percent_m', step) / 2) * (1 - look_for_in_df(self.df, 'qx_m', step) / 2) * look_for_in_df(self.df, 'paidup_percent_m', step)) if self.product_features.look_for('critical illness (y/n)', label=self.policies.look_for( 'product', line=policy_number)) > 0: count_critical_illness.append( last_count_live * (1 - look_for_in_df(self.df, 'surr_percent_m', step) / 2) * (1 - look_for_in_df(self.df, 'qx_m', step) / 2) * (1 - look_for_in_df(self.df, 'paidup_percent_m', step) / 2) * look_for_in_df(self.df, 'qx_ci_m', step)) elif self.product_features.look_for('critical illness (y/n)', label=self.policies.look_for( 'product', line=policy_number)) == 0: pass if self.month == self.policies.look_for('pol_term_y', line=policy_number) * 12: count_maturity.append(count_live[step]) else: pass count_live_value = last_count_live count_live_value -= count_surrender[step] count_live_value -= count_death[step] if self.product_features.look_for('critical illness (y/n)', label=self.policies.look_for( 'product', line=policy_number)) > 0: count_live_value -= count_critical_illness[step] if self.month == self.policies.look_for('pol_term_y', line=policy_number) * 12: count_live_value -= count_maturity[step] count_live_value -= count_paidup[step] count_live.append(count_live_value) last_count_live = count_live[step] self.df['count_surrender'] = count_surrender self.df['count_death'] = count_death if self.product_features.look_for( 'critical illness (y/n)', label=self.policies.look_for('product', line=policy_number)) > 0: self.df['count_critical_illness'] = count_critical_illness if self.month == self.policies.look_for('pol_term_y', line=policy_number) * 12: self.df['count_maturity'] = count_maturity self.df['count_paidup'] = count_paidup self.df['count_live'] = count_live
def qx12_sd_m(self): step_for_calc = 11 values = [''] previous_calc = look_for_in_df(self.df, 'pm_x', 0) + look_for_in_df(self.df, 'pm2_x', 0) \ - look_for_in_df(self.df, 'pm_x', 0) * look_for_in_df(self.df, 'pm2_x', 0) blockPrint() for step in range(self.step_size, self.step_until, self.step_size): try: values.append(1 - ( (look_for_in_df(self.df, 'pm_x', step + step_for_calc) + look_for_in_df(self.df, 'pm2_x', step + step_for_calc) - look_for_in_df(self.df, 'pm_x', step + step_for_calc) * look_for_in_df(self.df, 'pm2_x', step + step_for_calc)) / previous_calc)) previous_calc = look_for_in_df(self.df, 'pm_x', step) + look_for_in_df(self.df, 'pm2_x', step) \ - look_for_in_df(self.df, 'pm_x', step) * look_for_in_df(self.df, 'pm2_x', step) except KeyError: values.append(1) except TypeError: values.append(1) enablePrint() self.df['qx12_sd_m'] = values