def __init__(self, date_of_valuation, date_of_birth, date_of_entry, age_of_term_cost, multi_table=None, decrement=None, i=None, age_first_instalment=None, age_last_instalment=None, age_first_payment=None): ''' Creates an instance of a Present Value of a Term Cost object. This object will allow us to get an hold in all the information necessary to compute everything we need to valuate actuarial liabilities. :param date_of_valuation: date of valuation :param date_of_birth: date of birth :param date_of_entry: date of entry :param age_of_term_cost: date of the first payment of the term cost :param multi_table: the net table, that is, the multidecrement table used :param decrement: the decrement that originates the payment :param i: the technical rate of interest :param age_first_instalment: how many periods we wait, after entry age, until the first instalment to start amortizing the term cost :param age_last_instalment: how many periods we wait, after entry age, until the last instalment to finish amortizing the term cost :param age_first_payment: how many periods, after the age of the term cost, until the first payment of the term cost ''' self.date_of_valuation = date_of_valuation self.date_of_birth = date_of_birth self.date_of_entry = date_of_entry self.age_of_term_cost = age_of_term_cost self.multi_table = multi_table self.decrement = decrement self.i = i / 100, self.v = 1 / (1 + i / 100) self.age_first_instalment = None self.age_last_instalment = None self.age_first_payment = None self.age_date_of_entry = age.Age(date1=date_of_birth, date2=date_of_entry) self.age_date_of_valuation = age.Age(date1=self.date_of_birth, date2=self.date_of_valuation) self.x = self.age_date_of_valuation.age_act() self.y_ = self.age_date_of_entry.age_f()[3] self.y = int(np.ceil(self.y_)) self.past_time_service_years = self.x - self.y self.future_time_service_years = self.age_of_term_cost - self.x self.total_time_service_years = self.age_of_term_cost - self.y self.waiting = None
def __create_dates_ages(self): ''' Creates all dates and ages from y to the age of the first payment ''' # careful when counting years because of the actuarial ages dates_ages_past = [(age.Age( date1=self.date_of_valuation, date2=self.date_of_valuation).date_inc_years(-j).date2.year, self.x - j) for j in range(self.past_time_service_years + 1)] dates_ages_future = [ (age.Age( date1=self.date_of_valuation, date2=self.date_of_valuation).date_inc_years(j).date2.year, self.x + j) for j in range(1, self.future_time_service_years + self.waiting + 1) ] self.dates_ages = dates_ages_past[::-1] + dates_ages_future
def set_dates_ages_w(self): ''' Creates all dates and ages from y to the largest w, expectedly the mortality table's w. ''' # careful when counting years because of the actuarial ages max_w = [t[1].w for t in self.multi_table.unidecrement_tables.items()] max_w = max(max_w) dates_ages_w = [ (age.Age( date1=self.date_of_valuation, date2=self.date_of_valuation).date_inc_years(j).date2.year, self.x + j) for j in range(-self.past_time_service_years, max_w - self.x + 1) ] self.__dates_ages_w = dates_ages_w
ekv80 = dt.EVK_80 ekv80_70 = dt.EVK_80_ext_70 pcr1 = tt.pcr_turnover pcr2 = tt.pcr_turnover_65 mt_GRF95 = mt.MortalityTable(mt=soa_GRF95.table_qx) mt_TV7377 = mt.MortalityTable(mt=soa_TV7377.table_qx) dt_ekv80 = mt.MortalityTable(mt=ekv80, last_q=0) tt_pcr = mt.MortalityTable(mt=pcr1, last_q=0) tables_unidecrement = {'mortality': mt_TV7377, 'disability': dt_ekv80, 'turnover': tt_pcr} tables_multidecrement = mdt(dict_tables=tables_unidecrement) tables_multidecrement.create_udd_multidecrement_table() dict_dates = {'date_of_birth': '1977-03-12', 'date_of_entry': '1997-05-15'} date_of_valuation = '2019-12-31' dates_for_term_cost = age.Age(date1=dict_dates['date_of_birth'], date2=dict_dates['date_of_birth']).date_inc_years(55) age_term_cost_years = dates_for_term_cost.age_act() pvfb_d = pvftc.PVTermCost(date_of_valuation=date_of_valuation, date_of_birth=dict_dates['date_of_birth'], date_of_entry=dict_dates['date_of_entry'], age_of_term_cost=age_term_cost_years, waiting=0, multi_table=tables_multidecrement, decrement='disability', i=2) series_pvftc_d = pvfb_d.series_pvftc_path_proj(atc_initial=25, atc_final=65, x=None) ''' PUC ''' series_puc_d_puc = pvfb_d.series_Projected_Unit_Credit(atc_initial=15, atc_final=65, x=None, waiting_after_y=0, waiting_before_atc=1)
tt_pcr = mt.MortalityTable(mt=pcr1, last_q=0) tables_unidecrement = { 'mortality': mt_TV7377, 'disability': dt_ekv80, 'turnover': tt_pcr } tables_multidecrement = mdt(dict_tables=tables_unidecrement) tables_multidecrement.create_udd_multidecrement_table() dict_dates = {'date_of_birth': '1977-03-12', 'date_of_entry': '1997-05-15'} date_of_valuation = '2019-12-31' dates_for_term_cost = age.Age( date1=dict_dates['date_of_birth'], date2=dict_dates['date_of_birth']).date_inc_years(55) age_term_cost_years = dates_for_term_cost.age_act() pvfb_d = pvtermcost.PVTermCost(date_of_valuation=date_of_valuation, date_of_birth=dict_dates['date_of_birth'], date_of_entry=dict_dates['date_of_entry'], age_of_term_cost=age_term_cost_years, multi_table=tables_multidecrement, decrement='disability', i=2, age_first_instalment=None, age_last_instalment=None, age_first_payment=None) pvfb_d.set_default_waiting_periods()
def set_age_date_of_entry(self): self.__age_date_of_entry = age.Age(self.__date_of_birth, self.__date_of_entry)
def set_age_date_of_valuation(self): self.__age_date_of_valuation = age.Age(self.__date_of_birth, self.__date_of_valuation)
__author__ = "PedroCR" from essential_life import age import datetime from dateutil.relativedelta import relativedelta import pandas as pd sd = '1956-12-24' sd2 = '1841-03-02' sd3 = '2000/04-23' d1 = datetime.date(2000, 4, 23) d2 = datetime.date(2002, 7, 18) a = age.Age(d1, d2) print( f"Age for {a} is {a.age_f()[0]} years, {a.age_f()[1]} months and {a.age_f()[2]} days," f" that is, {a.age_f()[3]} years") d1 = datetime.date(1968, 2, 14) d2 = datetime.datetime.now() print(relativedelta(d2, d1)) a = age.Age(d1, d2) print( f"Age for {a} is {a.age_f()[0]} years, {a.age_f()[1]} months and {a.age_f()[2]} days," f" that is, {a.age_f()[3]} years") d1 = "1968-02-14" d2 = datetime.date.today() print(a.age_f()) print('actuarial age:', a.age_act()) print((pd.to_datetime(d2) - pd.to_datetime(d1)))
def default_waiting_periods(date_of_entry, date_of_term_cost): waiting_first_instalment = 0 waiting_last_instalment = age.Age(date1=date_of_entry, date2=date_of_term_cost).age_act() - 1 waiting_first_payment = 0 return waiting_first_instalment, waiting_last_instalment, waiting_first_payment
def __init__(self, date_of_valuation, date_of_birth, date_of_entry, date_of_term_cost, multi_table=None, decrement=None, i=None, waiting_first_instalment=None, waiting_last_instalment=None, waiting_first_payment=None): ''' Creates an instance of a Projected Unit Credit amortization scheme :param date_of_valuation: date of valuation :param date_of_birth: date of birth :param date_of_entry: date of entry :param date_of_term_cost: date of the first payment of the term cost :param multi_table: the net table, that is, the multidecrement table used :param decrement: the decrement that originates the payment :param i: the technical rate of interest :param waiting_first_instalment: how many periods we wait, after entry age, until the first instalment to start amortizing the term cost :param waiting_last_instalment: how many periods we wait, after entry age, until the last instalment to finish amortizing the term cost :param waiting_first_payment: how many periods, after the age of the term cost, until the first payment of the term cost ''' self.i = i / 100 self.v = 1 / (1 + self.i) self.date_of_valuation = date_of_valuation self.date_of_birth = date_of_birth self.date_of_entry = date_of_entry self.date_of_term_cost = date_of_term_cost self.multi_table = multi_table self.decrement = decrement self.waiting_first_instalment = waiting_first_instalment self.waiting_last_instalment = waiting_last_instalment self.waiting_first_payment = waiting_first_payment self.age_x = age.Age(date1=date_of_birth, date2=date_of_valuation) self.age_at_entry = age.Age(date1=date_of_birth, date2=date_of_entry) self.past_time_service = age.Age(date1=date_of_entry, date2=date_of_valuation) self.future_time_service = age.Age(date1=date_of_valuation, date2=date_of_term_cost) self.total_time_service = age.Age(date1=date_of_entry, date2=date_of_term_cost) self.y = self.age_at_entry.age_act() self.x = self.age_x.age_act() self.z = age.Age(date1=date_of_birth, date2=date_of_term_cost).age_act() self.past_time_service_years = self.past_time_service.age_act() self.future_time_service_years = self.future_time_service.age_act() self.total_time_service_years = self.total_time_service.age_act() # careful when counting years because of the actuarial ages self.ages_dates = [(self.x + j, self.age_x.date2.year + j) for j in range(self.z - self.x + 1)] self.ages_dates_all = [(self.ages_dates[0][0] - j, self.ages_dates[0][1] - j) for j in range(1, self.x - self.y)] self.ages_dates_all.reverse() self.ages_dates_all = self.ages_dates_all + self.ages_dates
# tt_pcr.force_qw_0() tables_unidecrement = { 'mortality': mt_TV7377, 'disability': dt_ekv80, 'turnover': tt_pcr } tables_multidecrement = mdt(dict_tables=tables_unidecrement) tables_multidecrement.create_udd_multidecrement_table() dict_dates = {'date_of_birth': '1977-03-12', 'date_of_entry': '1997-05-15'} date_of_valuation = '2019-12-31' dict_ages = dict() for k_d, v_d in dict_dates.items(): new_age = age.Age(date1=v_d, date2=date_of_valuation) dict_ages[k_d.replace('date_of', 'age_at')] = new_age.age_act() age_cost = age.Age(date1=dict_dates['date_of_entry'], date2=dict_dates['date_of_entry']).date_inc_years(40) age_cost_2 = age.Age(date1=dict_dates['date_of_birth'], date2=dict_dates['date_of_birth']).date_inc_years(55) print(dict_ages) print('date_at_term_cost:', age_cost.date2, 'or', age_cost_2.date2) max_date = min(age_cost.date2, age_cost_2.date2) print('the oldest date is:', max_date) # PUC print('\n') print('Testing for Desability')