Skip to content

Commit

Permalink
munich example for docs
Browse files Browse the repository at this point in the history
  • Loading branch information
jbogaardt committed Jan 26, 2019
1 parent 152c375 commit 72b5f62
Show file tree
Hide file tree
Showing 23 changed files with 331 additions and 4 deletions.
4 changes: 2 additions & 2 deletions chainladder/core/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -618,11 +618,11 @@ def complete_date_range(origin_date, development_date,
''' Determines origin/development combinations in full. Useful for
when the triangle has holes in it. '''
origin_unique = \
pd.PeriodIndex(start=origin_date.min(),
pd.period_range(start=origin_date.min(),
end=origin_date.max(),
freq=origin_grain).to_timestamp()
development_unique = \
pd.PeriodIndex(start=origin_date.min(),
pd.period_range(start=origin_date.min(),
end=development_date.max(),
freq=development_grain).to_timestamp()
development_unique = TriangleBase.period_end(development_unique)
Expand Down
Binary file modified docs/auto_examples/auto_examples_jupyter.zip
Binary file not shown.
Binary file modified docs/auto_examples/auto_examples_python.zip
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 20 additions & 0 deletions docs/auto_examples/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,26 @@ Gallery of Chainladder Functionality
:hidden:

/auto_examples/plot_triangle_from_pandas

.. raw:: html

<div class="sphx-glr-thumbcontainer" tooltip="This example demonstrates how to adjust LDFs by the relationship between Paid and Incurred usin...">

.. only:: html

.. figure:: /auto_examples/images/thumb/sphx_glr_plot_munich_thumb.png

:ref:`sphx_glr_auto_examples_plot_munich.py`

.. raw:: html

</div>


.. toctree::
:hidden:

/auto_examples/plot_munich
.. raw:: html

<div style='clear:both'></div>
Expand Down
Binary file modified docs/auto_examples/plot_bf_apriori_from_cl_codeobj.pickle
Binary file not shown.
Binary file modified docs/auto_examples/plot_development_periods_codeobj.pickle
Binary file not shown.
Binary file modified docs/auto_examples/plot_industry_to_company_codeobj.pickle
Binary file not shown.
Binary file modified docs/auto_examples/plot_mack_codeobj.pickle
Binary file not shown.
54 changes: 54 additions & 0 deletions docs/auto_examples/plot_munich.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"%matplotlib inline"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n# Munich Adjustment Example\n\n\nThis example demonstrates how to adjust LDFs by the relationship between Paid\nand Incurred using the MunichAdjustment.\n.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import chainladder as cl\nimport seaborn as sns\nimport matplotlib.pyplot as plt\nsns.set_style('whitegrid')\nsns.set_palette('muted')\n\n# Load data\nmcl = cl.load_dataset('mcl')\n# Volume weighted (default) LDFs\ndev = cl.Development().fit_transform(mcl)\n# Traditional Chainladder\ncl_traditional = cl.Chainladder().fit(dev)\n# Munich Adjustment\ndev_munich = cl.MunichAdjustment(paid_to_incurred={'paid':'incurred'}).fit_transform(dev)\ncl_munich = cl.Chainladder().fit(dev_munich)\n\n# Plot data\nfig, (ax, ax2) = plt.subplots(ncols=2, sharex=True, figsize=(10,5))\nplot1_data = cl_munich.ultimate_['paid'].to_frame()\nplot1_data.columns = ['Paid Ultimate']\nplot1_data['Incurred Ultimate'] = cl_munich.ultimate_['incurred'].to_frame()\nplot2_data = (cl_munich.ultimate_['paid']/cl_munich.ultimate_['incurred']).to_frame()\nplot2_data.columns = ['Munich']\nplot2_data['Traditional'] = (cl_traditional.ultimate_['paid']/cl_traditional.ultimate_['incurred']).to_frame()\nplot1_data.plot(kind='bar', ax=ax)\nax.set_ylabel('Ultimate')\nax.set_xlabel('Accident Year')\nax.set_title('Munich Chainladder')\nplot2_data.plot(kind='bar', ax=ax2, ylim=(0,1.25))\nax2.set_title('P/I Ratio Comparison')\nax2.set_xlabel('Accident Year')\ng = plt.ylabel('Paid Ultimate / Incurred Ultimate')"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.3"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
42 changes: 42 additions & 0 deletions docs/auto_examples/plot_munich.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
"""
=========================
Munich Adjustment Example
=========================
This example demonstrates how to adjust LDFs by the relationship between Paid
and Incurred using the MunichAdjustment.
.
"""

import chainladder as cl
import seaborn as sns
import matplotlib.pyplot as plt
sns.set_style('whitegrid')
sns.set_palette('muted')

# Load data
mcl = cl.load_dataset('mcl')
# Volume weighted (default) LDFs
dev = cl.Development().fit_transform(mcl)
# Traditional Chainladder
cl_traditional = cl.Chainladder().fit(dev)
# Munich Adjustment
dev_munich = cl.MunichAdjustment(paid_to_incurred={'paid':'incurred'}).fit_transform(dev)
cl_munich = cl.Chainladder().fit(dev_munich)

# Plot data
fig, (ax, ax2) = plt.subplots(ncols=2, sharex=True, figsize=(10,5))
plot1_data = cl_munich.ultimate_['paid'].to_frame()
plot1_data.columns = ['Paid Ultimate']
plot1_data['Incurred Ultimate'] = cl_munich.ultimate_['incurred'].to_frame()
plot2_data = (cl_munich.ultimate_['paid']/cl_munich.ultimate_['incurred']).to_frame()
plot2_data.columns = ['Munich']
plot2_data['Traditional'] = (cl_traditional.ultimate_['paid']/cl_traditional.ultimate_['incurred']).to_frame()
plot1_data.plot(kind='bar', ax=ax)
ax.set_ylabel('Ultimate')
ax.set_xlabel('Accident Year')
ax.set_title('Munich Chainladder')
plot2_data.plot(kind='bar', ax=ax2, ylim=(0,1.25))
ax2.set_title('P/I Ratio Comparison')
ax2.set_xlabel('Accident Year')
g = plt.ylabel('Paid Ultimate / Incurred Ultimate')
1 change: 1 addition & 0 deletions docs/auto_examples/plot_munich.py.md5
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
242c50127e7690e88516533290192901
92 changes: 92 additions & 0 deletions docs/auto_examples/plot_munich.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
.. note::
:class: sphx-glr-download-link-note

Click :ref:`here <sphx_glr_download_auto_examples_plot_munich.py>` to download the full example code
.. rst-class:: sphx-glr-example-title

.. _sphx_glr_auto_examples_plot_munich.py:


=========================
Munich Adjustment Example
=========================

This example demonstrates how to adjust LDFs by the relationship between Paid
and Incurred using the MunichAdjustment.
.




.. image:: /auto_examples/images/sphx_glr_plot_munich_001.png
:class: sphx-glr-single-img





.. code-block:: python
import chainladder as cl
import seaborn as sns
import matplotlib.pyplot as plt
sns.set_style('whitegrid')
sns.set_palette('muted')
# Load data
mcl = cl.load_dataset('mcl')
# Volume weighted (default) LDFs
dev = cl.Development().fit_transform(mcl)
# Traditional Chainladder
cl_traditional = cl.Chainladder().fit(dev)
# Munich Adjustment
dev_munich = cl.MunichAdjustment(paid_to_incurred={'paid':'incurred'}).fit_transform(dev)
cl_munich = cl.Chainladder().fit(dev_munich)
# Plot data
fig, (ax, ax2) = plt.subplots(ncols=2, sharex=True, figsize=(10,5))
plot1_data = cl_munich.ultimate_['paid'].to_frame()
plot1_data.columns = ['Paid Ultimate']
plot1_data['Incurred Ultimate'] = cl_munich.ultimate_['incurred'].to_frame()
plot2_data = (cl_munich.ultimate_['paid']/cl_munich.ultimate_['incurred']).to_frame()
plot2_data.columns = ['Munich']
plot2_data['Traditional'] = (cl_traditional.ultimate_['paid']/cl_traditional.ultimate_['incurred']).to_frame()
plot1_data.plot(kind='bar', ax=ax)
ax.set_ylabel('Ultimate')
ax.set_xlabel('Accident Year')
ax.set_title('Munich Chainladder')
plot2_data.plot(kind='bar', ax=ax2, ylim=(0,1.25))
ax2.set_title('P/I Ratio Comparison')
ax2.set_xlabel('Accident Year')
g = plt.ylabel('Paid Ultimate / Incurred Ultimate')
**Total running time of the script:** ( 0 minutes 0.433 seconds)


.. _sphx_glr_download_auto_examples_plot_munich.py:


.. only :: html
.. container:: sphx-glr-footer
:class: sphx-glr-footer-example
.. container:: sphx-glr-download
:download:`Download Python source code: plot_munich.py <plot_munich.py>`
.. container:: sphx-glr-download
:download:`Download Jupyter notebook: plot_munich.ipynb <plot_munich.ipynb>`
.. only:: html

.. rst-class:: sphx-glr-signature

`Gallery generated by Sphinx-Gallery <https://sphinx-gallery.readthedocs.io>`_
Binary file added docs/auto_examples/plot_munich_codeobj.pickle
Binary file not shown.
Binary file modified docs/auto_examples/plot_triangle_from_pandas_codeobj.pickle
Binary file not shown.
Binary file modified docs/auto_examples/plot_triangle_slicing_codeobj.pickle
Binary file not shown.
18 changes: 18 additions & 0 deletions docs/modules/generated/chainladder.Chainladder.examples
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,21 @@ Examples using ``chainladder.Chainladder``
.. only:: not html

* :ref:`sphx_glr_auto_examples_plot_bf_apriori_from_cl.py`

.. raw:: html

<div class="sphx-glr-thumbcontainer" tooltip="This example demonstrates how to adjust LDFs by the relationship between Paid and Incurred usin...">

.. only:: html

.. figure:: /auto_examples/images/thumb/sphx_glr_plot_munich_thumb.png

:ref:`sphx_glr_auto_examples_plot_munich.py`

.. raw:: html

</div>

.. only:: not html

* :ref:`sphx_glr_auto_examples_plot_munich.py`
18 changes: 18 additions & 0 deletions docs/modules/generated/chainladder.Development.examples
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,21 @@ Examples using ``chainladder.Development``
.. only:: not html

* :ref:`sphx_glr_auto_examples_plot_mack.py`

.. raw:: html

<div class="sphx-glr-thumbcontainer" tooltip="This example demonstrates how to adjust LDFs by the relationship between Paid and Incurred usin...">

.. only:: html

.. figure:: /auto_examples/images/thumb/sphx_glr_plot_munich_thumb.png

:ref:`sphx_glr_auto_examples_plot_munich.py`

.. raw:: html

</div>

.. only:: not html

* :ref:`sphx_glr_auto_examples_plot_munich.py`
22 changes: 22 additions & 0 deletions docs/modules/generated/chainladder.MunichAdjustment.examples
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@


Examples using ``chainladder.MunichAdjustment``
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. raw:: html

<div class="sphx-glr-thumbcontainer" tooltip="This example demonstrates how to adjust LDFs by the relationship between Paid and Incurred usin...">

.. only:: html

.. figure:: /auto_examples/images/thumb/sphx_glr_plot_munich_thumb.png

:ref:`sphx_glr_auto_examples_plot_munich.py`

.. raw:: html

</div>

.. only:: not html

* :ref:`sphx_glr_auto_examples_plot_munich.py`
18 changes: 18 additions & 0 deletions docs/modules/generated/chainladder.load_dataset.examples
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,21 @@ Examples using ``chainladder.load_dataset``
.. only:: not html

* :ref:`sphx_glr_auto_examples_plot_bf_apriori_from_cl.py`

.. raw:: html

<div class="sphx-glr-thumbcontainer" tooltip="This example demonstrates how to adjust LDFs by the relationship between Paid and Incurred usin...">

.. only:: html

.. figure:: /auto_examples/images/thumb/sphx_glr_plot_munich_thumb.png

:ref:`sphx_glr_auto_examples_plot_munich.py`

.. raw:: html

</div>

.. only:: not html

* :ref:`sphx_glr_auto_examples_plot_munich.py`
4 changes: 2 additions & 2 deletions docs/themes/scikit-learn/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,8 @@
<img src="_images/sphx_glr_plot_triangle_slicing_thumb.png"></a>
</div>
<div class="item">
<a href="{{ pathto('auto_examples/cluster/plot_cluster_comparison') }}">
<img src="_images/sphx_glr_plot_cluster_comparison_thumb.png"></a>
<a href="{{ pathto('auto_examples/cluster/plot_munich') }}">
<img src="_images/sphx_glr_plot_munich_thumb.png"></a>
</div>
<div class="item">
<a href="{{ pathto('auto_examples/ensemble/plot_adaboost_twoclass') }}">
Expand Down
42 changes: 42 additions & 0 deletions examples/plot_munich.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
"""
=========================
Munich Adjustment Example
=========================
This example demonstrates how to adjust LDFs by the relationship between Paid
and Incurred using the MunichAdjustment.
.
"""

import chainladder as cl
import seaborn as sns
import matplotlib.pyplot as plt
sns.set_style('whitegrid')
sns.set_palette('muted')

# Load data
mcl = cl.load_dataset('mcl')
# Volume weighted (default) LDFs
dev = cl.Development().fit_transform(mcl)
# Traditional Chainladder
cl_traditional = cl.Chainladder().fit(dev)
# Munich Adjustment
dev_munich = cl.MunichAdjustment(paid_to_incurred={'paid':'incurred'}).fit_transform(dev)
cl_munich = cl.Chainladder().fit(dev_munich)

# Plot data
fig, (ax, ax2) = plt.subplots(ncols=2, sharex=True, figsize=(10,5))
plot1_data = cl_munich.ultimate_['paid'].to_frame()
plot1_data.columns = ['Paid Ultimate']
plot1_data['Incurred Ultimate'] = cl_munich.ultimate_['incurred'].to_frame()
plot2_data = (cl_munich.ultimate_['paid']/cl_munich.ultimate_['incurred']).to_frame()
plot2_data.columns = ['Munich']
plot2_data['Traditional'] = (cl_traditional.ultimate_['paid']/cl_traditional.ultimate_['incurred']).to_frame()
plot1_data.plot(kind='bar', ax=ax)
ax.set_ylabel('Ultimate')
ax.set_xlabel('Accident Year')
ax.set_title('Munich Chainladder')
plot2_data.plot(kind='bar', ax=ax2, ylim=(0,1.25))
ax2.set_title('P/I Ratio Comparison')
ax2.set_xlabel('Accident Year')
g = plt.ylabel('Paid Ultimate / Incurred Ultimate')

0 comments on commit 72b5f62

Please sign in to comment.