diff --git a/lifelib/libraries/savings/CashValue_ME_EX4/Projection/__init__.py b/lifelib/libraries/savings/CashValue_ME_EX4/Projection/__init__.py index 129aab6..599a5f3 100644 --- a/lifelib/libraries/savings/CashValue_ME_EX4/Projection/__init__.py +++ b/lifelib/libraries/savings/CashValue_ME_EX4/Projection/__init__.py @@ -1205,7 +1205,7 @@ def mort_rate(t): # return mort_table_reindexed().reindex( # mi, fill_value=0).set_axis(model_point().index, inplace=False) - return pd.Series(0, index=model_point().index).values + return np.zeros(len(model_point().index)) def mort_rate_mth(t): @@ -1431,7 +1431,7 @@ def pols_new_biz(t): * :func:`model_point` """ - return model_point()['policy_count'].where(duration_mth(t) == 0, other=0).values + return model_point()['policy_count'].values * (duration_mth(t) == 0) def prem_to_av(t): @@ -1491,11 +1491,8 @@ def premium_pp(t): # model_point().index, inplace=False) # return np.around(sum_assured() * prem_rates, 2) - sp = model_point()['premium_pp'].where((premium_type() == 'SINGLE') & (duration_mth(t) == 0), other=0).values - lp = model_point()['premium_pp'].where( - (premium_type() == 'LEVEL') & (duration_mth(t) < 12 * policy_term()), - other=0).values - return sp + lp + return model_point()['premium_pp'].values * ((premium_type() == 'SINGLE') & (duration_mth(t) == 0) | + (premium_type() == 'LEVEL') & (duration_mth(t) < 12 * policy_term())) def premium_type(): @@ -1900,9 +1897,12 @@ def surr_charge_rate(t): * :func:`surr_charge_max_idx` * :func:`surr_charge_table_stacked` """ - ind_row = surr_charge_table.index.searchsorted(np.minimum(duration(t), surr_charge_max_idx()), side='right') - 1 - ind_col = surr_charge_table.columns.searchsorted(surr_charge_id(), side='right') - 1 # TODO: not clear how it should work with has_surr_charge() - return surr_charge_table.values.flat[ind_col + ind_row * len(surr_charge_table.columns)] + ind_row = np.minimum(duration(t), surr_charge_max_idx()) + return surr_charge_table.values.flat[surr_charge_table_column() + ind_row * len(surr_charge_table.columns)] + + +def surr_charge_table_column(): + return surr_charge_table.columns.searchsorted(surr_charge_id(), side='right') - 1 def surr_charge_table_stacked(): diff --git a/lifelib/libraries/savings/savings_example4.ipynb b/lifelib/libraries/savings/savings_example4.ipynb index ed1ad85..f966ddd 100644 --- a/lifelib/libraries/savings/savings_example4.ipynb +++ b/lifelib/libraries/savings/savings_example4.ipynb @@ -41,7 +41,7 @@ { "data": { "text/plain": [ - "1.2689610000234097" + "1.2499775000000004" ] }, "execution_count": 3, @@ -82,7 +82,7 @@ { "data": { "text/plain": [ - "0.526920499978587" + "0.2862044000000008" ] }, "execution_count": 6, @@ -149,7 +149,7 @@ { "data": { "text/plain": [ - "7.84547259984538" + "8.0889741" ] }, "execution_count": 9, @@ -190,7 +190,7 @@ { "data": { "text/plain": [ - "3.8828028000425547" + "2.3929682999999997" ] }, "execution_count": 12, @@ -295,70 +295,70 @@ " \n", " \n", " surr_charge_rate(t)\n", - " 0.626154\n", - " 36.491786\n", + " 0.697034\n", + " 39.238824\n", " \n", " \n", " inv_return_mth(t)\n", - " 0.291798\n", - " 17.005771\n", + " 0.338032\n", + " 19.029207\n", " \n", " \n", " premium_pp(t)\n", - " 0.206414\n", - " 12.029663\n", + " 0.146663\n", + " 8.256274\n", " \n", " \n", - " claim_pp(t, kind)\n", - " 0.077510\n", - " 4.517216\n", + " pols_new_biz(t)\n", + " 0.069975\n", + " 3.939195\n", " \n", " \n", - " claims(t, kind)\n", - " 0.063502\n", - " 3.700866\n", + " inv_income_pp(t)\n", + " 0.069556\n", + " 3.915600\n", " \n", " \n", - " pols_if_at(t, timing)\n", - " 0.038705\n", - " 2.255718\n", + " claims(t, kind)\n", + " 0.064405\n", + " 3.625641\n", " \n", " \n", - " av_pp_at(t, timing)\n", - " 0.034805\n", - " 2.028384\n", + " expenses(t)\n", + " 0.035827\n", + " 2.016841\n", " \n", " \n", - " inv_return_table()\n", - " 0.031250\n", - " 1.821226\n", + " pols_maturity(t)\n", + " 0.032865\n", + " 1.850092\n", " \n", " \n", - " expenses(t)\n", - " 0.029133\n", - " 1.697868\n", + " claim_pp(t, kind)\n", + " 0.032804\n", + " 1.846696\n", " \n", " \n", - " inv_income(t)\n", - " 0.027631\n", - " 1.610330\n", + " prem_to_av_pp(t)\n", + " 0.031291\n", + " 1.761523\n", " \n", " \n", "\n", "" ], "text/plain": [ - " duration dur_perc\n", - "surr_charge_rate(t) 0.626154 36.491786\n", - "inv_return_mth(t) 0.291798 17.005771\n", - "premium_pp(t) 0.206414 12.029663\n", - "claim_pp(t, kind) 0.077510 4.517216\n", - "claims(t, kind) 0.063502 3.700866\n", - "pols_if_at(t, timing) 0.038705 2.255718\n", - "av_pp_at(t, timing) 0.034805 2.028384\n", - "inv_return_table() 0.031250 1.821226\n", - "expenses(t) 0.029133 1.697868\n", - "inv_income(t) 0.027631 1.610330" + " duration dur_perc\n", + "surr_charge_rate(t) 0.697034 39.238824\n", + "inv_return_mth(t) 0.338032 19.029207\n", + "premium_pp(t) 0.146663 8.256274\n", + "pols_new_biz(t) 0.069975 3.939195\n", + "inv_income_pp(t) 0.069556 3.915600\n", + "claims(t, kind) 0.064405 3.625641\n", + "expenses(t) 0.035827 2.016841\n", + "pols_maturity(t) 0.032865 1.850092\n", + "claim_pp(t, kind) 0.032804 1.846696\n", + "prem_to_av_pp(t) 0.031291 1.761523" ] }, "execution_count": 15, @@ -415,54 +415,54 @@ " \n", " \n", " \n", - " surr_charge_rate(t)\n", - " 0.204015\n", - " 37.341396\n", + " premium_pp(t)\n", + " 0.033878\n", + " 10.744304\n", " \n", " \n", - " premium_pp(t)\n", - " 0.115471\n", - " 21.134984\n", + " mort_rate_mth(t)\n", + " 0.032263\n", + " 10.231875\n", " \n", " \n", - " pv_claims(kind)\n", - " 0.031336\n", - " 5.735535\n", + " surr_charge_rate(t)\n", + " 0.024496\n", + " 7.768857\n", " \n", " \n", - " inv_return_table()\n", - " 0.023608\n", - " 4.320994\n", + " duration(t)\n", + " 0.019624\n", + " 6.223781\n", " \n", " \n", - " lapse_rate(t)\n", - " 0.022686\n", - " 4.152201\n", + " inv_return_table()\n", + " 0.018503\n", + " 5.868249\n", " \n", " \n", - " prem_to_av_pp(t)\n", - " 0.018686\n", - " 3.420122\n", + " pv_claims(kind)\n", + " 0.018216\n", + " 5.776984\n", " \n", " \n", - " av_change(t)\n", - " 0.016086\n", - " 2.944244\n", + " claims(t, kind)\n", + " 0.018125\n", + " 5.748327\n", " \n", " \n", - " commissions(t)\n", - " 0.015623\n", - " 2.859585\n", + " av_at(t, timing)\n", + " 0.016349\n", + " 5.185010\n", " \n", " \n", - " premiums(t)\n", - " 0.015507\n", - " 2.838290\n", + " prem_to_av_pp(t)\n", + " 0.015626\n", + " 4.955751\n", " \n", " \n", - " std_norm_rand()\n", - " 0.012620\n", - " 2.309915\n", + " pols_new_biz(t)\n", + " 0.015588\n", + " 4.943653\n", " \n", " \n", "\n", @@ -470,16 +470,16 @@ ], "text/plain": [ " duration dur_perc\n", - "surr_charge_rate(t) 0.204015 37.341396\n", - "premium_pp(t) 0.115471 21.134984\n", - "pv_claims(kind) 0.031336 5.735535\n", - "inv_return_table() 0.023608 4.320994\n", - "lapse_rate(t) 0.022686 4.152201\n", - "prem_to_av_pp(t) 0.018686 3.420122\n", - "av_change(t) 0.016086 2.944244\n", - "commissions(t) 0.015623 2.859585\n", - "premiums(t) 0.015507 2.838290\n", - "std_norm_rand() 0.012620 2.309915" + "premium_pp(t) 0.033878 10.744304\n", + "mort_rate_mth(t) 0.032263 10.231875\n", + "surr_charge_rate(t) 0.024496 7.768857\n", + "duration(t) 0.019624 6.223781\n", + "inv_return_table() 0.018503 5.868249\n", + "pv_claims(kind) 0.018216 5.776984\n", + "claims(t, kind) 0.018125 5.748327\n", + "av_at(t, timing) 0.016349 5.185010\n", + "prem_to_av_pp(t) 0.015626 4.955751\n", + "pols_new_biz(t) 0.015588 4.943653" ] }, "execution_count": 16, @@ -529,28 +529,33 @@ " \n", " \n", " surr_charge_rate(t)\n", - " 0.626154\n", - " 0.204015\n", + " 0.697034\n", + " 0.024496\n", " \n", " \n", " inv_return_mth(t)\n", - " 0.291798\n", - " 0.002037\n", + " 0.338032\n", + " 0.000000\n", " \n", " \n", " premium_pp(t)\n", - " 0.206414\n", - " 0.115471\n", + " 0.146663\n", + " 0.033878\n", " \n", " \n", - " claim_pp(t, kind)\n", - " 0.077510\n", - " 0.002008\n", + " pols_new_biz(t)\n", + " 0.069975\n", + " 0.015588\n", + " \n", + " \n", + " inv_income_pp(t)\n", + " 0.069556\n", + " 0.015507\n", " \n", " \n", " claims(t, kind)\n", - " 0.063502\n", - " 0.000000\n", + " 0.064405\n", + " 0.018125\n", " \n", " \n", "\n", @@ -558,11 +563,12 @@ ], "text/plain": [ " df1 df4\n", - "surr_charge_rate(t) 0.626154 0.204015\n", - "inv_return_mth(t) 0.291798 0.002037\n", - "premium_pp(t) 0.206414 0.115471\n", - "claim_pp(t, kind) 0.077510 0.002008\n", - "claims(t, kind) 0.063502 0.000000" + "surr_charge_rate(t) 0.697034 0.024496\n", + "inv_return_mth(t) 0.338032 0.000000\n", + "premium_pp(t) 0.146663 0.033878\n", + "pols_new_biz(t) 0.069975 0.015588\n", + "inv_income_pp(t) 0.069556 0.015507\n", + "claims(t, kind) 0.064405 0.018125" ] }, "execution_count": 17, @@ -593,7 +599,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.10.6" + "version": "3.9.7" } }, "nbformat": 4,