def run_fa_acct_iter(self): raw_input = { "Acct Value": 1344581.6, "Attained Age": 52.8, "DB Rider Name": "Step-up", "WB Rider Name": "PP", "ID": "000001", "Issue Age": 45.1, "Issue Date": dt.date(2005, 6, 22), "Initial Date": dt.date(2013, 2, 1), "Maturity Age": 90, "Population": 1, "Riders": dict({}), "ROP Amount": 1038872.0, "Gender": "F", "RPB": 1038872.0, "Free Withdrawal Rate": 0.1, "Asset Names": ["Credit Account"], "Asset Values": [1344581.6] } # For now, we assume the init_date is month begin step_per_year = 12 credit_rate = 0.03 periods = 360 init_date = dt.date(2013, 2, 1) # Set up the investment index credit_rider = isr.InsCreditRateFixed(credit_rate) # Set up non-rider fees annual_fee_rate = 0.01 annual_booking_fee = 100 mgmt_fee = mif.InsFeeProp(annual_fee_rate, fee_name="Mgmt Fee") booking_fee = mif.InsFeeConst(annual_booking_fee, fee_name="Booking Fee") fees = [mgmt_fee, booking_fee] # Set up rider db_rider_fee_rate = 0.005 db_rider = mir.InsRiderDB(extract_strict(raw_input, "ROP Amount"), db_rider_fee_rate, rider_name="UWL") riders = [db_rider] # Setup investment index inv_index = credit_rider.inv_index(init_date, periods, step_per_year) # Setup iteration product = InsProduct(riders, fees, inv_index) acct = InsAcct(raw_input, product) acct_iter = acct.acct_iterator() # model iterator to evolve the model_iter to move forward time_line = pd.date_range(init_date, periods=60, freq='3MS').date rs = { 'Account Value': [], 'UWL Benefit Base': [], 'UWL Fee': [], 'UWL Benefit': [], 'Mgmt Fee': [], 'Booking Fee': [], 'Date': [], 'Age': [], 'Pre Fee Acct': [], 'Anniv Flag': [] } for d in time_line: if d == init_date: rs['Account Value'].append(acct_iter.acct_value) rs['UWL Fee'].append(acct_iter.rider_fee("UWL")) rs['Date'].append(acct_iter.date) rs['Age'].append(acct_iter.attained_age) rs['Booking Fee'].append( acct_iter.non_rider_fee("Booking Fee")) rs['Mgmt Fee'].append(acct_iter.non_rider_fee('Mgmt Fee')) rs['UWL Benefit'].append(acct_iter.rider_benefit('UWL')) rs['UWL Benefit Base'].append( acct_iter.rider_benefit_base('UWL')) rs['Pre Fee Acct'].append(acct_iter.acct_value_pre_fee) rs['Anniv Flag'].append(acct_iter.anniv_flag) else: acct_iter.next(d) rs['Account Value'].append(acct_iter.acct_value) rs['UWL Fee'].append(acct_iter.rider_fee("UWL")) rs['Date'].append(acct_iter.date) rs['Age'].append(acct_iter.attained_age) rs['Booking Fee'].append( acct_iter.non_rider_fee("Booking Fee")) rs['Mgmt Fee'].append(acct_iter.non_rider_fee('Mgmt Fee')) rs['UWL Benefit'].append(acct_iter.rider_benefit('UWL')) rs['UWL Benefit Base'].append( acct_iter.rider_benefit_base('UWL')) rs['Pre Fee Acct'].append(acct_iter.acct_value_pre_fee) rs['Anniv Flag'].append(acct_iter.anniv_flag) df = pd.DataFrame.from_dict(rs) df.set_index(['Date'], inplace=True) df['Anniv Flag'] = df['Anniv Flag'].astype(int) return df
def run_va_model(self): raw_input = {"Acct Value": 1344581.6, "Attained Age": 52.8, "ID": "000001", "Issue Age": 45.1, "Issue Date": dt.date(2005, 6, 22), "Initial Date": dt.date(2013, 2, 1), "Maturity Age": 90, "Population": 1, "Riders": dict({}), "ROP Amount": 1038872.0, "Gender": "F", "RPB": 1038872.0, "Free Withdrawal Rate": 0.1, "Asset Names": ["Fund A", "Fund B"], "Asset Values": [1344581.6/2, 1344581.6/2]} # For now, we assume the init_date is month begin step_per_year = 12 periods = 360 init_date = dt.date(2013, 2, 1) pricing_date = init_date # Set up the investment index #credit_rider = isr.InsCreditRateFixed(credit_rate) # set up the mutual fund return index init_df = [ pd.TimeSeries(data=[100], index=[init_date], name='stock A'), pd.TimeSeries(data=[100], index=[init_date], name='stock B') ] eq_index = [ip.IndexProvider(init_df[0], 'stock A'), ip.IndexProvider(init_df[1], 'stock B')] # no vol, otherwise randomness will break my test sim_engine = EqBSEngine(np.array([0.02, 0.02]), np.array([0.0, 0.0]), corr=np.array([[1., 0.3], [0.3, 1.]])) simulator = ScenarioGenerator(eq_index, sim_engine, **{'max_time_step': 5. / BDAYS_PER_YEAR}) MARKET_DATA_MANAGER.reset() MARKET_DATA_MANAGER.setup(init_date) MARKET_DATA_MANAGER.index_table[ 'stock A'] = eq_index[0] MARKET_DATA_MANAGER.index_table[ 'stock B'] = eq_index[1] MARKET_DATA_MANAGER.scen_gen_table['stock A']=simulator MARKET_DATA_MANAGER.scen_gen_table['stock B']=simulator fund_info = {'Fund A': { 'Allocations': { 'stock A': 1, 'stock B': 0, }, 'Management Fee': 0.01, 'Description': 'blah blah', }, 'Fund B': { 'Allocations': { 'stock A': 0, 'stock B': 1, }, 'Management Fee': 0.01, 'Description': 'blah blah', }, } credit_rider = isr.InsCreditRateMutualFunds(fund_info=fund_info) # Set up non-rider fees annual_fee_rate = 0.01 annual_booking_fee = 100 mgmt_fee = mif.InsFeeProp(annual_fee_rate, fee_name="Mgmt Fee") booking_fee = mif.InsFeeConst(annual_booking_fee, fee_name="Booking Fee") fees = [mgmt_fee, booking_fee] # Set up rider db_rider_fee_rate = 0.005 db_rider = mir.InsRiderDB(extract_strict(raw_input, "ROP Amount"), db_rider_fee_rate, rider_name="UWL") riders = [db_rider] # Setup investment index inv_index = credit_rider.inv_index(init_date, periods, step_per_year) # Setup iteration product = InsProduct(riders, fees, inv_index) acct = InsAcct(raw_input, product) acct_iter = acct.acct_iterator() # Setup lapse function and lapse model xs = [0] ys = [0.0, 0.1] shock_func = linear_comp_bounded(1, 0, floor=0.5, cap=1.5) lapse_model = LapseDynamic(InsStepFunc(xs, ys), shock_func, rider_name='UWL') # Setup surrender charge xs = [0] ys = [100, 100] fixed_charge_func = InsStepFunc(xs, ys) xs = [0, 1, 2] ys = [0.0, 0.3, 0.2, 0.0] pct_charge_func = InsStepFunc(xs, ys) surrender_charge = SurrenderCharge(fixed_charge_func, pct_charge_func) # Setup mortality function and mortality model xs = [x for x in range(0, 100)] ys = [0.01] * 100 ys.append(float('inf')) mort_model = InsMortModel(InsStepFunc(xs, ys)) # Setup VA Model model = InsModelVA(acct, lapse_model, mort_model, surrender_charge) model_iter = model.create_iterator(pricing_date) # model iterator to evolve the model_iter to move forward metrics = ['Account Value', 'Active Population', 'Benefit Base.UWL', 'Rider Fee.UWL', 'Benefit.UWL', 'Fee.Mgmt Fee', 'Fee.Booking Fee', 'Date', 'Attained Age', 'Anniv Flag', 'Death', 'Lapse', 'Paid Benefit.UWL', 'Surrender Charge', ] crv_aggregator = create_curve_aggregator(metrics) params = {'pricing date': init_date, 'periods': 60, 'frequency': 'MS'} proj_mgr = ProjectionManager(crv_aggregator, model_iter, **params) proj_mgr.run() df = crv_aggregator.to_dataframe() # df[['Rider Fee.UWL', 'Fee.Mgmt Fee', 'Fee.Booking Fee', 'Surrender Charge']].plot(kind='bar', stacked=True) return df
def run_fa_model(self): raw_input = { "Acct Value": 1344581.6, "Attained Age": 52.8, "ID": "000001", "Issue Age": 45.1, "Issue Date": dt.date(2005, 6, 22), "Initial Date": dt.date(2013, 2, 1), "Maturity Age": 90, "Population": 1, "Riders": dict({}), "ROP Amount": 1038872.0, "Gender": "F", "RPB": 1038872.0, "Free Withdrawal Rate": 0.1, "Asset Names": ["Credit Account"], "Asset Values": [1344581.6] } # For now, we assume the init_date is month begin step_per_year = 12 credit_rate = 0.03 periods = 360 init_date = dt.date(2013, 2, 1) pricing_date = init_date # Set up the investment index credit_rider = isr.InsCreditRateFixed(credit_rate) # Set up non-rider fees annual_fee_rate = 0.01 annual_booking_fee = 100 mgmt_fee = mif.InsFeeProp(annual_fee_rate, fee_name="Mgmt Fee") booking_fee = mif.InsFeeConst(annual_booking_fee, fee_name="Booking Fee") fees = [mgmt_fee, booking_fee] # Set up rider db_rider_fee_rate = 0.005 db_rider = mir.InsRiderDB(extract_strict(raw_input, "ROP Amount"), db_rider_fee_rate, rider_name="UWL") riders = [db_rider] # Setup investment index inv_index = credit_rider.inv_index(init_date, periods, step_per_year) # Setup iteration product = InsProduct(riders, fees, inv_index) acct = InsAcct(raw_input, product) # Setup lapse function and lapse model xs = [0] ys = [0.0, 0.1] lapse_model = LapseStatic(InsStepFunc(xs, ys)) # Setup surrender charge xs = [0] ys = [100, 100] fixed_charge_func = InsStepFunc(xs, ys) xs = [0, 1, 2] ys = [0.0, 0.3, 0.2, 0.0] pct_charge_func = InsStepFunc(xs, ys) surrender_charge = SurrenderCharge(fixed_charge_func, pct_charge_func) # Setup mortality function and mortality model xs = [x for x in range(0, 100)] ys = [0.01] * 100 ys.append(float('inf')) mort_model = InsMortModel(InsStepFunc(xs, ys)) # Setup FA Model model = InsModelFA(acct, lapse_model, mort_model, surrender_charge) model_iter = model.create_iterator(pricing_date) # model iterator to evolve the model_iter to move forward metrics = [ 'Account Value', 'Active Population', 'Benefit Base.UWL', 'Rider Fee.UWL', 'Benefit.UWL', 'Fee.Mgmt Fee', 'Fee.Booking Fee', 'Date', 'Attained Age', 'Anniv Flag', 'Death', 'Lapse', 'Paid Benefit.UWL', 'Surrender Charge', ] crv_aggregator = create_curve_aggregator(metrics) time_line = pd.date_range(init_date, periods=60, freq='MS').date prev_date = init_date for d in time_line: if d != init_date: year_frac = (d - prev_date).days / DAYS_PER_YEAR model_iter.next(d, year_frac) crv_aggregator.collect_element(model_iter) prev_date = d df = crv_aggregator.to_dataframe() return df
"Asset Values": [1344581.6] } # For now, we assume the init_date is month begin step_per_year = 12 credit_rate = 0.03 periods = 360 init_date = dt.date(2013, 2, 1) pricing_date = init_date # Set up the investment index credit_rider = isr.InsCreditRateFixed(credit_rate) # Set up non-rider fees annual_fee_rate = 0.01 annual_booking_fee = 100 mgmt_fee = mif.InsFeeProp(annual_fee_rate, fee_name="Mgmt Fee") booking_fee = mif.InsFeeConst(annual_booking_fee, fee_name="Booking Fee") fees = [mgmt_fee, booking_fee] # Set up rider db_rider_fee_rate = 0.005 db_rider = mir.InsRiderDB(extract_strict(raw_input, "ROP Amount"), db_rider_fee_rate, rider_name="UWL") riders = [db_rider] # Setup investment index inv_index = credit_rider.inv_index(init_date, periods, step_per_year) # Setup iteration product = InsProduct(riders, fees, inv_index)
# --- Create a new product family ---------- # parameters, TODO: all these redundant info are due to the current way of creating index! step_per_year = 12 periods = 360 init_date = dt.date(2013, 2, 1) pricing_date = init_date # Dummy place holder TBD = 0.0 # riders db_rider = mir.InsRiderDB(rider_name="UWL") riders = [db_rider] # fees mgmt_fee = mif.InsFeeProp(fee_name="Mgmt Fee") booking_fee = mif.InsFeeConst(fee_name="Booking Fee") fees = [mgmt_fee, booking_fee] # inv_index, Todo: This part is nasty since the index is 'hard' created for now. Once the logic of searching from # database is set up, this should be much better. credit_rider = isr.InsCreditRateFixed() # define the product family class FASample(InsProduct): def __init__(self, default_params): self._default_params = default_params self._riders = riders self._riders[0].set_fee_rate(default_params.get('DB Rider Fee Rate'))