Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 30 additions & 1 deletion lifelib/libraries/assets/generate_bond_data.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,35 @@
"* 1000\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Click the badge below to run this notebook online on Google Colab. You need a Google account and need to be logged in to it to run this notebook on Google Colab.\n",
"[![Run on Google Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/lifelib-dev/lifelib/blob/current/lifelib/libraries/assets/generate_bond_data.ipynb)\n",
"\n",
"\n",
"The next code cell below is relevant only when you run this notebook on Google Colab. It installs lifelib and creates a copy of the library for this notebook."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import sys, os\n",
"\n",
"if 'google.colab' in sys.modules:\n",
" lib = 'assets'; lib_dir = '/content/'+ lib\n",
" if not os.path.exists(lib_dir):\n",
" !pip install lifelib\n",
" !pip install QuantLib\n",
" import lifelib; lifelib.create(lib, lib_dir)\n",
" \n",
" %cd $lib_dir"
]
},
{
"cell_type": "code",
"execution_count": 7,
Expand Down Expand Up @@ -355,7 +384,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.7"
"version": "3.10.13"
}
},
"nbformat": 4,
Expand Down
150 changes: 95 additions & 55 deletions lifelib/libraries/basiclife/create_premium_table.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
"id": "53bfe3af",
"metadata": {},
"source": [
"\n",
"\n",
"This notebook shows how to create the premium table from `BasicTerm_M` model to be used in `BasicTerm_SE` and `BasicTerm_ME`.\n",
"\n",
"To calculate premiums, the present values of claims and annuities need to be taken at the beginning of the policy terms,\n",
Expand All @@ -26,12 +28,50 @@
"* Read the `BasicTerm_M` model.\n",
"* Replace the model point table with the one for the premium table. By default, the premium rates vary only by `age_at_entry` and `policy_term`. The range of `age_at_entry` is 20 to 59, and `policy_term` takes the value of either 10, 15 or 20. The model point data for the premium table is created from the combinations of the two attributes.\n",
"* Calculate per-policy premiums for the model points.\n",
"* Create the premium table by processing the result of the above.\n"
"* Create the premium table by processing the result of the above."
]
},
{
"cell_type": "markdown",
"id": "66e2145f",
"metadata": {},
"source": [
"Click the badge below to run this notebook online on Google Colab. You need a Google account and need to be logged in to it to run this notebook on Google Colab.\n",
"[![Run on Google Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/lifelib-dev/lifelib/blob/current/lifelib/libraries/basiclife/create_premium_table.ipynb)\n",
"\n",
"\n",
"The next code cell below is relevant only when you run this notebook on Google Colab. It installs lifelib and creates a copy of the library for this notebook."
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "ef2f6f0a",
"metadata": {},
"outputs": [],
"source": [
"import sys, os\n",
"\n",
"if 'google.colab' in sys.modules:\n",
" lib = 'basiclife'; lib_dir = '/content/'+ lib\n",
" if not os.path.exists(lib_dir):\n",
" !pip install lifelib\n",
" import lifelib; lifelib.create(lib, lib_dir)\n",
" \n",
" %cd $lib_dir"
]
},
{
"cell_type": "markdown",
"id": "69e7aed3",
"metadata": {},
"source": [
"The next code imports the necessary Python modules."
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "71da5b1f",
"metadata": {},
"outputs": [],
Expand All @@ -51,7 +91,7 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 3,
"id": "cd4d5b2b",
"metadata": {},
"outputs": [],
Expand All @@ -71,7 +111,7 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 4,
"id": "00d461d2",
"metadata": {},
"outputs": [
Expand Down Expand Up @@ -109,67 +149,67 @@
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <td>1</td>\n",
" <th>1</th>\n",
" <td>20</td>\n",
" <td>10</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <td>2</td>\n",
" <th>2</th>\n",
" <td>20</td>\n",
" <td>15</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <td>3</td>\n",
" <th>3</th>\n",
" <td>20</td>\n",
" <td>20</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <td>4</td>\n",
" <th>4</th>\n",
" <td>21</td>\n",
" <td>10</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <td>5</td>\n",
" <th>5</th>\n",
" <td>21</td>\n",
" <td>15</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <td>...</td>\n",
" <th>...</th>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" </tr>\n",
" <tr>\n",
" <td>116</td>\n",
" <th>116</th>\n",
" <td>58</td>\n",
" <td>15</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <td>117</td>\n",
" <th>117</th>\n",
" <td>58</td>\n",
" <td>20</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <td>118</td>\n",
" <th>118</th>\n",
" <td>59</td>\n",
" <td>10</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <td>119</td>\n",
" <th>119</th>\n",
" <td>59</td>\n",
" <td>15</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <td>120</td>\n",
" <th>120</th>\n",
" <td>59</td>\n",
" <td>20</td>\n",
" <td>1</td>\n",
Expand Down Expand Up @@ -197,7 +237,7 @@
"[120 rows x 3 columns]"
]
},
"execution_count": 3,
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -220,7 +260,7 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 5,
"id": "9d4cae36",
"metadata": {},
"outputs": [],
Expand All @@ -239,7 +279,7 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 6,
"id": "7af10c19",
"metadata": {},
"outputs": [
Expand All @@ -265,7 +305,7 @@
" return np.around((1 + loading_prem()) * net_premium_pp(), 2)"
]
},
"execution_count": 5,
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -276,7 +316,7 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 7,
"id": "0eb44b4d",
"metadata": {},
"outputs": [],
Expand All @@ -288,46 +328,46 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 8,
"id": "a2ee55a0",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([4.64097542e-05, 5.20142069e-05, 5.74162410e-05, 4.76584950e-05,\n",
" 5.35875249e-05, 5.93504754e-05, 4.90032815e-05, 5.52810109e-05,\n",
" 6.14332619e-05, 5.04508083e-05, 5.71035347e-05, 6.36761718e-05,\n",
" 5.20083923e-05, 5.90648080e-05, 6.60919024e-05, 5.36840347e-05,\n",
" 6.11754713e-05, 6.86943971e-05, 5.54864901e-05, 6.34471903e-05,\n",
" 7.14989789e-05, 5.74253436e-05, 6.58927638e-05, 7.45224992e-05,\n",
" 5.95110960e-05, 6.85262433e-05, 7.77835053e-05, 6.17552588e-05,\n",
" 7.13630677e-05, 8.13024264e-05, 6.41704608e-05, 7.44202123e-05,\n",
" 8.51017838e-05, 6.67705658e-05, 7.77163572e-05, 8.92064251e-05,\n",
" 6.95708052e-05, 8.12720745e-05, 9.36437881e-05, 7.25879257e-05,\n",
" 8.51100388e-05, 9.84441965e-05, 7.58403545e-05, 8.92552633e-05,\n",
" 1.03641193e-04, 7.93483847e-05, 9.37353646e-05, 1.09271914e-04,\n",
" 8.31343827e-05, 9.85808605e-05, 1.15377512e-04, 8.72230213e-05,\n",
" 1.03825505e-04, 1.22003627e-04, 9.16415414e-05, 1.09506665e-04,\n",
" 1.29200929e-04, 9.64200458e-05, 1.15665745e-04, 1.37025717e-04,\n",
" 1.01591830e-04, 1.22348667e-04, 1.45540604e-04, 1.07193757e-04,\n",
" 1.29606410e-04, 1.54815292e-04, 1.13266673e-04, 1.37495622e-04,\n",
" 1.64927437e-04, 1.19855887e-04, 1.46079307e-04, 1.75963645e-04,\n",
" 1.27011700e-04, 1.55427611e-04, 1.88020582e-04, 1.34790017e-04,\n",
" 1.65618702e-04, 2.01206244e-04, 1.43253028e-04, 1.76739777e-04,\n",
" 2.15641388e-04, 1.52469982e-04, 1.88888191e-04, 2.31461155e-04,\n",
" 1.62518071e-04, 2.02172755e-04, 2.48816911e-04, 1.73483423e-04,\n",
" 2.16715197e-04, 2.67878332e-04, 1.85462240e-04, 2.32651824e-04,\n",
" 2.88835763e-04, 1.98562080e-04, 2.50135419e-04, 3.11902899e-04,\n",
" 2.12903328e-04, 2.69337392e-04, 3.37319808e-04, 2.28620863e-04,\n",
" 2.90450228e-04, 3.65356364e-04, 2.45865958e-04, 3.13690280e-04,\n",
" 3.96316114e-04, 2.64808454e-04, 3.39300945e-04, 4.30540656e-04,\n",
" 2.85639234e-04, 3.67556282e-04, 4.68414557e-04, 3.08573055e-04,\n",
" 3.98765135e-04, 5.10370897e-04, 3.33851788e-04, 4.33275832e-04,\n",
" 5.56897468e-04, 3.61748118e-04, 4.71481528e-04, 6.08543708e-04])"
"array([4.64097874e-05, 5.20142609e-05, 5.74163309e-05, 4.76585304e-05,\n",
" 5.35875832e-05, 5.93505736e-05, 4.90033193e-05, 5.52810740e-05,\n",
" 6.14333696e-05, 5.04508489e-05, 5.71036033e-05, 6.36762900e-05,\n",
" 5.20084360e-05, 5.90648826e-05, 6.60920324e-05, 5.36840817e-05,\n",
" 6.11755527e-05, 6.86945406e-05, 5.54865410e-05, 6.34472793e-05,\n",
" 7.14991376e-05, 5.74253987e-05, 6.58928613e-05, 7.45226753e-05,\n",
" 5.95111559e-05, 6.85263505e-05, 7.77837009e-05, 6.17553240e-05,\n",
" 7.13631858e-05, 8.13026444e-05, 6.41705320e-05, 7.44203428e-05,\n",
" 8.51020274e-05, 6.67706437e-05, 7.77165017e-05, 8.92066979e-05,\n",
" 6.95708907e-05, 8.12722349e-05, 9.36440944e-05, 7.25880198e-05,\n",
" 8.51102174e-05, 9.84445414e-05, 7.58404584e-05, 8.92554627e-05,\n",
" 1.03641583e-04, 7.93484996e-05, 9.37355878e-05, 1.09272355e-04,\n",
" 8.31345102e-05, 9.85811110e-05, 1.15378012e-04, 8.72231632e-05,\n",
" 1.03825787e-04, 1.22004196e-04, 9.16416996e-05, 1.09506983e-04,\n",
" 1.29201578e-04, 9.64202228e-05, 1.15666105e-04, 1.37026460e-04,\n",
" 1.01592029e-04, 1.22349075e-04, 1.45541457e-04, 1.07193980e-04,\n",
" 1.29606875e-04, 1.54816273e-04, 1.13266925e-04, 1.37496152e-04,\n",
" 1.64928569e-04, 1.19856171e-04, 1.46079913e-04, 1.75964954e-04,\n",
" 1.27012023e-04, 1.55428306e-04, 1.88022101e-04, 1.34790385e-04,\n",
" 1.65619502e-04, 2.01208012e-04, 1.43253447e-04, 1.76740699e-04,\n",
" 2.15643451e-04, 1.52470461e-04, 1.88889258e-04, 2.31463569e-04,\n",
" 1.62518620e-04, 2.02173994e-04, 2.48819743e-04, 1.73484055e-04,\n",
" 2.16716638e-04, 2.67881664e-04, 1.85462968e-04, 2.32653505e-04,\n",
" 2.88839696e-04, 1.98562923e-04, 2.50137387e-04, 3.11907554e-04,\n",
" 2.12904306e-04, 2.69339702e-04, 3.37325333e-04, 2.28622001e-04,\n",
" 2.90452947e-04, 3.65362941e-04, 2.45867287e-04, 3.13693489e-04,\n",
" 3.96323966e-04, 2.64810009e-04, 3.39304745e-04, 4.30550057e-04,\n",
" 2.85641059e-04, 3.67560794e-04, 4.68425846e-04, 3.08575204e-04,\n",
" 3.98770509e-04, 5.10384491e-04, 3.33854326e-04, 4.33282251e-04,\n",
" 5.56913884e-04, 3.61751124e-04, 4.71489217e-04, 6.08563590e-04])"
]
},
"execution_count": 7,
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -347,7 +387,7 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": 9,
"id": "7bf4d583",
"metadata": {},
"outputs": [
Expand All @@ -369,7 +409,7 @@
"Name: premium_rate, Length: 120, dtype: float64"
]
},
"execution_count": 8,
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -385,7 +425,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand All @@ -399,7 +439,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.4"
"version": "3.10.13"
}
},
"nbformat": 4,
Expand Down
Loading