Skip to content
Merged
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
360 changes: 360 additions & 0 deletions docs/user_guide/development.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -7383,6 +7383,366 @@
"```"
]
},
{
"attachments": {},
"cell_type": "markdown",
"id": "origin-varying-intro",
"metadata": {},
"source": [
"### Origin-varying patterns\n",
"\n",
"`DevelopmentML` predicts every cell of the `Triangle`, so its `ldf_` has one row per\n",
"origin period, where `Development` has a single row. Whether those rows differ\n",
"depends on the model. The over-dispersed Poisson (ODP) cross-classified GLM, fit to\n",
"incrementals with a log link and the design matrix `C(development) + C(origin)`,\n",
"gives the same pattern for every origin, and that pattern is the volume-weighted\n",
"chainladder {cite}`taylor2016`."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "origin-varying-odp",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>12-24</th>\n",
" <th>24-36</th>\n",
" <th>36-48</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>2001</th>\n",
" <td>3.4910</td>\n",
" <td>1.7470</td>\n",
" <td>1.4570</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2002</th>\n",
" <td>3.4910</td>\n",
" <td>1.7470</td>\n",
" <td>1.4570</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2003</th>\n",
" <td>3.4910</td>\n",
" <td>1.7470</td>\n",
" <td>1.4570</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2004</th>\n",
" <td>3.4910</td>\n",
" <td>1.7470</td>\n",
" <td>1.4570</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2005</th>\n",
" <td>3.4910</td>\n",
" <td>1.7470</td>\n",
" <td>1.4570</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2006</th>\n",
" <td>3.4910</td>\n",
" <td>1.7470</td>\n",
" <td>1.4570</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2007</th>\n",
" <td>3.4910</td>\n",
" <td>1.7470</td>\n",
" <td>1.4570</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2008</th>\n",
" <td>3.4910</td>\n",
" <td>1.7470</td>\n",
" <td>1.4570</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2009</th>\n",
" <td>3.4910</td>\n",
" <td>1.7470</td>\n",
" <td>1.4570</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2010</th>\n",
" <td>3.4910</td>\n",
" <td>1.7470</td>\n",
" <td>1.4570</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>"
],
"text/plain": [
" 12-24 24-36 36-48\n",
"2001 3.491 1.747 1.457\n",
"2002 3.491 1.747 1.457\n",
"2003 3.491 1.747 1.457\n",
"2004 3.491 1.747 1.457\n",
"2005 3.491 1.747 1.457\n",
"2006 3.491 1.747 1.457\n",
"2007 3.491 1.747 1.457\n",
"2008 3.491 1.747 1.457\n",
"2009 3.491 1.747 1.457\n",
"2010 3.491 1.747 1.457"
]
},
"execution_count": null,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"genins = cl.load_sample(\"genins\")\n",
"\n",
"# alpha=0 turns off the default L2 penalty\n",
"cross_classified = cl.TweedieGLM(\n",
" design_matrix=\"C(development) + C(origin)\", alpha=0, max_iter=1000\n",
").fit(genins)\n",
"cross_classified.ldf_.iloc[..., :3].round(3)"
]
},
{
"attachments": {},
"cell_type": "markdown",
"id": "origin-varying-drift",
"metadata": {},
"source": [
"Every row matches `cl.Development().fit(genins).ldf_`. Adding an\n",
"`origin:I(development / 12)` term lets the development pattern drift from one origin\n",
"year to the next, so each origin gets its own age-to-age factors. Here the factors\n",
"rise for later origins."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "origin-varying-fit",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>12-24</th>\n",
" <th>24-36</th>\n",
" <th>36-48</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>2001</th>\n",
" <td>3.4320</td>\n",
" <td>1.7270</td>\n",
" <td>1.4430</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2002</th>\n",
" <td>3.4460</td>\n",
" <td>1.7330</td>\n",
" <td>1.4480</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2003</th>\n",
" <td>3.4600</td>\n",
" <td>1.7380</td>\n",
" <td>1.4520</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2004</th>\n",
" <td>3.4740</td>\n",
" <td>1.7430</td>\n",
" <td>1.4570</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2005</th>\n",
" <td>3.4880</td>\n",
" <td>1.7490</td>\n",
" <td>1.4610</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2006</th>\n",
" <td>3.5020</td>\n",
" <td>1.7540</td>\n",
" <td>1.4660</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2007</th>\n",
" <td>3.5160</td>\n",
" <td>1.7600</td>\n",
" <td>1.4710</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2008</th>\n",
" <td>3.5310</td>\n",
" <td>1.7660</td>\n",
" <td>1.4750</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2009</th>\n",
" <td>3.5450</td>\n",
" <td>1.7710</td>\n",
" <td>1.4800</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2010</th>\n",
" <td>3.5600</td>\n",
" <td>1.7770</td>\n",
" <td>1.4850</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>"
],
"text/plain": [
" 12-24 24-36 36-48\n",
"2001 3.432 1.727 1.443\n",
"2002 3.446 1.733 1.448\n",
"2003 3.460 1.738 1.452\n",
"2004 3.474 1.743 1.457\n",
"2005 3.488 1.749 1.461\n",
"2006 3.502 1.754 1.466\n",
"2007 3.516 1.760 1.471\n",
"2008 3.531 1.766 1.475\n",
"2009 3.545 1.771 1.480\n",
"2010 3.560 1.777 1.485"
]
},
"execution_count": null,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"drifting = cl.TweedieGLM(\n",
" design_matrix=\"C(development) + C(origin) + origin:I(development / 12)\",\n",
" alpha=0,\n",
" max_iter=1000,\n",
").fit(genins)\n",
"drifting.ldf_.iloc[..., :3].round(3)"
]
},
{
"attachments": {},
"cell_type": "markdown",
"id": "origin-varying-methods",
"metadata": {},
"source": [
"`Chainladder` applies each origin's own row of `ldf_`: an\n",
"origin's ultimate is its latest diagonal times the product of its own factors from\n",
"its current age onward. Dividing by the traditional chainladder ultimates shows the\n",
"drift raising the recent origins most."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "origin-varying-ultimates",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>2261</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>2001</th>\n",
" <td>1.0000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2002</th>\n",
" <td>1.0010</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2003</th>\n",
" <td>1.0040</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2004</th>\n",
" <td>1.0090</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2005</th>\n",
" <td>1.0180</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2006</th>\n",
" <td>1.0290</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2007</th>\n",
" <td>1.0430</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2008</th>\n",
" <td>1.0660</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2009</th>\n",
" <td>1.0950</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2010</th>\n",
" <td>1.1350</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>"
],
"text/plain": [
" 2261\n",
"2001 1.000\n",
"2002 1.001\n",
"2003 1.004\n",
"2004 1.009\n",
"2005 1.018\n",
"2006 1.029\n",
"2007 1.043\n",
"2008 1.066\n",
"2009 1.095\n",
"2010 1.135"
]
},
"execution_count": null,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"plain = cl.Chainladder().fit(cl.Development().fit_transform(genins))\n",
"drift = cl.Chainladder().fit(drifting.transform(genins))\n",
"(drift.ultimate_ / plain.ultimate_).round(3)"
]
},
{
"attachments": {},
"cell_type": "markdown",
"id": "origin-varying-note",
"metadata": {},
"source": [
"```{note}\n",
"The `origin:I(development / 12)` term illustrates one kind of time-heterogeneity. Test\n",
"any such term against the data, for example with residuals by origin, before relying\n",
"on it. `TweedieGLM` applies an L2 penalty by default, so this example sets `alpha=0` to fit\n",
"the unpenalized GLM.\n",
"```"
]
},
{
"attachments": {},
"cell_type": "markdown",
Expand Down
Loading