diff --git a/chainladder/__init__.py b/chainladder/__init__.py index 04eeaf15..356efbac 100644 --- a/chainladder/__init__.py +++ b/chainladder/__init__.py @@ -5,4 +5,4 @@ from chainladder.methods import * # noqa (API Import) from chainladder.workflow import * # noqa (API Import) -__version__ = '0.4.5' +__version__ = '0.4.7' diff --git a/chainladder/core/tests/test_triangle.py b/chainladder/core/tests/test_triangle.py index 38aaf4b7..af0362c8 100644 --- a/chainladder/core/tests/test_triangle.py +++ b/chainladder/core/tests/test_triangle.py @@ -259,3 +259,9 @@ def test_commutative(): assert full.cum_to_incr().grain('OYDY').val_to_dev() == full.val_to_dev().cum_to_incr().grain('OYDY') assert np.allclose(np.nan_to_num(full.grain('OYDY').cum_to_incr().val_to_dev().incr_to_cum().values), np.nan_to_num(full.val_to_dev().grain('OYDY').values), atol=1e-5) + +def test_broadcasting(): + t1 = cl.load_dataset('raa') + t2 = tri + assert t1.broadcast_axis('columns', t2.columns).shape[1] == t2.shape[1] + assert t1.broadcast_axis('index', t2.index).shape[0] == t2.shape[0] diff --git a/chainladder/core/triangle.py b/chainladder/core/triangle.py index 517972ba..f22a18c8 100644 --- a/chainladder/core/triangle.py +++ b/chainladder/core/triangle.py @@ -498,3 +498,31 @@ def trend(self, trend=0.0, axis='origin', valuation_date=None, ultimate_lag=None obj = copy.deepcopy(self) obj.values = obj.values*trend return obj + + def broadcast_axis(self, axis, value): + """ Broadcasts (i.e. repeats) triangles along an axis. The axis to be + broadcast must be of length 1. + + Parameters + ---------- + axis : str or int + the axis to be broadcast over. + value : axis-like + The value of the new axis. + """ + obj = copy.deepcopy(self) + axis = self._get_axis(axis) + if self.shape[axis] != 1: + raise ValueError('Axis to be broadcast must be of length 1') + elif axis > 1: + raise ValueError('Only index and column axes are supported') + else: + obj.values = np.repeat(obj.values, len(value), axis) + if axis == 0: + obj.key_labels = list(value.columns) + obj.kdims = value.values + obj.index = value + if axis == 1: + obj.vdims = value.values + obj.columns = value + return obj diff --git a/chainladder/development/bootstrap.py b/chainladder/development/bootstrap.py index 06ba03eb..9ad257b8 100644 --- a/chainladder/development/bootstrap.py +++ b/chainladder/development/bootstrap.py @@ -61,6 +61,7 @@ def __init__(self, n_sims=1000, n_periods=-1, self.random_state = random_state def fit(self, X, y=None, sample_weight=None): + warn('Process risk not yet implemented...') if (type(X.ddims) != np.ndarray): raise ValueError('Triangle must be expressed with development lags') obj = copy.copy(X) diff --git a/docs/auto_examples/auto_examples_jupyter.zip b/docs/auto_examples/auto_examples_jupyter.zip index ab8e3bc5..79d8d71c 100644 Binary files a/docs/auto_examples/auto_examples_jupyter.zip and b/docs/auto_examples/auto_examples_jupyter.zip differ diff --git a/docs/auto_examples/auto_examples_python.zip b/docs/auto_examples/auto_examples_python.zip index 9c9dfe24..6aa05c65 100644 Binary files a/docs/auto_examples/auto_examples_python.zip and b/docs/auto_examples/auto_examples_python.zip differ diff --git a/docs/auto_examples/images/sphx_glr_plot_bootstrap_001.png b/docs/auto_examples/images/sphx_glr_plot_bootstrap_001.png index 84d37089..3fe7247f 100644 Binary files a/docs/auto_examples/images/sphx_glr_plot_bootstrap_001.png and b/docs/auto_examples/images/sphx_glr_plot_bootstrap_001.png differ diff --git a/docs/auto_examples/images/sphx_glr_plot_bootstrap_comparison_001.png b/docs/auto_examples/images/sphx_glr_plot_bootstrap_comparison_001.png new file mode 100644 index 00000000..89af0a06 Binary files /dev/null and b/docs/auto_examples/images/sphx_glr_plot_bootstrap_comparison_001.png differ diff --git a/docs/auto_examples/images/sphx_glr_plot_exposure_triangle_001.png b/docs/auto_examples/images/sphx_glr_plot_exposure_triangle_001.png new file mode 100644 index 00000000..524131c3 Binary files /dev/null and b/docs/auto_examples/images/sphx_glr_plot_exposure_triangle_001.png differ diff --git a/docs/auto_examples/images/sphx_glr_plot_ibnr_runoff_001.png b/docs/auto_examples/images/sphx_glr_plot_ibnr_runoff_001.png new file mode 100644 index 00000000..469d37b9 Binary files /dev/null and b/docs/auto_examples/images/sphx_glr_plot_ibnr_runoff_001.png differ diff --git a/docs/auto_examples/images/sphx_glr_plot_stochastic_bornferg_001.png b/docs/auto_examples/images/sphx_glr_plot_stochastic_bornferg_001.png new file mode 100644 index 00000000..5b8802eb Binary files /dev/null and b/docs/auto_examples/images/sphx_glr_plot_stochastic_bornferg_001.png differ diff --git a/docs/auto_examples/images/sphx_glr_plot_triangle_from_pandas_001.png b/docs/auto_examples/images/sphx_glr_plot_triangle_from_pandas_001.png index e5283a1e..f1f9dc3d 100644 Binary files a/docs/auto_examples/images/sphx_glr_plot_triangle_from_pandas_001.png and b/docs/auto_examples/images/sphx_glr_plot_triangle_from_pandas_001.png differ diff --git a/docs/auto_examples/images/sphx_glr_plot_value_at_risk_001.png b/docs/auto_examples/images/sphx_glr_plot_value_at_risk_001.png new file mode 100644 index 00000000..4d43c778 Binary files /dev/null and b/docs/auto_examples/images/sphx_glr_plot_value_at_risk_001.png differ diff --git a/docs/auto_examples/images/thumb/sphx_glr_plot_bootstrap_comparison_thumb.png b/docs/auto_examples/images/thumb/sphx_glr_plot_bootstrap_comparison_thumb.png new file mode 100644 index 00000000..b8c0ec43 Binary files /dev/null and b/docs/auto_examples/images/thumb/sphx_glr_plot_bootstrap_comparison_thumb.png differ diff --git a/docs/auto_examples/images/thumb/sphx_glr_plot_bootstrap_thumb.png b/docs/auto_examples/images/thumb/sphx_glr_plot_bootstrap_thumb.png index fd54ef89..14fbd439 100644 Binary files a/docs/auto_examples/images/thumb/sphx_glr_plot_bootstrap_thumb.png and b/docs/auto_examples/images/thumb/sphx_glr_plot_bootstrap_thumb.png differ diff --git a/docs/auto_examples/images/thumb/sphx_glr_plot_exposure_triangle_thumb.png b/docs/auto_examples/images/thumb/sphx_glr_plot_exposure_triangle_thumb.png new file mode 100644 index 00000000..5d93a2af Binary files /dev/null and b/docs/auto_examples/images/thumb/sphx_glr_plot_exposure_triangle_thumb.png differ diff --git a/docs/auto_examples/images/thumb/sphx_glr_plot_ibnr_runoff_thumb.png b/docs/auto_examples/images/thumb/sphx_glr_plot_ibnr_runoff_thumb.png new file mode 100644 index 00000000..318df334 Binary files /dev/null and b/docs/auto_examples/images/thumb/sphx_glr_plot_ibnr_runoff_thumb.png differ diff --git a/docs/auto_examples/images/thumb/sphx_glr_plot_stochastic_bornferg_thumb.png b/docs/auto_examples/images/thumb/sphx_glr_plot_stochastic_bornferg_thumb.png new file mode 100644 index 00000000..c38654ee Binary files /dev/null and b/docs/auto_examples/images/thumb/sphx_glr_plot_stochastic_bornferg_thumb.png differ diff --git a/docs/auto_examples/images/thumb/sphx_glr_plot_triangle_from_pandas_thumb.png b/docs/auto_examples/images/thumb/sphx_glr_plot_triangle_from_pandas_thumb.png index 31227039..7c7ad101 100644 Binary files a/docs/auto_examples/images/thumb/sphx_glr_plot_triangle_from_pandas_thumb.png and b/docs/auto_examples/images/thumb/sphx_glr_plot_triangle_from_pandas_thumb.png differ diff --git a/docs/auto_examples/images/thumb/sphx_glr_plot_value_at_risk_thumb.png b/docs/auto_examples/images/thumb/sphx_glr_plot_value_at_risk_thumb.png new file mode 100644 index 00000000..eb1b3a2a Binary files /dev/null and b/docs/auto_examples/images/thumb/sphx_glr_plot_value_at_risk_thumb.png differ diff --git a/docs/auto_examples/index.rst b/docs/auto_examples/index.rst index 1f4536d4..43dea9a2 100644 --- a/docs/auto_examples/index.rst +++ b/docs/auto_examples/index.rst @@ -51,6 +51,66 @@ Gallery of Chainladder Functionality /auto_examples/plot_triangle_slicing +.. raw:: html + +
+ +.. only:: html + + .. figure:: /auto_examples/images/thumb/sphx_glr_plot_value_at_risk_thumb.png + + :ref:`sphx_glr_auto_examples_plot_value_at_risk.py` + +.. raw:: html + +
+ + +.. toctree:: + :hidden: + + /auto_examples/plot_value_at_risk + +.. raw:: html + +
+ +.. only:: html + + .. figure:: /auto_examples/images/thumb/sphx_glr_plot_ibnr_runoff_thumb.png + + :ref:`sphx_glr_auto_examples_plot_ibnr_runoff.py` + +.. raw:: html + +
+ + +.. toctree:: + :hidden: + + /auto_examples/plot_ibnr_runoff + +.. raw:: html + +
+ +.. only:: html + + .. figure:: /auto_examples/images/thumb/sphx_glr_plot_exposure_triangle_thumb.png + + :ref:`sphx_glr_auto_examples_plot_exposure_triangle.py` + +.. raw:: html + +
+ + +.. toctree:: + :hidden: + + /auto_examples/plot_exposure_triangle + .. raw:: html
@@ -111,6 +171,46 @@ Gallery of Chainladder Functionality /auto_examples/plot_bf_apriori_from_cl +.. raw:: html + +
+ +.. only:: html + + .. figure:: /auto_examples/images/thumb/sphx_glr_plot_triangle_from_pandas_thumb.png + + :ref:`sphx_glr_auto_examples_plot_triangle_from_pandas.py` + +.. raw:: html + +
+ + +.. toctree:: + :hidden: + + /auto_examples/plot_triangle_from_pandas + +.. raw:: html + +
+ +.. only:: html + + .. figure:: /auto_examples/images/thumb/sphx_glr_plot_bootstrap_comparison_thumb.png + + :ref:`sphx_glr_auto_examples_plot_bootstrap_comparison.py` + +.. raw:: html + +
+ + +.. toctree:: + :hidden: + + /auto_examples/plot_bootstrap_comparison + .. raw:: html
@@ -173,13 +273,13 @@ Gallery of Chainladder Functionality .. raw:: html -
+
.. only:: html - .. figure:: /auto_examples/images/thumb/sphx_glr_plot_triangle_from_pandas_thumb.png + .. figure:: /auto_examples/images/thumb/sphx_glr_plot_munich_thumb.png - :ref:`sphx_glr_auto_examples_plot_triangle_from_pandas.py` + :ref:`sphx_glr_auto_examples_plot_munich.py` .. raw:: html @@ -189,17 +289,17 @@ Gallery of Chainladder Functionality .. toctree:: :hidden: - /auto_examples/plot_triangle_from_pandas + /auto_examples/plot_munich .. raw:: html -
+
.. only:: html - .. figure:: /auto_examples/images/thumb/sphx_glr_plot_munich_thumb.png + .. figure:: /auto_examples/images/thumb/sphx_glr_plot_stochastic_bornferg_thumb.png - :ref:`sphx_glr_auto_examples_plot_munich.py` + :ref:`sphx_glr_auto_examples_plot_stochastic_bornferg.py` .. raw:: html @@ -209,7 +309,7 @@ Gallery of Chainladder Functionality .. toctree:: :hidden: - /auto_examples/plot_munich + /auto_examples/plot_stochastic_bornferg .. raw:: html diff --git a/docs/auto_examples/plot_ave_analysis.rst b/docs/auto_examples/plot_ave_analysis.rst index 21dd854b..3df591dc 100644 --- a/docs/auto_examples/plot_ave_analysis.rst +++ b/docs/auto_examples/plot_ave_analysis.rst @@ -68,7 +68,7 @@ payment patterns for the demo. .. rst-class:: sphx-glr-timing - **Total running time of the script:** ( 0 minutes 3.530 seconds) + **Total running time of the script:** ( 0 minutes 3.187 seconds) .. _sphx_glr_download_auto_examples_plot_ave_analysis.py: diff --git a/docs/auto_examples/plot_ave_analysis_codeobj.pickle b/docs/auto_examples/plot_ave_analysis_codeobj.pickle index f369bbe6..fc43bdd9 100644 Binary files a/docs/auto_examples/plot_ave_analysis_codeobj.pickle and b/docs/auto_examples/plot_ave_analysis_codeobj.pickle differ diff --git a/docs/auto_examples/plot_benktander.rst b/docs/auto_examples/plot_benktander.rst index 8af59635..58a0203b 100644 --- a/docs/auto_examples/plot_benktander.rst +++ b/docs/auto_examples/plot_benktander.rst @@ -65,7 +65,7 @@ choice. .. rst-class:: sphx-glr-timing - **Total running time of the script:** ( 0 minutes 30.942 seconds) + **Total running time of the script:** ( 0 minutes 28.456 seconds) .. _sphx_glr_download_auto_examples_plot_benktander.py: diff --git a/docs/auto_examples/plot_benktander_codeobj.pickle b/docs/auto_examples/plot_benktander_codeobj.pickle index 65595b1c..d4bd3963 100644 Binary files a/docs/auto_examples/plot_benktander_codeobj.pickle and b/docs/auto_examples/plot_benktander_codeobj.pickle differ diff --git a/docs/auto_examples/plot_bf_apriori_from_cl.rst b/docs/auto_examples/plot_bf_apriori_from_cl.rst index 3c1f3373..9d02f65d 100644 --- a/docs/auto_examples/plot_bf_apriori_from_cl.rst +++ b/docs/auto_examples/plot_bf_apriori_from_cl.rst @@ -27,7 +27,7 @@ apriori selection for the Bornhuetter-Ferguson Method. .. code-block:: none - + @@ -60,7 +60,7 @@ apriori selection for the Bornhuetter-Ferguson Method. .. rst-class:: sphx-glr-timing - **Total running time of the script:** ( 0 minutes 1.345 seconds) + **Total running time of the script:** ( 0 minutes 1.238 seconds) .. _sphx_glr_download_auto_examples_plot_bf_apriori_from_cl.py: diff --git a/docs/auto_examples/plot_bf_apriori_from_cl_codeobj.pickle b/docs/auto_examples/plot_bf_apriori_from_cl_codeobj.pickle index 0a4fe7fe..930f24af 100644 Binary files a/docs/auto_examples/plot_bf_apriori_from_cl_codeobj.pickle and b/docs/auto_examples/plot_bf_apriori_from_cl_codeobj.pickle differ diff --git a/docs/auto_examples/plot_bootstrap.rst b/docs/auto_examples/plot_bootstrap.rst index 691aea40..d6e8a180 100644 --- a/docs/auto_examples/plot_bootstrap.rst +++ b/docs/auto_examples/plot_bootstrap.rst @@ -26,6 +26,8 @@ Bootstrap sampler and get various properties about parameter uncertainty. .. code-block:: none + c:\users\jboga\onedrive\documents\github\chainladder-python\chainladder\development\bootstrap.py:64: UserWarning: Process risk not yet implemented... + warn('Process risk not yet implemented...') c:\users\jboga\onedrive\documents\github\chainladder-python\chainladder\core\pandas.py:219: RuntimeWarning: Mean of empty slice obj.values = func(obj.values, axis=axis, *args, **kwargs) @@ -69,7 +71,7 @@ Bootstrap sampler and get various properties about parameter uncertainty. .. rst-class:: sphx-glr-timing - **Total running time of the script:** ( 0 minutes 14.352 seconds) + **Total running time of the script:** ( 0 minutes 13.354 seconds) .. _sphx_glr_download_auto_examples_plot_bootstrap.py: diff --git a/docs/auto_examples/plot_bootstrap_codeobj.pickle b/docs/auto_examples/plot_bootstrap_codeobj.pickle index 529a30d0..e307edeb 100644 Binary files a/docs/auto_examples/plot_bootstrap_codeobj.pickle and b/docs/auto_examples/plot_bootstrap_codeobj.pickle differ diff --git a/docs/auto_examples/plot_bootstrap_comparison.ipynb b/docs/auto_examples/plot_bootstrap_comparison.ipynb new file mode 100644 index 00000000..1eaf7ad5 --- /dev/null +++ b/docs/auto_examples/plot_bootstrap_comparison.ipynb @@ -0,0 +1,54 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "%matplotlib inline" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\n# ODP Bootstrap Comparison\n\n\nThis example demonstrates how you can drop the outlier link ratios from the\nBootstrapODPSample to reduce reserve variability estimates.\n\n\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "import chainladder as cl\n\nimport seaborn as sns\nsns.set_style('whitegrid')\n\n# Load triangle\ntriangle = cl.load_dataset('raa')\n\n# Use bootstrap sampler to get resampled triangles\ns1 = cl.BootstrapODPSample(\n n_sims=5000, random_state=42).fit(triangle).resampled_triangles_\n\n## Alternatively use fit_transform() to access resampled triangles dropping\n# outlier link-ratios from resampler\ns2 = cl.BootstrapODPSample(\n drop_high=True, drop_low=True,\n n_sims=5000, random_state=42).fit_transform(triangle)\n\n# Summarize results of first model\nresults = cl.Chainladder().fit(s1).ibnr_.sum('origin').rename('columns', ['Original'])\n# Add another column to triangle with second set of results.\nresults['Dropped'] = cl.Chainladder().fit(s2).ibnr_.sum('origin')\n\n# Plot both IBNR distributions\nresults.to_frame().plot(kind='hist', bins=50, alpha=0.5)" + ] + } + ], + "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 +} \ No newline at end of file diff --git a/docs/auto_examples/plot_bootstrap_comparison.py b/docs/auto_examples/plot_bootstrap_comparison.py new file mode 100644 index 00000000..3415d21f --- /dev/null +++ b/docs/auto_examples/plot_bootstrap_comparison.py @@ -0,0 +1,34 @@ +""" +======================== +ODP Bootstrap Comparison +======================== + +This example demonstrates how you can drop the outlier link ratios from the +BootstrapODPSample to reduce reserve variability estimates. + +""" +import chainladder as cl + +import seaborn as sns +sns.set_style('whitegrid') + +# Load triangle +triangle = cl.load_dataset('raa') + +# Use bootstrap sampler to get resampled triangles +s1 = cl.BootstrapODPSample( + n_sims=5000, random_state=42).fit(triangle).resampled_triangles_ + +## Alternatively use fit_transform() to access resampled triangles dropping +# outlier link-ratios from resampler +s2 = cl.BootstrapODPSample( + drop_high=True, drop_low=True, + n_sims=5000, random_state=42).fit_transform(triangle) + +# Summarize results of first model +results = cl.Chainladder().fit(s1).ibnr_.sum('origin').rename('columns', ['Original']) +# Add another column to triangle with second set of results. +results['Dropped'] = cl.Chainladder().fit(s2).ibnr_.sum('origin') + +# Plot both IBNR distributions +results.to_frame().plot(kind='hist', bins=50, alpha=0.5) diff --git a/docs/auto_examples/plot_bootstrap_comparison.py.md5 b/docs/auto_examples/plot_bootstrap_comparison.py.md5 new file mode 100644 index 00000000..3182bb82 --- /dev/null +++ b/docs/auto_examples/plot_bootstrap_comparison.py.md5 @@ -0,0 +1 @@ +af4123840aa71f01d2fd75aee3df3e94 \ No newline at end of file diff --git a/docs/auto_examples/plot_bootstrap_comparison.rst b/docs/auto_examples/plot_bootstrap_comparison.rst new file mode 100644 index 00000000..3a83380b --- /dev/null +++ b/docs/auto_examples/plot_bootstrap_comparison.rst @@ -0,0 +1,107 @@ +.. note:: + :class: sphx-glr-download-link-note + + Click :ref:`here ` to download the full example code +.. rst-class:: sphx-glr-example-title + +.. _sphx_glr_auto_examples_plot_bootstrap_comparison.py: + + +======================== +ODP Bootstrap Comparison +======================== + +This example demonstrates how you can drop the outlier link ratios from the +BootstrapODPSample to reduce reserve variability estimates. + + + + +.. image:: /auto_examples/images/sphx_glr_plot_bootstrap_comparison_001.png + :class: sphx-glr-single-img + + +.. rst-class:: sphx-glr-script-out + + Out: + + .. code-block:: none + + c:\users\jboga\onedrive\documents\github\chainladder-python\chainladder\development\bootstrap.py:64: UserWarning: Process risk not yet implemented... + warn('Process risk not yet implemented...') + c:\users\jboga\onedrive\documents\github\chainladder-python\chainladder\development\base.py:149: UserWarning: drop_high and drop_low cannot be computed when less than three LDFs are present. Ignoring exclusions in some cases. + warnings.warn('drop_high and drop_low cannot be computed ' + c:\users\jboga\onedrive\documents\github\chainladder-python\chainladder\utils\weighted_regression.py:58: RuntimeWarning: invalid value encountered in sqrt + residual = (y-fitted_value)*np.sqrt(w) + c:\users\jboga\onedrive\documents\github\chainladder-python\chainladder\development\base.py:228: RuntimeWarning: invalid value encountered in sqrt + np.swapaxes(np.sqrt(x**(2-val))[..., 0:1, :], -1, -2)) + + + + + + + +| + + +.. code-block:: default + + import chainladder as cl + + import seaborn as sns + sns.set_style('whitegrid') + + # Load triangle + triangle = cl.load_dataset('raa') + + # Use bootstrap sampler to get resampled triangles + s1 = cl.BootstrapODPSample( + n_sims=5000, random_state=42).fit(triangle).resampled_triangles_ + + ## Alternatively use fit_transform() to access resampled triangles dropping + # outlier link-ratios from resampler + s2 = cl.BootstrapODPSample( + drop_high=True, drop_low=True, + n_sims=5000, random_state=42).fit_transform(triangle) + + # Summarize results of first model + results = cl.Chainladder().fit(s1).ibnr_.sum('origin').rename('columns', ['Original']) + # Add another column to triangle with second set of results. + results['Dropped'] = cl.Chainladder().fit(s2).ibnr_.sum('origin') + + # Plot both IBNR distributions + results.to_frame().plot(kind='hist', bins=50, alpha=0.5) + + +.. rst-class:: sphx-glr-timing + + **Total running time of the script:** ( 0 minutes 9.323 seconds) + + +.. _sphx_glr_download_auto_examples_plot_bootstrap_comparison.py: + + +.. only :: html + + .. container:: sphx-glr-footer + :class: sphx-glr-footer-example + + + + .. container:: sphx-glr-download + + :download:`Download Python source code: plot_bootstrap_comparison.py ` + + + + .. container:: sphx-glr-download + + :download:`Download Jupyter notebook: plot_bootstrap_comparison.ipynb ` + + +.. only:: html + + .. rst-class:: sphx-glr-signature + + `Gallery generated by Sphinx-Gallery `_ diff --git a/docs/auto_examples/plot_bootstrap_comparison_codeobj.pickle b/docs/auto_examples/plot_bootstrap_comparison_codeobj.pickle new file mode 100644 index 00000000..ae375107 Binary files /dev/null and b/docs/auto_examples/plot_bootstrap_comparison_codeobj.pickle differ diff --git a/docs/auto_examples/plot_capecod.rst b/docs/auto_examples/plot_capecod.rst index ac317360..2e06de81 100644 --- a/docs/auto_examples/plot_capecod.rst +++ b/docs/auto_examples/plot_capecod.rst @@ -71,7 +71,7 @@ and ``decay``. .. rst-class:: sphx-glr-timing - **Total running time of the script:** ( 0 minutes 9.717 seconds) + **Total running time of the script:** ( 0 minutes 9.773 seconds) .. _sphx_glr_download_auto_examples_plot_capecod.py: diff --git a/docs/auto_examples/plot_capecod_codeobj.pickle b/docs/auto_examples/plot_capecod_codeobj.pickle index 2e35d7f6..a6dd16be 100644 Binary files a/docs/auto_examples/plot_capecod_codeobj.pickle and b/docs/auto_examples/plot_capecod_codeobj.pickle differ diff --git a/docs/auto_examples/plot_development_periods.rst b/docs/auto_examples/plot_development_periods.rst index 044509ea..3fe22dea 100644 --- a/docs/auto_examples/plot_development_periods.rst +++ b/docs/auto_examples/plot_development_periods.rst @@ -64,7 +64,7 @@ transformer to see its influence on the overall ultimate estimate. .. rst-class:: sphx-glr-timing - **Total running time of the script:** ( 0 minutes 7.008 seconds) + **Total running time of the script:** ( 0 minutes 7.271 seconds) .. _sphx_glr_download_auto_examples_plot_development_periods.py: diff --git a/docs/auto_examples/plot_development_periods_codeobj.pickle b/docs/auto_examples/plot_development_periods_codeobj.pickle index 65139306..59130a96 100644 Binary files a/docs/auto_examples/plot_development_periods_codeobj.pickle and b/docs/auto_examples/plot_development_periods_codeobj.pickle differ diff --git a/docs/auto_examples/plot_exhibits.rst b/docs/auto_examples/plot_exhibits.rst index d0b3a014..a5f3fdd5 100644 --- a/docs/auto_examples/plot_exhibits.rst +++ b/docs/auto_examples/plot_exhibits.rst @@ -80,7 +80,7 @@ See :ref:`Exhibits` for more detail. .. rst-class:: sphx-glr-timing - **Total running time of the script:** ( 0 minutes 9.939 seconds) + **Total running time of the script:** ( 0 minutes 7.113 seconds) .. _sphx_glr_download_auto_examples_plot_exhibits.py: diff --git a/docs/auto_examples/plot_exhibits_codeobj.pickle b/docs/auto_examples/plot_exhibits_codeobj.pickle index bac76c2c..08b9b870 100644 Binary files a/docs/auto_examples/plot_exhibits_codeobj.pickle and b/docs/auto_examples/plot_exhibits_codeobj.pickle differ diff --git a/docs/auto_examples/plot_exposure_triangle.ipynb b/docs/auto_examples/plot_exposure_triangle.ipynb new file mode 100644 index 00000000..e74ddd43 --- /dev/null +++ b/docs/auto_examples/plot_exposure_triangle.ipynb @@ -0,0 +1,54 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "%matplotlib inline" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\n# Exposure Triangle\n\n\nAlthough triangles have both origin and development attributes, it is often\nconvenient to create premium or exposure vectors that can work with loss\ntriangles. The `Triangle` class treats the development parameter as\noptional. This example instantiates a 'premium' triangle as a single vector.\n\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "import chainladder as cl\nimport pandas as pd\nimport seaborn as sns\nsns.set_style('whitegrid')\n\nimport chainladder as cl\n\n# Raw premium data in pandas\npremium_df = pd.DataFrame(\n {'AccYear':[item for item in range(1977, 1988)],\n 'premium': [3000000]*11})\n\n# Create a premium 'triangle' with no development\npremium = cl.Triangle(premium_df, origin='AccYear', columns='premium')\n\n# Create some loss triangle\nloss = cl.load_dataset('abc')\nultimate = cl.Chainladder().fit(loss).ultimate_\n\n# Plot\n(ultimate / premium).plot(\n kind='area', title='Loss Ratio by Accident Year',\n alpha=0.7, color='darkgreen', legend=False);" + ] + } + ], + "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 +} \ No newline at end of file diff --git a/docs/auto_examples/plot_exposure_triangle.py b/docs/auto_examples/plot_exposure_triangle.py new file mode 100644 index 00000000..4a2d5701 --- /dev/null +++ b/docs/auto_examples/plot_exposure_triangle.py @@ -0,0 +1,34 @@ +""" +================= +Exposure Triangle +================= + +Although triangles have both origin and development attributes, it is often +convenient to create premium or exposure vectors that can work with loss +triangles. The `Triangle` class treats the development parameter as +optional. This example instantiates a 'premium' triangle as a single vector. +""" + +import chainladder as cl +import pandas as pd +import seaborn as sns +sns.set_style('whitegrid') + +import chainladder as cl + +# Raw premium data in pandas +premium_df = pd.DataFrame( + {'AccYear':[item for item in range(1977, 1988)], + 'premium': [3000000]*11}) + +# Create a premium 'triangle' with no development +premium = cl.Triangle(premium_df, origin='AccYear', columns='premium') + +# Create some loss triangle +loss = cl.load_dataset('abc') +ultimate = cl.Chainladder().fit(loss).ultimate_ + +# Plot +(ultimate / premium).plot( + kind='area', title='Loss Ratio by Accident Year', + alpha=0.7, color='darkgreen', legend=False); diff --git a/docs/auto_examples/plot_exposure_triangle.py.md5 b/docs/auto_examples/plot_exposure_triangle.py.md5 new file mode 100644 index 00000000..85147c2d --- /dev/null +++ b/docs/auto_examples/plot_exposure_triangle.py.md5 @@ -0,0 +1 @@ +dcc3f3b1cd5838b713a52b013fbf6253 \ No newline at end of file diff --git a/docs/auto_examples/plot_exposure_triangle.rst b/docs/auto_examples/plot_exposure_triangle.rst new file mode 100644 index 00000000..e468c695 --- /dev/null +++ b/docs/auto_examples/plot_exposure_triangle.rst @@ -0,0 +1,99 @@ +.. note:: + :class: sphx-glr-download-link-note + + Click :ref:`here ` to download the full example code +.. rst-class:: sphx-glr-example-title + +.. _sphx_glr_auto_examples_plot_exposure_triangle.py: + + +================= +Exposure Triangle +================= + +Although triangles have both origin and development attributes, it is often +convenient to create premium or exposure vectors that can work with loss +triangles. The `Triangle` class treats the development parameter as +optional. This example instantiates a 'premium' triangle as a single vector. + + + +.. image:: /auto_examples/images/sphx_glr_plot_exposure_triangle_001.png + :class: sphx-glr-single-img + + +.. rst-class:: sphx-glr-script-out + + Out: + + .. code-block:: none + + + + + + + + +| + + +.. code-block:: default + + + import chainladder as cl + import pandas as pd + import seaborn as sns + sns.set_style('whitegrid') + + import chainladder as cl + + # Raw premium data in pandas + premium_df = pd.DataFrame( + {'AccYear':[item for item in range(1977, 1988)], + 'premium': [3000000]*11}) + + # Create a premium 'triangle' with no development + premium = cl.Triangle(premium_df, origin='AccYear', columns='premium') + + # Create some loss triangle + loss = cl.load_dataset('abc') + ultimate = cl.Chainladder().fit(loss).ultimate_ + + # Plot + (ultimate / premium).plot( + kind='area', title='Loss Ratio by Accident Year', + alpha=0.7, color='darkgreen', legend=False); + + +.. rst-class:: sphx-glr-timing + + **Total running time of the script:** ( 0 minutes 1.169 seconds) + + +.. _sphx_glr_download_auto_examples_plot_exposure_triangle.py: + + +.. only :: html + + .. container:: sphx-glr-footer + :class: sphx-glr-footer-example + + + + .. container:: sphx-glr-download + + :download:`Download Python source code: plot_exposure_triangle.py ` + + + + .. container:: sphx-glr-download + + :download:`Download Jupyter notebook: plot_exposure_triangle.ipynb ` + + +.. only:: html + + .. rst-class:: sphx-glr-signature + + `Gallery generated by Sphinx-Gallery `_ diff --git a/docs/auto_examples/plot_exposure_triangle_codeobj.pickle b/docs/auto_examples/plot_exposure_triangle_codeobj.pickle new file mode 100644 index 00000000..098cc348 Binary files /dev/null and b/docs/auto_examples/plot_exposure_triangle_codeobj.pickle differ diff --git a/docs/auto_examples/plot_ibnr_runoff.ipynb b/docs/auto_examples/plot_ibnr_runoff.ipynb new file mode 100644 index 00000000..04f36644 --- /dev/null +++ b/docs/auto_examples/plot_ibnr_runoff.ipynb @@ -0,0 +1,54 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "%matplotlib inline" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\n# IBNR Runoff\n\n\nAll IBNR models spin off several results triangles including `inbr_`,\n`ultimate_`, `full_expectation`, and `full_triangle_`. These can be\nmanipulated into a variety of formats. This example demonstrates how to\ncreate a calendar year runoff of IBNR.\n\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "import chainladder as cl\nimport seaborn as sns\nsns.set_style('whitegrid')\n\n# Create a triangle\ntriangle = cl.load_dataset('GenIns')\n\n# Fit a model\nmodel = cl.Chainladder().fit(triangle)\n\n# Develop IBNR runoff triangle\nrunoff = (model.full_triangle_.cum_to_incr() - triangle.cum_to_incr())\n\n# Convert to calendar period and aggregate across all accident years\ncal_yr_runoff = runoff.dev_to_val().dropna().sum(axis='origin')\n\n# Plot results\ncal_yr_runoff.T.plot(kind='bar', legend=False, color='red',\n title='GenIns: IBNR Run-off', alpha=0.7) \\\n .set(xlabel='Calendar Year', ylabel='IBNR');" + ] + } + ], + "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 +} \ No newline at end of file diff --git a/docs/auto_examples/plot_ibnr_runoff.py b/docs/auto_examples/plot_ibnr_runoff.py new file mode 100644 index 00000000..70fedf59 --- /dev/null +++ b/docs/auto_examples/plot_ibnr_runoff.py @@ -0,0 +1,31 @@ +""" +============ +IBNR Runoff +============ + +All IBNR models spin off several results triangles including `inbr_`, +`ultimate_`, `full_expectation`, and `full_triangle_`. These can be +manipulated into a variety of formats. This example demonstrates how to +create a calendar year runoff of IBNR. +""" + +import chainladder as cl +import seaborn as sns +sns.set_style('whitegrid') + +# Create a triangle +triangle = cl.load_dataset('GenIns') + +# Fit a model +model = cl.Chainladder().fit(triangle) + +# Develop IBNR runoff triangle +runoff = (model.full_triangle_.cum_to_incr() - triangle.cum_to_incr()) + +# Convert to calendar period and aggregate across all accident years +cal_yr_runoff = runoff.dev_to_val().dropna().sum(axis='origin') + +# Plot results +cal_yr_runoff.T.plot(kind='bar', legend=False, color='red', + title='GenIns: IBNR Run-off', alpha=0.7) \ + .set(xlabel='Calendar Year', ylabel='IBNR'); diff --git a/docs/auto_examples/plot_ibnr_runoff.py.md5 b/docs/auto_examples/plot_ibnr_runoff.py.md5 new file mode 100644 index 00000000..f43b6d3e --- /dev/null +++ b/docs/auto_examples/plot_ibnr_runoff.py.md5 @@ -0,0 +1 @@ +312dd6e8e17a275f03627a08e81b97bd \ No newline at end of file diff --git a/docs/auto_examples/plot_ibnr_runoff.rst b/docs/auto_examples/plot_ibnr_runoff.rst new file mode 100644 index 00000000..cd3d7bf9 --- /dev/null +++ b/docs/auto_examples/plot_ibnr_runoff.rst @@ -0,0 +1,96 @@ +.. note:: + :class: sphx-glr-download-link-note + + Click :ref:`here ` to download the full example code +.. rst-class:: sphx-glr-example-title + +.. _sphx_glr_auto_examples_plot_ibnr_runoff.py: + + +============ +IBNR Runoff +============ + +All IBNR models spin off several results triangles including `inbr_`, +`ultimate_`, `full_expectation`, and `full_triangle_`. These can be +manipulated into a variety of formats. This example demonstrates how to +create a calendar year runoff of IBNR. + + + +.. image:: /auto_examples/images/sphx_glr_plot_ibnr_runoff_001.png + :class: sphx-glr-single-img + + +.. rst-class:: sphx-glr-script-out + + Out: + + .. code-block:: none + + + [Text(0,0.5,'IBNR'), Text(0.5,0,'Calendar Year')] + + + + + +| + + +.. code-block:: default + + + import chainladder as cl + import seaborn as sns + sns.set_style('whitegrid') + + # Create a triangle + triangle = cl.load_dataset('GenIns') + + # Fit a model + model = cl.Chainladder().fit(triangle) + + # Develop IBNR runoff triangle + runoff = (model.full_triangle_.cum_to_incr() - triangle.cum_to_incr()) + + # Convert to calendar period and aggregate across all accident years + cal_yr_runoff = runoff.dev_to_val().dropna().sum(axis='origin') + + # Plot results + cal_yr_runoff.T.plot(kind='bar', legend=False, color='red', + title='GenIns: IBNR Run-off', alpha=0.7) \ + .set(xlabel='Calendar Year', ylabel='IBNR'); + + +.. rst-class:: sphx-glr-timing + + **Total running time of the script:** ( 0 minutes 0.960 seconds) + + +.. _sphx_glr_download_auto_examples_plot_ibnr_runoff.py: + + +.. only :: html + + .. container:: sphx-glr-footer + :class: sphx-glr-footer-example + + + + .. container:: sphx-glr-download + + :download:`Download Python source code: plot_ibnr_runoff.py ` + + + + .. container:: sphx-glr-download + + :download:`Download Jupyter notebook: plot_ibnr_runoff.ipynb ` + + +.. only:: html + + .. rst-class:: sphx-glr-signature + + `Gallery generated by Sphinx-Gallery `_ diff --git a/docs/auto_examples/plot_ibnr_runoff_codeobj.pickle b/docs/auto_examples/plot_ibnr_runoff_codeobj.pickle new file mode 100644 index 00000000..a576ca28 Binary files /dev/null and b/docs/auto_examples/plot_ibnr_runoff_codeobj.pickle differ diff --git a/docs/auto_examples/plot_industry_to_company.ipynb b/docs/auto_examples/plot_industry_to_company.ipynb index 8cdeeb1a..aa838ea8 100644 --- a/docs/auto_examples/plot_industry_to_company.ipynb +++ b/docs/auto_examples/plot_industry_to_company.ipynb @@ -26,7 +26,7 @@ }, "outputs": [], "source": [ - "import chainladder as cl\n\nclrd = cl.load_dataset('clrd')['CumPaidLoss']\nclrd = clrd[clrd['LOB'] == 'wkcomp']\n\nindustry = clrd.sum()\nallstate_industry_cl = cl.Chainladder().fit(industry).predict(clrd).ultimate_.loc['Allstate Ins Co Grp']\nallstate_company_cl = cl.Chainladder().fit(clrd.loc['Allstate Ins Co Grp']).ultimate_\ndiff = (allstate_industry_cl - allstate_company_cl)\n\nprint(diff.rename('development',['Industry to Company LDF Diff']))" + "import chainladder as cl\n\nclrd = cl.load_dataset('clrd')['CumPaidLoss']\nclrd = clrd[clrd['LOB'] == 'wkcomp']\n\nindustry = clrd.sum()\nallstate_industry_cl = cl.Chainladder().fit(industry).predict(clrd.loc['Allstate Ins Co Grp']).ultimate_\nallstate_company_cl = cl.Chainladder().fit(clrd.loc['Allstate Ins Co Grp']).ultimate_\ndiff = (allstate_industry_cl - allstate_company_cl)\n\nprint(diff.rename('development',['Industry to Company LDF Diff']))" ] } ], diff --git a/docs/auto_examples/plot_industry_to_company.py b/docs/auto_examples/plot_industry_to_company.py index acb0fb34..74e77d97 100644 --- a/docs/auto_examples/plot_industry_to_company.py +++ b/docs/auto_examples/plot_industry_to_company.py @@ -12,7 +12,7 @@ clrd = clrd[clrd['LOB'] == 'wkcomp'] industry = clrd.sum() -allstate_industry_cl = cl.Chainladder().fit(industry).predict(clrd).ultimate_.loc['Allstate Ins Co Grp'] +allstate_industry_cl = cl.Chainladder().fit(industry).predict(clrd.loc['Allstate Ins Co Grp']).ultimate_ allstate_company_cl = cl.Chainladder().fit(clrd.loc['Allstate Ins Co Grp']).ultimate_ diff = (allstate_industry_cl - allstate_company_cl) diff --git a/docs/auto_examples/plot_industry_to_company.py.md5 b/docs/auto_examples/plot_industry_to_company.py.md5 index f63b0a41..b058b941 100644 --- a/docs/auto_examples/plot_industry_to_company.py.md5 +++ b/docs/auto_examples/plot_industry_to_company.py.md5 @@ -1 +1 @@ -3ed5458775372b9208b619e5a01949a8 \ No newline at end of file +7fea55f6f48c4ae06097f5fb1308d7eb \ No newline at end of file diff --git a/docs/auto_examples/plot_industry_to_company.rst b/docs/auto_examples/plot_industry_to_company.rst index a19ac9b4..c8427f93 100644 --- a/docs/auto_examples/plot_industry_to_company.rst +++ b/docs/auto_examples/plot_industry_to_company.rst @@ -23,30 +23,6 @@ particular ``index`` grain and apply them to another. .. code-block:: none - c:\users\jboga\onedrive\documents\github\chainladder-python\chainladder\utils\weighted_regression.py:54: RuntimeWarning: divide by zero encountered in true_divide - coef = np.nansum(w*x*y, axis)/np.nansum((y*0+1)*w*x*x, axis) - c:\users\jboga\onedrive\documents\github\chainladder-python\chainladder\utils\weighted_regression.py:54: RuntimeWarning: invalid value encountered in true_divide - coef = np.nansum(w*x*y, axis)/np.nansum((y*0+1)*w*x*x, axis) - c:\users\jboga\onedrive\documents\github\chainladder-python\chainladder\utils\weighted_regression.py:58: RuntimeWarning: invalid value encountered in sqrt - residual = (y-fitted_value)*np.sqrt(w) - c:\users\jboga\onedrive\documents\github\chainladder-python\chainladder\utils\weighted_regression.py:63: RuntimeWarning: invalid value encountered in true_divide - std_err = np.sqrt(mse/np.nansum(w*x*x*(y*0+1), axis)) - c:\users\jboga\onedrive\documents\github\chainladder-python\chainladder\utils\weighted_regression.py:92: RuntimeWarning: invalid value encountered in multiply - w = np.nan_to_num(ly*0+1) - c:\users\jboga\onedrive\documents\github\chainladder-python\chainladder\utils\weighted_regression.py:45: RuntimeWarning: Mean of empty slice - (np.nansum(w*x*y, axis)-np.nansum(x*w, axis)*np.nanmean(y, axis)) / - c:\users\jboga\onedrive\documents\github\chainladder-python\chainladder\utils\weighted_regression.py:46: RuntimeWarning: Mean of empty slice - (np.nansum(w*x*x, axis)-np.nanmean(x, axis)*np.nansum(w*x, axis))) - c:\users\jboga\onedrive\documents\github\chainladder-python\chainladder\utils\weighted_regression.py:46: RuntimeWarning: invalid value encountered in true_divide - (np.nansum(w*x*x, axis)-np.nanmean(x, axis)*np.nansum(w*x, axis))) - c:\users\jboga\onedrive\documents\github\chainladder-python\chainladder\utils\weighted_regression.py:47: RuntimeWarning: Mean of empty slice - intercept = np.nanmean(y, axis) - slope * np.nanmean(x, axis) - c:\users\jboga\onedrive\documents\github\chainladder-python\chainladder\development\base.py:227: RuntimeWarning: invalid value encountered in multiply - params.sigma_ / - c:\users\jboga\onedrive\documents\github\chainladder-python\chainladder\development\base.py:228: RuntimeWarning: invalid value encountered in sqrt - np.swapaxes(np.sqrt(x**(2-val))[..., 0:1, :], -1, -2)) - c:\users\jboga\onedrive\documents\github\chainladder-python\chainladder\development\base.py:228: RuntimeWarning: overflow encountered in add - np.swapaxes(np.sqrt(x**(2-val))[..., 0:1, :], -1, -2)) Industry to Company LDF Diff 1988 NaN 1989 -202.830662 @@ -75,7 +51,7 @@ particular ``index`` grain and apply them to another. clrd = clrd[clrd['LOB'] == 'wkcomp'] industry = clrd.sum() - allstate_industry_cl = cl.Chainladder().fit(industry).predict(clrd).ultimate_.loc['Allstate Ins Co Grp'] + allstate_industry_cl = cl.Chainladder().fit(industry).predict(clrd.loc['Allstate Ins Co Grp']).ultimate_ allstate_company_cl = cl.Chainladder().fit(clrd.loc['Allstate Ins Co Grp']).ultimate_ diff = (allstate_industry_cl - allstate_company_cl) @@ -84,7 +60,7 @@ particular ``index`` grain and apply them to another. .. rst-class:: sphx-glr-timing - **Total running time of the script:** ( 0 minutes 4.303 seconds) + **Total running time of the script:** ( 0 minutes 4.280 seconds) .. _sphx_glr_download_auto_examples_plot_industry_to_company.py: diff --git a/docs/auto_examples/plot_industry_to_company_codeobj.pickle b/docs/auto_examples/plot_industry_to_company_codeobj.pickle index 7525c90d..7fd28d11 100644 Binary files a/docs/auto_examples/plot_industry_to_company_codeobj.pickle and b/docs/auto_examples/plot_industry_to_company_codeobj.pickle differ diff --git a/docs/auto_examples/plot_mack.rst b/docs/auto_examples/plot_mack.rst index 2c03cd5e..974c1b00 100644 --- a/docs/auto_examples/plot_mack.rst +++ b/docs/auto_examples/plot_mack.rst @@ -64,7 +64,7 @@ This example demonstrates how you can can use the Mack Chainladder method. .. rst-class:: sphx-glr-timing - **Total running time of the script:** ( 0 minutes 1.516 seconds) + **Total running time of the script:** ( 0 minutes 1.419 seconds) .. _sphx_glr_download_auto_examples_plot_mack.py: diff --git a/docs/auto_examples/plot_mack_codeobj.pickle b/docs/auto_examples/plot_mack_codeobj.pickle index b09dcc38..f33a140d 100644 Binary files a/docs/auto_examples/plot_mack_codeobj.pickle and b/docs/auto_examples/plot_mack_codeobj.pickle differ diff --git a/docs/auto_examples/plot_munich.rst b/docs/auto_examples/plot_munich.rst index 3d5282e8..48d45d0f 100644 --- a/docs/auto_examples/plot_munich.rst +++ b/docs/auto_examples/plot_munich.rst @@ -64,7 +64,7 @@ and Incurred using the MunichAdjustment. .. rst-class:: sphx-glr-timing - **Total running time of the script:** ( 0 minutes 1.975 seconds) + **Total running time of the script:** ( 0 minutes 1.898 seconds) .. _sphx_glr_download_auto_examples_plot_munich.py: diff --git a/docs/auto_examples/plot_munich_codeobj.pickle b/docs/auto_examples/plot_munich_codeobj.pickle index 027a5e58..8ebfdb0a 100644 Binary files a/docs/auto_examples/plot_munich_codeobj.pickle and b/docs/auto_examples/plot_munich_codeobj.pickle differ diff --git a/docs/auto_examples/plot_stochastic_bornferg.ipynb b/docs/auto_examples/plot_stochastic_bornferg.ipynb new file mode 100644 index 00000000..2052a704 --- /dev/null +++ b/docs/auto_examples/plot_stochastic_bornferg.ipynb @@ -0,0 +1,54 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "%matplotlib inline" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\n# Stochastic Bornhuetter Ferguson\n\n\nThere are several aspects of the chainladder module that are demonstrated with\nthis example.\n\n1. We see how to use the `BootstrapODPSample` and `BornhuetterFerguson` to come\n up with a stochastic view of the Bornhuetter-Ferguson method.\n2. We see how we can use the `Triangle.values` property `numpy` to modify the\n the data underlying the Triangle\n3. We use the `broadcast_axis` method of the triangle class (new in 0.4.7)\n\n\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "import chainladder as cl\nimport numpy as np\n\n# Simulation parameters\nrandom_state = 42\nn_sims = 1000\n\n# Get data\nloss = cl.load_dataset('genins')\npremium = loss.latest_diagonal*0+8e6\n\n# Simulate loss triangles\nsim = cl.BootstrapODPSample(random_state=random_state, n_sims=n_sims)\nsim.fit(loss, sample_weight=premium)\n\n# Repeat the premium triangle to align with simulated losses\nsim_p = premium.broadcast_axis('index', sim.resampled_triangles_.index)\n\n# Simulate aprioris using numpy\napriori_mu = 0.65\napriori_sigma = .10\naprioris = np.random.normal(apriori_mu, apriori_sigma, n_sims)\nsim_p.values = (sim_p.values * aprioris.reshape(n_sims,-1)[..., np.newaxis, np.newaxis])\n\n# Fit Bornhuetter-Ferguson to stochastically generated data\nmodel = cl.BornhuetterFerguson().fit(sim.resampled_triangles_, sample_weight=sim_p)\n\n# Grab completed triangle replacing simulated known data with actual known data\nfull_triangle = model.full_triangle_ - model.X_ + \\\n loss.broadcast_axis('index', sim.resampled_triangles_.index)\n\n# Limiting to the current year for plotting\ncurrent_year = full_triangle[full_triangle.origin==full_triangle.origin.max()].to_frame().T\n\n# Plot the data\ncurrent_year.reset_index(drop=True).plot(\n color='orange', legend=False, alpha=0.1,\n title='Current Accident Year BornFerg Distribution', grid=True);" + ] + } + ], + "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 +} \ No newline at end of file diff --git a/docs/auto_examples/plot_stochastic_bornferg.py b/docs/auto_examples/plot_stochastic_bornferg.py new file mode 100644 index 00000000..7136c752 --- /dev/null +++ b/docs/auto_examples/plot_stochastic_bornferg.py @@ -0,0 +1,53 @@ +""" +================================ +Stochastic Bornhuetter Ferguson +================================ + +There are several aspects of the chainladder module that are demonstrated with +this example. + +1. We see how to use the `BootstrapODPSample` and `BornhuetterFerguson` to come + up with a stochastic view of the Bornhuetter-Ferguson method. +2. We see how we can use the `Triangle.values` property `numpy` to modify the + the data underlying the Triangle +3. We use the `broadcast_axis` method of the triangle class (new in 0.4.7) + +""" +import chainladder as cl +import numpy as np + +# Simulation parameters +random_state = 42 +n_sims = 1000 + +# Get data +loss = cl.load_dataset('genins') +premium = loss.latest_diagonal*0+8e6 + +# Simulate loss triangles +sim = cl.BootstrapODPSample(random_state=random_state, n_sims=n_sims) +sim.fit(loss, sample_weight=premium) + +# Repeat the premium triangle to align with simulated losses +sim_p = premium.broadcast_axis('index', sim.resampled_triangles_.index) + +# Simulate aprioris using numpy +apriori_mu = 0.65 +apriori_sigma = .10 +aprioris = np.random.normal(apriori_mu, apriori_sigma, n_sims) +sim_p.values = (sim_p.values * aprioris.reshape(n_sims,-1)[..., np.newaxis, np.newaxis]) + +# Fit Bornhuetter-Ferguson to stochastically generated data +model = cl.BornhuetterFerguson().fit(sim.resampled_triangles_, sample_weight=sim_p) + +# Grab completed triangle replacing simulated known data with actual known data +full_triangle = model.full_triangle_ - model.X_ + \ + loss.broadcast_axis('index', sim.resampled_triangles_.index) + +# Limiting to the current year for plotting +current_year = full_triangle[full_triangle.origin==full_triangle.origin.max()].to_frame().T + +# Plot the data +current_year.reset_index(drop=True).plot( + color='orange', legend=False, alpha=0.1, + title='Current Accident Year BornFerg Distribution', grid=True); diff --git a/docs/auto_examples/plot_stochastic_bornferg.py.md5 b/docs/auto_examples/plot_stochastic_bornferg.py.md5 new file mode 100644 index 00000000..157069e9 --- /dev/null +++ b/docs/auto_examples/plot_stochastic_bornferg.py.md5 @@ -0,0 +1 @@ +fda7e7a947a9b21b4741c8cf611c4820 \ No newline at end of file diff --git a/docs/auto_examples/plot_stochastic_bornferg.rst b/docs/auto_examples/plot_stochastic_bornferg.rst new file mode 100644 index 00000000..2c723826 --- /dev/null +++ b/docs/auto_examples/plot_stochastic_bornferg.rst @@ -0,0 +1,120 @@ +.. note:: + :class: sphx-glr-download-link-note + + Click :ref:`here ` to download the full example code +.. rst-class:: sphx-glr-example-title + +.. _sphx_glr_auto_examples_plot_stochastic_bornferg.py: + + +================================ +Stochastic Bornhuetter Ferguson +================================ + +There are several aspects of the chainladder module that are demonstrated with +this example. + +1. We see how to use the `BootstrapODPSample` and `BornhuetterFerguson` to come + up with a stochastic view of the Bornhuetter-Ferguson method. +2. We see how we can use the `Triangle.values` property `numpy` to modify the + the data underlying the Triangle +3. We use the `broadcast_axis` method of the triangle class (new in 0.4.7) + + + + +.. image:: /auto_examples/images/sphx_glr_plot_stochastic_bornferg_001.png + :class: sphx-glr-single-img + + +.. rst-class:: sphx-glr-script-out + + Out: + + .. code-block:: none + + c:\users\jboga\onedrive\documents\github\chainladder-python\chainladder\development\bootstrap.py:64: UserWarning: Process risk not yet implemented... + warn('Process risk not yet implemented...') + + + + + + + +| + + +.. code-block:: default + + import chainladder as cl + import numpy as np + + # Simulation parameters + random_state = 42 + n_sims = 1000 + + # Get data + loss = cl.load_dataset('genins') + premium = loss.latest_diagonal*0+8e6 + + # Simulate loss triangles + sim = cl.BootstrapODPSample(random_state=random_state, n_sims=n_sims) + sim.fit(loss, sample_weight=premium) + + # Repeat the premium triangle to align with simulated losses + sim_p = premium.broadcast_axis('index', sim.resampled_triangles_.index) + + # Simulate aprioris using numpy + apriori_mu = 0.65 + apriori_sigma = .10 + aprioris = np.random.normal(apriori_mu, apriori_sigma, n_sims) + sim_p.values = (sim_p.values * aprioris.reshape(n_sims,-1)[..., np.newaxis, np.newaxis]) + + # Fit Bornhuetter-Ferguson to stochastically generated data + model = cl.BornhuetterFerguson().fit(sim.resampled_triangles_, sample_weight=sim_p) + + # Grab completed triangle replacing simulated known data with actual known data + full_triangle = model.full_triangle_ - model.X_ + \ + loss.broadcast_axis('index', sim.resampled_triangles_.index) + + # Limiting to the current year for plotting + current_year = full_triangle[full_triangle.origin==full_triangle.origin.max()].to_frame().T + + # Plot the data + current_year.reset_index(drop=True).plot( + color='orange', legend=False, alpha=0.1, + title='Current Accident Year BornFerg Distribution', grid=True); + + +.. rst-class:: sphx-glr-timing + + **Total running time of the script:** ( 0 minutes 17.268 seconds) + + +.. _sphx_glr_download_auto_examples_plot_stochastic_bornferg.py: + + +.. only :: html + + .. container:: sphx-glr-footer + :class: sphx-glr-footer-example + + + + .. container:: sphx-glr-download + + :download:`Download Python source code: plot_stochastic_bornferg.py ` + + + + .. container:: sphx-glr-download + + :download:`Download Jupyter notebook: plot_stochastic_bornferg.ipynb ` + + +.. only:: html + + .. rst-class:: sphx-glr-signature + + `Gallery generated by Sphinx-Gallery `_ diff --git a/docs/auto_examples/plot_stochastic_bornferg_codeobj.pickle b/docs/auto_examples/plot_stochastic_bornferg_codeobj.pickle new file mode 100644 index 00000000..8fdf0409 Binary files /dev/null and b/docs/auto_examples/plot_stochastic_bornferg_codeobj.pickle differ diff --git a/docs/auto_examples/plot_triangle_from_pandas.ipynb b/docs/auto_examples/plot_triangle_from_pandas.ipynb index 4e31c5e3..de8d8ffd 100644 --- a/docs/auto_examples/plot_triangle_from_pandas.ipynb +++ b/docs/auto_examples/plot_triangle_from_pandas.ipynb @@ -26,7 +26,7 @@ }, "outputs": [], "source": [ - "import chainladder as cl\nimport pandas as pd\nimport seaborn as sns\nimport matplotlib.pyplot as plt\n\n# Read in the data\nlobs = 'wkcomp'\ndata = pd.read_csv(r'https://www.casact.org/research/reserve_data/wkcomp_pos.csv')\ndata = data[data['DevelopmentYear']<=1997]\n\n# Create a triangle\ntriangle = cl.Triangle(data, origin='AccidentYear',\n development='DevelopmentYear',\n index=['GRNAME'],\n columns=['IncurLoss_D','CumPaidLoss_D','EarnedPremDIR_D'])\n\n# Output\nprint('Raw data:')\nprint(data.head())\nprint()\nprint('Triangle summary:')\nprint(triangle)\nprint()\nprint('Aggregate Paid Triangle:')\nprint(triangle['CumPaidLoss_D'].sum())\n\n\nplot_data = triangle['CumPaidLoss_D'].sum().to_frame().unstack().reset_index()\nplot_data.columns = ['Development Period', 'Accident Year', 'Cumulative Paid Loss']\n\nsns.set_style('whitegrid')\nplt.title('CAS Loss Reserve Database: Workers'' Compensation')\ng = sns.pointplot(x='Development Period', y='Cumulative Paid Loss',\n hue='Accident Year', data=plot_data, markers='.')" + "import chainladder as cl\nimport pandas as pd\nimport seaborn as sns\nimport matplotlib.pyplot as plt\n\n# Read in the data\nlobs = 'wkcomp'\ndata = pd.read_csv(r'https://www.casact.org/research/reserve_data/wkcomp_pos.csv')\ndata = data[data['DevelopmentYear']<=1997]\n\n# Create a triangle\ntriangle = cl.Triangle(\n data, origin='AccidentYear', development='DevelopmentYear',\n index=['GRNAME'], columns=['IncurLoss_D','CumPaidLoss_D','EarnedPremDIR_D'])\n\n# Output\nprint('Raw data:')\nprint(data.head())\nprint()\nprint('Triangle summary:')\nprint(triangle)\nprint()\nprint('Aggregate Paid Triangle:')\nprint(triangle['CumPaidLoss_D'].sum())\n\n# Plot data\nax = triangle['CumPaidLoss_D'].sum().T.plot(\n marker='.', title='CAS Loss Reserve Database: Workers Compensation');\nax.set(xlabel='Development Period', ylabel='Cumulative Paid Loss')\n\nplt.show()" ] } ], diff --git a/docs/auto_examples/plot_triangle_from_pandas.py b/docs/auto_examples/plot_triangle_from_pandas.py index 14714a12..bde2efc0 100644 --- a/docs/auto_examples/plot_triangle_from_pandas.py +++ b/docs/auto_examples/plot_triangle_from_pandas.py @@ -24,10 +24,9 @@ data = data[data['DevelopmentYear']<=1997] # Create a triangle -triangle = cl.Triangle(data, origin='AccidentYear', - development='DevelopmentYear', - index=['GRNAME'], - columns=['IncurLoss_D','CumPaidLoss_D','EarnedPremDIR_D']) +triangle = cl.Triangle( + data, origin='AccidentYear', development='DevelopmentYear', + index=['GRNAME'], columns=['IncurLoss_D','CumPaidLoss_D','EarnedPremDIR_D']) # Output print('Raw data:') @@ -39,11 +38,9 @@ print('Aggregate Paid Triangle:') print(triangle['CumPaidLoss_D'].sum()) +# Plot data +ax = triangle['CumPaidLoss_D'].sum().T.plot( + marker='.', title='CAS Loss Reserve Database: Workers Compensation'); +ax.set(xlabel='Development Period', ylabel='Cumulative Paid Loss') -plot_data = triangle['CumPaidLoss_D'].sum().to_frame().unstack().reset_index() -plot_data.columns = ['Development Period', 'Accident Year', 'Cumulative Paid Loss'] - -sns.set_style('whitegrid') -plt.title('CAS Loss Reserve Database: Workers'' Compensation') -g = sns.pointplot(x='Development Period', y='Cumulative Paid Loss', - hue='Accident Year', data=plot_data, markers='.') +plt.show() diff --git a/docs/auto_examples/plot_triangle_from_pandas.py.md5 b/docs/auto_examples/plot_triangle_from_pandas.py.md5 index 8173c740..4c5a1ac0 100644 --- a/docs/auto_examples/plot_triangle_from_pandas.py.md5 +++ b/docs/auto_examples/plot_triangle_from_pandas.py.md5 @@ -1 +1 @@ -e57d90a0dc9b181d6249b18fcce0e22f \ No newline at end of file +c329885cf58ead9c74c0d9be78213bed \ No newline at end of file diff --git a/docs/auto_examples/plot_triangle_from_pandas.rst b/docs/auto_examples/plot_triangle_from_pandas.rst index f6b8fc6d..41424c68 100644 --- a/docs/auto_examples/plot_triangle_from_pandas.rst +++ b/docs/auto_examples/plot_triangle_from_pandas.rst @@ -33,12 +33,14 @@ in the CAS Loss Reserve Database for Workers' Compensation. .. code-block:: none Raw data: - GRCODE GRNAME AccidentYear DevelopmentYear DevelopmentLag IncurLoss_D CumPaidLoss_D BulkLoss_D EarnedPremDIR_D EarnedPremCeded_D EarnedPremNet_D Single PostedReserve97_D - 0 86 Allstate Ins Co Grp 1988 1988 1 367404 70571 127737 400699 5957 394742 0 281872 - 1 86 Allstate Ins Co Grp 1988 1989 2 362988 155905 60173 400699 5957 394742 0 281872 - 2 86 Allstate Ins Co Grp 1988 1990 3 347288 220744 27763 400699 5957 394742 0 281872 - 3 86 Allstate Ins Co Grp 1988 1991 4 330648 251595 15280 400699 5957 394742 0 281872 - 4 86 Allstate Ins Co Grp 1988 1992 5 354690 274156 27689 400699 5957 394742 0 281872 + GRCODE GRNAME AccidentYear ... EarnedPremNet_D Single PostedReserve97_D + 0 86 Allstate Ins Co Grp 1988 ... 394742 0 281872 + 1 86 Allstate Ins Co Grp 1988 ... 394742 0 281872 + 2 86 Allstate Ins Co Grp 1988 ... 394742 0 281872 + 3 86 Allstate Ins Co Grp 1988 ... 394742 0 281872 + 4 86 Allstate Ins Co Grp 1988 ... 394742 0 281872 + + [5 rows x 13 columns] Triangle summary: Valuation: 1997-12 @@ -59,8 +61,6 @@ in the CAS Loss Reserve Database for Workers' Compensation. 1995 343841.0 768575.0 962081.0 NaN NaN NaN NaN NaN NaN NaN 1996 381484.0 736040.0 NaN NaN NaN NaN NaN NaN NaN NaN 1997 340132.0 NaN NaN NaN NaN NaN NaN NaN NaN NaN - C:\Users\jboga\AppData\Local\Continuum\anaconda3\lib\site-packages\seaborn\categorical.py:1508: FutureWarning: remove_na is deprecated and is a private function. Do not use. - stat_data = remove_na(group_data[hue_mask]) @@ -84,10 +84,9 @@ in the CAS Loss Reserve Database for Workers' Compensation. data = data[data['DevelopmentYear']<=1997] # Create a triangle - triangle = cl.Triangle(data, origin='AccidentYear', - development='DevelopmentYear', - index=['GRNAME'], - columns=['IncurLoss_D','CumPaidLoss_D','EarnedPremDIR_D']) + triangle = cl.Triangle( + data, origin='AccidentYear', development='DevelopmentYear', + index=['GRNAME'], columns=['IncurLoss_D','CumPaidLoss_D','EarnedPremDIR_D']) # Output print('Raw data:') @@ -99,19 +98,17 @@ in the CAS Loss Reserve Database for Workers' Compensation. print('Aggregate Paid Triangle:') print(triangle['CumPaidLoss_D'].sum()) + # Plot data + ax = triangle['CumPaidLoss_D'].sum().T.plot( + marker='.', title='CAS Loss Reserve Database: Workers Compensation'); + ax.set(xlabel='Development Period', ylabel='Cumulative Paid Loss') - plot_data = triangle['CumPaidLoss_D'].sum().to_frame().unstack().reset_index() - plot_data.columns = ['Development Period', 'Accident Year', 'Cumulative Paid Loss'] - - sns.set_style('whitegrid') - plt.title('CAS Loss Reserve Database: Workers'' Compensation') - g = sns.pointplot(x='Development Period', y='Cumulative Paid Loss', - hue='Accident Year', data=plot_data, markers='.') + plt.show() .. rst-class:: sphx-glr-timing - **Total running time of the script:** ( 0 minutes 2.494 seconds) + **Total running time of the script:** ( 0 minutes 2.139 seconds) .. _sphx_glr_download_auto_examples_plot_triangle_from_pandas.py: diff --git a/docs/auto_examples/plot_triangle_from_pandas_codeobj.pickle b/docs/auto_examples/plot_triangle_from_pandas_codeobj.pickle index 7e9d8c51..8a6c556e 100644 Binary files a/docs/auto_examples/plot_triangle_from_pandas_codeobj.pickle and b/docs/auto_examples/plot_triangle_from_pandas_codeobj.pickle differ diff --git a/docs/auto_examples/plot_triangle_slicing.rst b/docs/auto_examples/plot_triangle_slicing.rst index 4a96670e..7732cf8d 100644 --- a/docs/auto_examples/plot_triangle_slicing.rst +++ b/docs/auto_examples/plot_triangle_slicing.rst @@ -51,7 +51,7 @@ This example demonstrates the familiarity of the pandas API applied to a .. rst-class:: sphx-glr-timing - **Total running time of the script:** ( 0 minutes 3.882 seconds) + **Total running time of the script:** ( 0 minutes 3.130 seconds) .. _sphx_glr_download_auto_examples_plot_triangle_slicing.py: diff --git a/docs/auto_examples/plot_triangle_slicing_codeobj.pickle b/docs/auto_examples/plot_triangle_slicing_codeobj.pickle index 4134c604..81fc40bf 100644 Binary files a/docs/auto_examples/plot_triangle_slicing_codeobj.pickle and b/docs/auto_examples/plot_triangle_slicing_codeobj.pickle differ diff --git a/docs/auto_examples/plot_value_at_risk.ipynb b/docs/auto_examples/plot_value_at_risk.ipynb new file mode 100644 index 00000000..5d292450 --- /dev/null +++ b/docs/auto_examples/plot_value_at_risk.ipynb @@ -0,0 +1,54 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "%matplotlib inline" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\n# Value at Risk example\n\n\nThis example uses the `BootstrapODPSample` to simulate new triangles that\nare then used to simulate an IBNR distribution from which we can do\nValue at Risk percentile lookups.\n\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "import chainladder as cl\nimport seaborn as sns\nsns.set_style('whitegrid')\n\n# Load triangle\ntriangle = cl.load_dataset('genins')\n\n# Create 1000 bootstrap samples of the triangle\nresampled_triangles = cl.BootstrapODPSample().fit_transform(triangle)\n\n# Create 1000 IBNR estimates\nsim_ibnr = cl.Chainladder().fit(resampled_triangles).ibnr_.sum('origin')\n\n# X - mu\nsim_ibnr = (sim_ibnr - sim_ibnr.mean()).to_frame().sort_values()\n\n# Plot data\nsim_ibnr.index = [item/1000 for item in range(1000)]\nsim_ibnr.loc[0.90:].plot(\n title='Bootstrap VaR (90% and above)', color='red').set(xlabel='VaR');" + ] + } + ], + "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 +} \ No newline at end of file diff --git a/docs/auto_examples/plot_value_at_risk.py b/docs/auto_examples/plot_value_at_risk.py new file mode 100644 index 00000000..12ca3ca1 --- /dev/null +++ b/docs/auto_examples/plot_value_at_risk.py @@ -0,0 +1,30 @@ +""" +====================== +Value at Risk example +====================== + +This example uses the `BootstrapODPSample` to simulate new triangles that +are then used to simulate an IBNR distribution from which we can do +Value at Risk percentile lookups. +""" + +import chainladder as cl +import seaborn as sns +sns.set_style('whitegrid') + +# Load triangle +triangle = cl.load_dataset('genins') + +# Create 1000 bootstrap samples of the triangle +resampled_triangles = cl.BootstrapODPSample().fit_transform(triangle) + +# Create 1000 IBNR estimates +sim_ibnr = cl.Chainladder().fit(resampled_triangles).ibnr_.sum('origin') + +# X - mu +sim_ibnr = (sim_ibnr - sim_ibnr.mean()).to_frame().sort_values() + +# Plot data +sim_ibnr.index = [item/1000 for item in range(1000)] +sim_ibnr.loc[0.90:].plot( + title='Bootstrap VaR (90% and above)', color='red').set(xlabel='VaR'); diff --git a/docs/auto_examples/plot_value_at_risk.py.md5 b/docs/auto_examples/plot_value_at_risk.py.md5 new file mode 100644 index 00000000..d862ae44 --- /dev/null +++ b/docs/auto_examples/plot_value_at_risk.py.md5 @@ -0,0 +1 @@ +76e855b641bcb50aec618d21a617129d \ No newline at end of file diff --git a/docs/auto_examples/plot_value_at_risk.rst b/docs/auto_examples/plot_value_at_risk.rst new file mode 100644 index 00000000..cf3844d7 --- /dev/null +++ b/docs/auto_examples/plot_value_at_risk.rst @@ -0,0 +1,97 @@ +.. note:: + :class: sphx-glr-download-link-note + + Click :ref:`here ` to download the full example code +.. rst-class:: sphx-glr-example-title + +.. _sphx_glr_auto_examples_plot_value_at_risk.py: + + +====================== +Value at Risk example +====================== + +This example uses the `BootstrapODPSample` to simulate new triangles that +are then used to simulate an IBNR distribution from which we can do +Value at Risk percentile lookups. + + + +.. image:: /auto_examples/images/sphx_glr_plot_value_at_risk_001.png + :class: sphx-glr-single-img + + +.. rst-class:: sphx-glr-script-out + + Out: + + .. code-block:: none + + c:\users\jboga\onedrive\documents\github\chainladder-python\chainladder\development\bootstrap.py:64: UserWarning: Process risk not yet implemented... + warn('Process risk not yet implemented...') + + [Text(0.5,0,'VaR')] + + + + + +| + + +.. code-block:: default + + + import chainladder as cl + import seaborn as sns + sns.set_style('whitegrid') + + # Load triangle + triangle = cl.load_dataset('genins') + + # Create 1000 bootstrap samples of the triangle + resampled_triangles = cl.BootstrapODPSample().fit_transform(triangle) + + # Create 1000 IBNR estimates + sim_ibnr = cl.Chainladder().fit(resampled_triangles).ibnr_.sum('origin') + + # X - mu + sim_ibnr = (sim_ibnr - sim_ibnr.mean()).to_frame().sort_values() + + # Plot data + sim_ibnr.index = [item/1000 for item in range(1000)] + sim_ibnr.loc[0.90:].plot( + title='Bootstrap VaR (90% and above)', color='red').set(xlabel='VaR'); + + +.. rst-class:: sphx-glr-timing + + **Total running time of the script:** ( 0 minutes 2.420 seconds) + + +.. _sphx_glr_download_auto_examples_plot_value_at_risk.py: + + +.. only :: html + + .. container:: sphx-glr-footer + :class: sphx-glr-footer-example + + + + .. container:: sphx-glr-download + + :download:`Download Python source code: plot_value_at_risk.py ` + + + + .. container:: sphx-glr-download + + :download:`Download Jupyter notebook: plot_value_at_risk.ipynb ` + + +.. only:: html + + .. rst-class:: sphx-glr-signature + + `Gallery generated by Sphinx-Gallery `_ diff --git a/docs/auto_examples/plot_value_at_risk_codeobj.pickle b/docs/auto_examples/plot_value_at_risk_codeobj.pickle new file mode 100644 index 00000000..72c40e8a Binary files /dev/null and b/docs/auto_examples/plot_value_at_risk_codeobj.pickle differ diff --git a/docs/auto_examples/searchindex.bak b/docs/auto_examples/searchindex.bak index 7b9b2c50..62af0824 100644 --- a/docs/auto_examples/searchindex.bak +++ b/docs/auto_examples/searchindex.bak @@ -1,3 +1,3 @@ 'C:\\Users\\jboga\\OneDrive\\Documents\\GitHub\\chainladder-python\\docs\\_build\\html\\index.html', (0, 13693) 'C:\\Users\\jboga\\OneDrive\\Documents\\GitHub\\chainladder-python\\docs\\_build\\html\\_static\\documentation_options.js', (13824, 327) -'C:\\Users\\jboga\\OneDrive\\Documents\\GitHub\\chainladder-python\\docs\\_build\\html\\searchindex.js', (14336, 36750) +'C:\\Users\\jboga\\OneDrive\\Documents\\GitHub\\chainladder-python\\docs\\_build\\html\\searchindex.js', (14336, 40893) diff --git a/docs/auto_examples/searchindex.dat b/docs/auto_examples/searchindex.dat index f66b661f..b41b8a6e 100644 Binary files a/docs/auto_examples/searchindex.dat and b/docs/auto_examples/searchindex.dat differ diff --git a/docs/auto_examples/searchindex.dir b/docs/auto_examples/searchindex.dir index 7b9b2c50..62af0824 100644 --- a/docs/auto_examples/searchindex.dir +++ b/docs/auto_examples/searchindex.dir @@ -1,3 +1,3 @@ 'C:\\Users\\jboga\\OneDrive\\Documents\\GitHub\\chainladder-python\\docs\\_build\\html\\index.html', (0, 13693) 'C:\\Users\\jboga\\OneDrive\\Documents\\GitHub\\chainladder-python\\docs\\_build\\html\\_static\\documentation_options.js', (13824, 327) -'C:\\Users\\jboga\\OneDrive\\Documents\\GitHub\\chainladder-python\\docs\\_build\\html\\searchindex.js', (14336, 36750) +'C:\\Users\\jboga\\OneDrive\\Documents\\GitHub\\chainladder-python\\docs\\_build\\html\\searchindex.js', (14336, 40893) diff --git a/docs/auto_examples/sg_execution_times.rst b/docs/auto_examples/sg_execution_times.rst index d01b5e93..9d8b36a9 100644 --- a/docs/auto_examples/sg_execution_times.rst +++ b/docs/auto_examples/sg_execution_times.rst @@ -5,30 +5,40 @@ Computation times ================= -**01:31.000** total execution time for **auto_examples** files: +**00:30.622** total execution time for **auto_examples** files: +-----------------------------------------------------------------------------------------------+-----------+--------+ -| :ref:`sphx_glr_auto_examples_plot_benktander.py` (``plot_benktander.py``) | 00:30.942 | 0.0 MB | +| :ref:`sphx_glr_auto_examples_plot_stochastic_bornferg.py` (``plot_stochastic_bornferg.py``) | 00:17.268 | 0.0 MB | +-----------------------------------------------------------------------------------------------+-----------+--------+ -| :ref:`sphx_glr_auto_examples_plot_bootstrap.py` (``plot_bootstrap.py``) | 00:14.352 | 0.0 MB | +| :ref:`sphx_glr_auto_examples_plot_bootstrap.py` (``plot_bootstrap.py``) | 00:13.354 | 0.0 MB | +-----------------------------------------------------------------------------------------------+-----------+--------+ -| :ref:`sphx_glr_auto_examples_plot_exhibits.py` (``plot_exhibits.py``) | 00:09.939 | 0.0 MB | +| :ref:`sphx_glr_auto_examples_plot_ave_analysis.py` (``plot_ave_analysis.py``) | 00:00.000 | 0.0 MB | +-----------------------------------------------------------------------------------------------+-----------+--------+ -| :ref:`sphx_glr_auto_examples_plot_capecod.py` (``plot_capecod.py``) | 00:09.717 | 0.0 MB | +| :ref:`sphx_glr_auto_examples_plot_benktander.py` (``plot_benktander.py``) | 00:00.000 | 0.0 MB | +-----------------------------------------------------------------------------------------------+-----------+--------+ -| :ref:`sphx_glr_auto_examples_plot_development_periods.py` (``plot_development_periods.py``) | 00:07.008 | 0.0 MB | +| :ref:`sphx_glr_auto_examples_plot_bf_apriori_from_cl.py` (``plot_bf_apriori_from_cl.py``) | 00:00.000 | 0.0 MB | +-----------------------------------------------------------------------------------------------+-----------+--------+ -| :ref:`sphx_glr_auto_examples_plot_industry_to_company.py` (``plot_industry_to_company.py``) | 00:04.303 | 0.0 MB | +| :ref:`sphx_glr_auto_examples_plot_bootstrap_comparison.py` (``plot_bootstrap_comparison.py``) | 00:00.000 | 0.0 MB | +-----------------------------------------------------------------------------------------------+-----------+--------+ -| :ref:`sphx_glr_auto_examples_plot_triangle_slicing.py` (``plot_triangle_slicing.py``) | 00:03.882 | 0.0 MB | +| :ref:`sphx_glr_auto_examples_plot_capecod.py` (``plot_capecod.py``) | 00:00.000 | 0.0 MB | +-----------------------------------------------------------------------------------------------+-----------+--------+ -| :ref:`sphx_glr_auto_examples_plot_ave_analysis.py` (``plot_ave_analysis.py``) | 00:03.530 | 0.0 MB | +| :ref:`sphx_glr_auto_examples_plot_development_periods.py` (``plot_development_periods.py``) | 00:00.000 | 0.0 MB | +-----------------------------------------------------------------------------------------------+-----------+--------+ -| :ref:`sphx_glr_auto_examples_plot_triangle_from_pandas.py` (``plot_triangle_from_pandas.py``) | 00:02.494 | 0.0 MB | +| :ref:`sphx_glr_auto_examples_plot_exhibits.py` (``plot_exhibits.py``) | 00:00.000 | 0.0 MB | +-----------------------------------------------------------------------------------------------+-----------+--------+ -| :ref:`sphx_glr_auto_examples_plot_munich.py` (``plot_munich.py``) | 00:01.975 | 0.0 MB | +| :ref:`sphx_glr_auto_examples_plot_exposure_triangle.py` (``plot_exposure_triangle.py``) | 00:00.000 | 0.0 MB | +-----------------------------------------------------------------------------------------------+-----------+--------+ -| :ref:`sphx_glr_auto_examples_plot_mack.py` (``plot_mack.py``) | 00:01.516 | 0.0 MB | +| :ref:`sphx_glr_auto_examples_plot_ibnr_runoff.py` (``plot_ibnr_runoff.py``) | 00:00.000 | 0.0 MB | +-----------------------------------------------------------------------------------------------+-----------+--------+ -| :ref:`sphx_glr_auto_examples_plot_bf_apriori_from_cl.py` (``plot_bf_apriori_from_cl.py``) | 00:01.345 | 0.0 MB | +| :ref:`sphx_glr_auto_examples_plot_industry_to_company.py` (``plot_industry_to_company.py``) | 00:00.000 | 0.0 MB | ++-----------------------------------------------------------------------------------------------+-----------+--------+ +| :ref:`sphx_glr_auto_examples_plot_mack.py` (``plot_mack.py``) | 00:00.000 | 0.0 MB | ++-----------------------------------------------------------------------------------------------+-----------+--------+ +| :ref:`sphx_glr_auto_examples_plot_munich.py` (``plot_munich.py``) | 00:00.000 | 0.0 MB | ++-----------------------------------------------------------------------------------------------+-----------+--------+ +| :ref:`sphx_glr_auto_examples_plot_triangle_from_pandas.py` (``plot_triangle_from_pandas.py``) | 00:00.000 | 0.0 MB | ++-----------------------------------------------------------------------------------------------+-----------+--------+ +| :ref:`sphx_glr_auto_examples_plot_triangle_slicing.py` (``plot_triangle_slicing.py``) | 00:00.000 | 0.0 MB | ++-----------------------------------------------------------------------------------------------+-----------+--------+ +| :ref:`sphx_glr_auto_examples_plot_value_at_risk.py` (``plot_value_at_risk.py``) | 00:00.000 | 0.0 MB | +-----------------------------------------------------------------------------------------------+-----------+--------+ diff --git a/docs/modules/generated/chainladder.BootstrapODPSample.examples b/docs/modules/generated/chainladder.BootstrapODPSample.examples index 51ee11ee..f26de802 100644 --- a/docs/modules/generated/chainladder.BootstrapODPSample.examples +++ b/docs/modules/generated/chainladder.BootstrapODPSample.examples @@ -20,3 +20,21 @@ Examples using ``chainladder.BootstrapODPSample`` .. only:: not html * :ref:`sphx_glr_auto_examples_plot_bootstrap.py` + +.. raw:: html + +
+ +.. only:: html + + .. figure:: /auto_examples/images/thumb/sphx_glr_plot_stochastic_bornferg_thumb.png + + :ref:`sphx_glr_auto_examples_plot_stochastic_bornferg.py` + +.. raw:: html + +
+ +.. only:: not html + + * :ref:`sphx_glr_auto_examples_plot_stochastic_bornferg.py` diff --git a/docs/modules/generated/chainladder.BootstrapODPSample.fit.examples b/docs/modules/generated/chainladder.BootstrapODPSample.fit.examples index e69de29b..abd48de7 100644 --- a/docs/modules/generated/chainladder.BootstrapODPSample.fit.examples +++ b/docs/modules/generated/chainladder.BootstrapODPSample.fit.examples @@ -0,0 +1,22 @@ + + +Examples using ``chainladder.BootstrapODPSample.fit`` +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. raw:: html + +
+ +.. only:: html + + .. figure:: /auto_examples/images/thumb/sphx_glr_plot_stochastic_bornferg_thumb.png + + :ref:`sphx_glr_auto_examples_plot_stochastic_bornferg.py` + +.. raw:: html + +
+ +.. only:: not html + + * :ref:`sphx_glr_auto_examples_plot_stochastic_bornferg.py` diff --git a/docs/modules/generated/chainladder.BornhuetterFerguson.examples b/docs/modules/generated/chainladder.BornhuetterFerguson.examples index 9faa1e07..c2dd9612 100644 --- a/docs/modules/generated/chainladder.BornhuetterFerguson.examples +++ b/docs/modules/generated/chainladder.BornhuetterFerguson.examples @@ -5,13 +5,13 @@ Examples using ``chainladder.BornhuetterFerguson`` .. raw:: html -
+
.. only:: html - .. figure:: /auto_examples/images/thumb/sphx_glr_plot_bf_apriori_from_cl_thumb.png + .. figure:: /auto_examples/images/thumb/sphx_glr_plot_stochastic_bornferg_thumb.png - :ref:`sphx_glr_auto_examples_plot_bf_apriori_from_cl.py` + :ref:`sphx_glr_auto_examples_plot_stochastic_bornferg.py` .. raw:: html @@ -19,4 +19,4 @@ Examples using ``chainladder.BornhuetterFerguson`` .. only:: not html - * :ref:`sphx_glr_auto_examples_plot_bf_apriori_from_cl.py` + * :ref:`sphx_glr_auto_examples_plot_stochastic_bornferg.py` diff --git a/docs/modules/generated/chainladder.CSpacer.__init__.examples b/docs/modules/generated/chainladder.CSpacer.__init__.examples new file mode 100644 index 00000000..e69de29b diff --git a/docs/modules/generated/chainladder.CSpacer.format_validation.examples b/docs/modules/generated/chainladder.CSpacer.format_validation.examples new file mode 100644 index 00000000..e69de29b diff --git a/docs/modules/generated/chainladder.CSpacer.get_column_widths.examples b/docs/modules/generated/chainladder.CSpacer.get_column_widths.examples new file mode 100644 index 00000000..e69de29b diff --git a/docs/modules/generated/chainladder.CSpacer.rst b/docs/modules/generated/chainladder.CSpacer.rst new file mode 100644 index 00000000..ae39114e --- /dev/null +++ b/docs/modules/generated/chainladder.CSpacer.rst @@ -0,0 +1,16 @@ + +:mod:`chainladder`.CSpacer +================================= + +.. currentmodule:: chainladder + +.. autoclass:: CSpacer + + + .. automethod:: __init__ + + +.. include:: chainladder.CSpacer.examples +.. raw:: html + +
\ No newline at end of file diff --git a/docs/modules/generated/chainladder.CSpacer.to_excel.examples b/docs/modules/generated/chainladder.CSpacer.to_excel.examples new file mode 100644 index 00000000..e69de29b diff --git a/docs/modules/generated/chainladder.Chainladder.examples b/docs/modules/generated/chainladder.Chainladder.examples index f10585bc..a62ed10f 100644 --- a/docs/modules/generated/chainladder.Chainladder.examples +++ b/docs/modules/generated/chainladder.Chainladder.examples @@ -21,6 +21,60 @@ Examples using ``chainladder.Chainladder`` * :ref:`sphx_glr_auto_examples_plot_industry_to_company.py` +.. raw:: html + +
+ +.. only:: html + + .. figure:: /auto_examples/images/thumb/sphx_glr_plot_value_at_risk_thumb.png + + :ref:`sphx_glr_auto_examples_plot_value_at_risk.py` + +.. raw:: html + +
+ +.. only:: not html + + * :ref:`sphx_glr_auto_examples_plot_value_at_risk.py` + +.. raw:: html + +
+ +.. only:: html + + .. figure:: /auto_examples/images/thumb/sphx_glr_plot_ibnr_runoff_thumb.png + + :ref:`sphx_glr_auto_examples_plot_ibnr_runoff.py` + +.. raw:: html + +
+ +.. only:: not html + + * :ref:`sphx_glr_auto_examples_plot_ibnr_runoff.py` + +.. raw:: html + +
+ +.. only:: html + + .. figure:: /auto_examples/images/thumb/sphx_glr_plot_exposure_triangle_thumb.png + + :ref:`sphx_glr_auto_examples_plot_exposure_triangle.py` + +.. raw:: html + +
+ +.. only:: not html + + * :ref:`sphx_glr_auto_examples_plot_exposure_triangle.py` + .. raw:: html
@@ -57,6 +111,24 @@ Examples using ``chainladder.Chainladder`` * :ref:`sphx_glr_auto_examples_plot_bf_apriori_from_cl.py` +.. raw:: html + +
+ +.. only:: html + + .. figure:: /auto_examples/images/thumb/sphx_glr_plot_bootstrap_comparison_thumb.png + + :ref:`sphx_glr_auto_examples_plot_bootstrap_comparison.py` + +.. raw:: html + +
+ +.. only:: not html + + * :ref:`sphx_glr_auto_examples_plot_bootstrap_comparison.py` + .. raw:: html
diff --git a/docs/modules/generated/chainladder.Development.examples b/docs/modules/generated/chainladder.Development.examples index 5b933f10..04dbd091 100644 --- a/docs/modules/generated/chainladder.Development.examples +++ b/docs/modules/generated/chainladder.Development.examples @@ -3,42 +3,6 @@ Examples using ``chainladder.Development`` ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -.. raw:: html - -
- -.. only:: html - - .. figure:: /auto_examples/images/thumb/sphx_glr_plot_development_periods_thumb.png - - :ref:`sphx_glr_auto_examples_plot_development_periods.py` - -.. raw:: html - -
- -.. only:: not html - - * :ref:`sphx_glr_auto_examples_plot_development_periods.py` - -.. raw:: html - -
- -.. only:: html - - .. figure:: /auto_examples/images/thumb/sphx_glr_plot_mack_thumb.png - - :ref:`sphx_glr_auto_examples_plot_mack.py` - -.. raw:: html - -
- -.. only:: not html - - * :ref:`sphx_glr_auto_examples_plot_mack.py` - .. raw:: html
@@ -56,57 +20,3 @@ Examples using ``chainladder.Development`` .. only:: not html * :ref:`sphx_glr_auto_examples_plot_bootstrap.py` - -.. raw:: html - -
- -.. only:: html - - .. figure:: /auto_examples/images/thumb/sphx_glr_plot_benktander_thumb.png - - :ref:`sphx_glr_auto_examples_plot_benktander.py` - -.. raw:: html - -
- -.. only:: not html - - * :ref:`sphx_glr_auto_examples_plot_benktander.py` - -.. raw:: html - -
- -.. only:: html - - .. figure:: /auto_examples/images/thumb/sphx_glr_plot_munich_thumb.png - - :ref:`sphx_glr_auto_examples_plot_munich.py` - -.. raw:: html - -
- -.. only:: not html - - * :ref:`sphx_glr_auto_examples_plot_munich.py` - -.. raw:: html - -
- -.. only:: html - - .. figure:: /auto_examples/images/thumb/sphx_glr_plot_exhibits_thumb.png - - :ref:`sphx_glr_auto_examples_plot_exhibits.py` - -.. raw:: html - -
- -.. only:: not html - - * :ref:`sphx_glr_auto_examples_plot_exhibits.py` diff --git a/docs/modules/generated/chainladder.Image.__init__.examples b/docs/modules/generated/chainladder.Image.__init__.examples new file mode 100644 index 00000000..e69de29b diff --git a/docs/modules/generated/chainladder.Image.examples b/docs/modules/generated/chainladder.Image.examples new file mode 100644 index 00000000..e69de29b diff --git a/docs/modules/generated/chainladder.Image.rst b/docs/modules/generated/chainladder.Image.rst new file mode 100644 index 00000000..5127e37f --- /dev/null +++ b/docs/modules/generated/chainladder.Image.rst @@ -0,0 +1,16 @@ + +:mod:`chainladder`.Image +=============================== + +.. currentmodule:: chainladder + +.. autoclass:: Image + + + .. automethod:: __init__ + + +.. include:: chainladder.Image.examples +.. raw:: html + +
\ No newline at end of file diff --git a/docs/modules/generated/chainladder.Image.to_excel.examples b/docs/modules/generated/chainladder.Image.to_excel.examples new file mode 100644 index 00000000..e69de29b diff --git a/docs/modules/generated/chainladder.RSpacer.__init__.examples b/docs/modules/generated/chainladder.RSpacer.__init__.examples new file mode 100644 index 00000000..e69de29b diff --git a/docs/modules/generated/chainladder.RSpacer.examples b/docs/modules/generated/chainladder.RSpacer.examples new file mode 100644 index 00000000..e69de29b diff --git a/docs/modules/generated/chainladder.RSpacer.format_validation.examples b/docs/modules/generated/chainladder.RSpacer.format_validation.examples new file mode 100644 index 00000000..e69de29b diff --git a/docs/modules/generated/chainladder.RSpacer.get_column_widths.examples b/docs/modules/generated/chainladder.RSpacer.get_column_widths.examples new file mode 100644 index 00000000..e69de29b diff --git a/docs/modules/generated/chainladder.RSpacer.rst b/docs/modules/generated/chainladder.RSpacer.rst new file mode 100644 index 00000000..2086bcc9 --- /dev/null +++ b/docs/modules/generated/chainladder.RSpacer.rst @@ -0,0 +1,16 @@ + +:mod:`chainladder`.RSpacer +================================= + +.. currentmodule:: chainladder + +.. autoclass:: RSpacer + + + .. automethod:: __init__ + + +.. include:: chainladder.RSpacer.examples +.. raw:: html + +
\ No newline at end of file diff --git a/docs/modules/generated/chainladder.RSpacer.to_excel.examples b/docs/modules/generated/chainladder.RSpacer.to_excel.examples new file mode 100644 index 00000000..e69de29b diff --git a/docs/modules/generated/chainladder.Series.__init__.examples b/docs/modules/generated/chainladder.Series.__init__.examples new file mode 100644 index 00000000..e69de29b diff --git a/docs/modules/generated/chainladder.Series.column_widths.examples b/docs/modules/generated/chainladder.Series.column_widths.examples new file mode 100644 index 00000000..e69de29b diff --git a/docs/modules/generated/chainladder.Series.examples b/docs/modules/generated/chainladder.Series.examples new file mode 100644 index 00000000..e69de29b diff --git a/docs/modules/generated/chainladder.Series.rst b/docs/modules/generated/chainladder.Series.rst new file mode 100644 index 00000000..1cad9a50 --- /dev/null +++ b/docs/modules/generated/chainladder.Series.rst @@ -0,0 +1,16 @@ + +:mod:`chainladder`.Series +================================ + +.. currentmodule:: chainladder + +.. autoclass:: Series + + + .. automethod:: __init__ + + +.. include:: chainladder.Series.examples +.. raw:: html + +
\ No newline at end of file diff --git a/docs/modules/generated/chainladder.Series.to_excel.examples b/docs/modules/generated/chainladder.Series.to_excel.examples new file mode 100644 index 00000000..e69de29b diff --git a/docs/modules/generated/chainladder.Title.__init__.examples b/docs/modules/generated/chainladder.Title.__init__.examples new file mode 100644 index 00000000..e69de29b diff --git a/docs/modules/generated/chainladder.Title.column_widths.examples b/docs/modules/generated/chainladder.Title.column_widths.examples new file mode 100644 index 00000000..e69de29b diff --git a/docs/modules/generated/chainladder.Title.rst b/docs/modules/generated/chainladder.Title.rst new file mode 100644 index 00000000..1dd5d52e --- /dev/null +++ b/docs/modules/generated/chainladder.Title.rst @@ -0,0 +1,16 @@ + +:mod:`chainladder`.Title +=============================== + +.. currentmodule:: chainladder + +.. autoclass:: Title + + + .. automethod:: __init__ + + +.. include:: chainladder.Title.examples +.. raw:: html + +
\ No newline at end of file diff --git a/docs/modules/generated/chainladder.Title.to_excel.examples b/docs/modules/generated/chainladder.Title.to_excel.examples new file mode 100644 index 00000000..e69de29b diff --git a/docs/modules/generated/chainladder.Triangle.broadcast_axis.examples b/docs/modules/generated/chainladder.Triangle.broadcast_axis.examples new file mode 100644 index 00000000..949db819 --- /dev/null +++ b/docs/modules/generated/chainladder.Triangle.broadcast_axis.examples @@ -0,0 +1,22 @@ + + +Examples using ``chainladder.Triangle.broadcast_axis`` +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. raw:: html + +
+ +.. only:: html + + .. figure:: /auto_examples/images/thumb/sphx_glr_plot_stochastic_bornferg_thumb.png + + :ref:`sphx_glr_auto_examples_plot_stochastic_bornferg.py` + +.. raw:: html + +
+ +.. only:: not html + + * :ref:`sphx_glr_auto_examples_plot_stochastic_bornferg.py` diff --git a/docs/modules/generated/chainladder.Triangle.cum_to_incr.examples b/docs/modules/generated/chainladder.Triangle.cum_to_incr.examples index e69de29b..10d1fc74 100644 --- a/docs/modules/generated/chainladder.Triangle.cum_to_incr.examples +++ b/docs/modules/generated/chainladder.Triangle.cum_to_incr.examples @@ -0,0 +1,22 @@ + + +Examples using ``chainladder.Triangle.cum_to_incr`` +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. raw:: html + +
+ +.. only:: html + + .. figure:: /auto_examples/images/thumb/sphx_glr_plot_ibnr_runoff_thumb.png + + :ref:`sphx_glr_auto_examples_plot_ibnr_runoff.py` + +.. raw:: html + +
+ +.. only:: not html + + * :ref:`sphx_glr_auto_examples_plot_ibnr_runoff.py` diff --git a/docs/modules/generated/chainladder.Triangle.dev_to_val.examples b/docs/modules/generated/chainladder.Triangle.dev_to_val.examples index e69de29b..f8387dd5 100644 --- a/docs/modules/generated/chainladder.Triangle.dev_to_val.examples +++ b/docs/modules/generated/chainladder.Triangle.dev_to_val.examples @@ -0,0 +1,22 @@ + + +Examples using ``chainladder.Triangle.dev_to_val`` +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. raw:: html + +
+ +.. only:: html + + .. figure:: /auto_examples/images/thumb/sphx_glr_plot_ibnr_runoff_thumb.png + + :ref:`sphx_glr_auto_examples_plot_ibnr_runoff.py` + +.. raw:: html + +
+ +.. only:: not html + + * :ref:`sphx_glr_auto_examples_plot_ibnr_runoff.py` diff --git a/docs/modules/generated/chainladder.Triangle.examples b/docs/modules/generated/chainladder.Triangle.examples index 3d479aaa..6e4fe457 100644 --- a/docs/modules/generated/chainladder.Triangle.examples +++ b/docs/modules/generated/chainladder.Triangle.examples @@ -3,114 +3,6 @@ Examples using ``chainladder.Triangle`` ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -.. raw:: html - -
- -.. only:: html - - .. figure:: /auto_examples/images/thumb/sphx_glr_plot_industry_to_company_thumb.png - - :ref:`sphx_glr_auto_examples_plot_industry_to_company.py` - -.. raw:: html - -
- -.. only:: not html - - * :ref:`sphx_glr_auto_examples_plot_industry_to_company.py` - -.. raw:: html - -
- -.. only:: html - - .. figure:: /auto_examples/images/thumb/sphx_glr_plot_triangle_slicing_thumb.png - - :ref:`sphx_glr_auto_examples_plot_triangle_slicing.py` - -.. raw:: html - -
- -.. only:: not html - - * :ref:`sphx_glr_auto_examples_plot_triangle_slicing.py` - -.. raw:: html - -
- -.. only:: html - - .. figure:: /auto_examples/images/thumb/sphx_glr_plot_development_periods_thumb.png - - :ref:`sphx_glr_auto_examples_plot_development_periods.py` - -.. raw:: html - -
- -.. only:: not html - - * :ref:`sphx_glr_auto_examples_plot_development_periods.py` - -.. raw:: html - -
- -.. only:: html - - .. figure:: /auto_examples/images/thumb/sphx_glr_plot_mack_thumb.png - - :ref:`sphx_glr_auto_examples_plot_mack.py` - -.. raw:: html - -
- -.. only:: not html - - * :ref:`sphx_glr_auto_examples_plot_mack.py` - -.. raw:: html - -
- -.. only:: html - - .. figure:: /auto_examples/images/thumb/sphx_glr_plot_bf_apriori_from_cl_thumb.png - - :ref:`sphx_glr_auto_examples_plot_bf_apriori_from_cl.py` - -.. raw:: html - -
- -.. only:: not html - - * :ref:`sphx_glr_auto_examples_plot_bf_apriori_from_cl.py` - -.. raw:: html - -
- -.. only:: html - - .. figure:: /auto_examples/images/thumb/sphx_glr_plot_ave_analysis_thumb.png - - :ref:`sphx_glr_auto_examples_plot_ave_analysis.py` - -.. raw:: html - -
- -.. only:: not html - - * :ref:`sphx_glr_auto_examples_plot_ave_analysis.py` - .. raw:: html
@@ -131,85 +23,13 @@ Examples using ``chainladder.Triangle`` .. raw:: html -
- -.. only:: html - - .. figure:: /auto_examples/images/thumb/sphx_glr_plot_benktander_thumb.png - - :ref:`sphx_glr_auto_examples_plot_benktander.py` - -.. raw:: html - -
- -.. only:: not html - - * :ref:`sphx_glr_auto_examples_plot_benktander.py` - -.. raw:: html - -
- -.. only:: html - - .. figure:: /auto_examples/images/thumb/sphx_glr_plot_triangle_from_pandas_thumb.png - - :ref:`sphx_glr_auto_examples_plot_triangle_from_pandas.py` - -.. raw:: html - -
- -.. only:: not html - - * :ref:`sphx_glr_auto_examples_plot_triangle_from_pandas.py` - -.. raw:: html - -
- -.. only:: html - - .. figure:: /auto_examples/images/thumb/sphx_glr_plot_munich_thumb.png - - :ref:`sphx_glr_auto_examples_plot_munich.py` - -.. raw:: html - -
- -.. only:: not html - - * :ref:`sphx_glr_auto_examples_plot_munich.py` - -.. raw:: html - -
- -.. only:: html - - .. figure:: /auto_examples/images/thumb/sphx_glr_plot_capecod_thumb.png - - :ref:`sphx_glr_auto_examples_plot_capecod.py` - -.. raw:: html - -
- -.. only:: not html - - * :ref:`sphx_glr_auto_examples_plot_capecod.py` - -.. raw:: html - -
+
.. only:: html - .. figure:: /auto_examples/images/thumb/sphx_glr_plot_exhibits_thumb.png + .. figure:: /auto_examples/images/thumb/sphx_glr_plot_stochastic_bornferg_thumb.png - :ref:`sphx_glr_auto_examples_plot_exhibits.py` + :ref:`sphx_glr_auto_examples_plot_stochastic_bornferg.py` .. raw:: html @@ -217,4 +37,4 @@ Examples using ``chainladder.Triangle`` .. only:: not html - * :ref:`sphx_glr_auto_examples_plot_exhibits.py` + * :ref:`sphx_glr_auto_examples_plot_stochastic_bornferg.py` diff --git a/docs/modules/generated/chainladder.Triangle.latest_diagonal.examples b/docs/modules/generated/chainladder.Triangle.latest_diagonal.examples index 844fb25e..1c4aacda 100644 --- a/docs/modules/generated/chainladder.Triangle.latest_diagonal.examples +++ b/docs/modules/generated/chainladder.Triangle.latest_diagonal.examples @@ -5,13 +5,13 @@ Examples using ``chainladder.Triangle.latest_diagonal`` .. raw:: html -
+
.. only:: html - .. figure:: /auto_examples/images/thumb/sphx_glr_plot_ave_analysis_thumb.png + .. figure:: /auto_examples/images/thumb/sphx_glr_plot_stochastic_bornferg_thumb.png - :ref:`sphx_glr_auto_examples_plot_ave_analysis.py` + :ref:`sphx_glr_auto_examples_plot_stochastic_bornferg.py` .. raw:: html @@ -19,4 +19,4 @@ Examples using ``chainladder.Triangle.latest_diagonal`` .. only:: not html - * :ref:`sphx_glr_auto_examples_plot_ave_analysis.py` + * :ref:`sphx_glr_auto_examples_plot_stochastic_bornferg.py` diff --git a/docs/modules/generated/chainladder.Triangle.origin.examples b/docs/modules/generated/chainladder.Triangle.origin.examples index b6d80ff5..801ee3cf 100644 --- a/docs/modules/generated/chainladder.Triangle.origin.examples +++ b/docs/modules/generated/chainladder.Triangle.origin.examples @@ -5,13 +5,13 @@ Examples using ``chainladder.Triangle.origin`` .. raw:: html -
+
.. only:: html - .. figure:: /auto_examples/images/thumb/sphx_glr_plot_ave_analysis_thumb.png + .. figure:: /auto_examples/images/thumb/sphx_glr_plot_bootstrap_thumb.png - :ref:`sphx_glr_auto_examples_plot_ave_analysis.py` + :ref:`sphx_glr_auto_examples_plot_bootstrap.py` .. raw:: html @@ -19,17 +19,17 @@ Examples using ``chainladder.Triangle.origin`` .. only:: not html - * :ref:`sphx_glr_auto_examples_plot_ave_analysis.py` + * :ref:`sphx_glr_auto_examples_plot_bootstrap.py` .. raw:: html -
+
.. only:: html - .. figure:: /auto_examples/images/thumb/sphx_glr_plot_bootstrap_thumb.png + .. figure:: /auto_examples/images/thumb/sphx_glr_plot_stochastic_bornferg_thumb.png - :ref:`sphx_glr_auto_examples_plot_bootstrap.py` + :ref:`sphx_glr_auto_examples_plot_stochastic_bornferg.py` .. raw:: html @@ -37,4 +37,4 @@ Examples using ``chainladder.Triangle.origin`` .. only:: not html - * :ref:`sphx_glr_auto_examples_plot_bootstrap.py` + * :ref:`sphx_glr_auto_examples_plot_stochastic_bornferg.py` diff --git a/docs/modules/generated/chainladder.Triangle.to_frame.examples b/docs/modules/generated/chainladder.Triangle.to_frame.examples index e2995a8b..d1ba1c5e 100644 --- a/docs/modules/generated/chainladder.Triangle.to_frame.examples +++ b/docs/modules/generated/chainladder.Triangle.to_frame.examples @@ -21,6 +21,24 @@ Examples using ``chainladder.Triangle.to_frame`` * :ref:`sphx_glr_auto_examples_plot_bf_apriori_from_cl.py` +.. raw:: html + +
+ +.. only:: html + + .. figure:: /auto_examples/images/thumb/sphx_glr_plot_bootstrap_comparison_thumb.png + + :ref:`sphx_glr_auto_examples_plot_bootstrap_comparison.py` + +.. raw:: html + +
+ +.. only:: not html + + * :ref:`sphx_glr_auto_examples_plot_bootstrap_comparison.py` + .. raw:: html
diff --git a/docs/modules/generated/chainladder.core.triangle.Triangle.origin.max.examples b/docs/modules/generated/chainladder.core.triangle.Triangle.origin.max.examples index f3e78355..ad39aaa2 100644 --- a/docs/modules/generated/chainladder.core.triangle.Triangle.origin.max.examples +++ b/docs/modules/generated/chainladder.core.triangle.Triangle.origin.max.examples @@ -20,3 +20,21 @@ Examples using ``chainladder.core.triangle.Triangle.origin.max`` .. only:: not html * :ref:`sphx_glr_auto_examples_plot_bootstrap.py` + +.. raw:: html + +
+ +.. only:: html + + .. figure:: /auto_examples/images/thumb/sphx_glr_plot_stochastic_bornferg_thumb.png + + :ref:`sphx_glr_auto_examples_plot_stochastic_bornferg.py` + +.. raw:: html + +
+ +.. only:: not html + + * :ref:`sphx_glr_auto_examples_plot_stochastic_bornferg.py` diff --git a/docs/modules/generated/chainladder.core.triangle.Triangle.values.examples b/docs/modules/generated/chainladder.core.triangle.Triangle.values.examples new file mode 100644 index 00000000..11bb0a83 --- /dev/null +++ b/docs/modules/generated/chainladder.core.triangle.Triangle.values.examples @@ -0,0 +1,22 @@ + + +Examples using ``chainladder.core.triangle.Triangle.values`` +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. raw:: html + +
+ +.. only:: html + + .. figure:: /auto_examples/images/thumb/sphx_glr_plot_stochastic_bornferg_thumb.png + + :ref:`sphx_glr_auto_examples_plot_stochastic_bornferg.py` + +.. raw:: html + +
+ +.. only:: not html + + * :ref:`sphx_glr_auto_examples_plot_stochastic_bornferg.py` diff --git a/docs/modules/generated/chainladder.development.bootstrap.BootstrapODPSample.resampled_triangles_.examples b/docs/modules/generated/chainladder.development.bootstrap.BootstrapODPSample.resampled_triangles_.examples new file mode 100644 index 00000000..78302168 --- /dev/null +++ b/docs/modules/generated/chainladder.development.bootstrap.BootstrapODPSample.resampled_triangles_.examples @@ -0,0 +1,22 @@ + + +Examples using ``chainladder.development.bootstrap.BootstrapODPSample.resampled_triangles_`` +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. raw:: html + +
+ +.. only:: html + + .. figure:: /auto_examples/images/thumb/sphx_glr_plot_stochastic_bornferg_thumb.png + + :ref:`sphx_glr_auto_examples_plot_stochastic_bornferg.py` + +.. raw:: html + +
+ +.. only:: not html + + * :ref:`sphx_glr_auto_examples_plot_stochastic_bornferg.py` diff --git a/docs/modules/generated/chainladder.development.bootstrap.BootstrapODPSample.resampled_triangles_.index.examples b/docs/modules/generated/chainladder.development.bootstrap.BootstrapODPSample.resampled_triangles_.index.examples new file mode 100644 index 00000000..7964f53d --- /dev/null +++ b/docs/modules/generated/chainladder.development.bootstrap.BootstrapODPSample.resampled_triangles_.index.examples @@ -0,0 +1,22 @@ + + +Examples using ``chainladder.development.bootstrap.BootstrapODPSample.resampled_triangles_.index`` +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. raw:: html + +
+ +.. only:: html + + .. figure:: /auto_examples/images/thumb/sphx_glr_plot_stochastic_bornferg_thumb.png + + :ref:`sphx_glr_auto_examples_plot_stochastic_bornferg.py` + +.. raw:: html + +
+ +.. only:: not html + + * :ref:`sphx_glr_auto_examples_plot_stochastic_bornferg.py` diff --git a/docs/modules/generated/chainladder.load_dataset.examples b/docs/modules/generated/chainladder.load_dataset.examples index f521e416..4762125a 100644 --- a/docs/modules/generated/chainladder.load_dataset.examples +++ b/docs/modules/generated/chainladder.load_dataset.examples @@ -3,114 +3,6 @@ Examples using ``chainladder.load_dataset`` ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -.. raw:: html - -
- -.. only:: html - - .. figure:: /auto_examples/images/thumb/sphx_glr_plot_industry_to_company_thumb.png - - :ref:`sphx_glr_auto_examples_plot_industry_to_company.py` - -.. raw:: html - -
- -.. only:: not html - - * :ref:`sphx_glr_auto_examples_plot_industry_to_company.py` - -.. raw:: html - -
- -.. only:: html - - .. figure:: /auto_examples/images/thumb/sphx_glr_plot_triangle_slicing_thumb.png - - :ref:`sphx_glr_auto_examples_plot_triangle_slicing.py` - -.. raw:: html - -
- -.. only:: not html - - * :ref:`sphx_glr_auto_examples_plot_triangle_slicing.py` - -.. raw:: html - -
- -.. only:: html - - .. figure:: /auto_examples/images/thumb/sphx_glr_plot_development_periods_thumb.png - - :ref:`sphx_glr_auto_examples_plot_development_periods.py` - -.. raw:: html - -
- -.. only:: not html - - * :ref:`sphx_glr_auto_examples_plot_development_periods.py` - -.. raw:: html - -
- -.. only:: html - - .. figure:: /auto_examples/images/thumb/sphx_glr_plot_mack_thumb.png - - :ref:`sphx_glr_auto_examples_plot_mack.py` - -.. raw:: html - -
- -.. only:: not html - - * :ref:`sphx_glr_auto_examples_plot_mack.py` - -.. raw:: html - -
- -.. only:: html - - .. figure:: /auto_examples/images/thumb/sphx_glr_plot_bf_apriori_from_cl_thumb.png - - :ref:`sphx_glr_auto_examples_plot_bf_apriori_from_cl.py` - -.. raw:: html - -
- -.. only:: not html - - * :ref:`sphx_glr_auto_examples_plot_bf_apriori_from_cl.py` - -.. raw:: html - -
- -.. only:: html - - .. figure:: /auto_examples/images/thumb/sphx_glr_plot_ave_analysis_thumb.png - - :ref:`sphx_glr_auto_examples_plot_ave_analysis.py` - -.. raw:: html - -
- -.. only:: not html - - * :ref:`sphx_glr_auto_examples_plot_ave_analysis.py` - .. raw:: html
@@ -131,67 +23,13 @@ Examples using ``chainladder.load_dataset`` .. raw:: html -
- -.. only:: html - - .. figure:: /auto_examples/images/thumb/sphx_glr_plot_benktander_thumb.png - - :ref:`sphx_glr_auto_examples_plot_benktander.py` - -.. raw:: html - -
- -.. only:: not html - - * :ref:`sphx_glr_auto_examples_plot_benktander.py` - -.. raw:: html - -
- -.. only:: html - - .. figure:: /auto_examples/images/thumb/sphx_glr_plot_munich_thumb.png - - :ref:`sphx_glr_auto_examples_plot_munich.py` - -.. raw:: html - -
- -.. only:: not html - - * :ref:`sphx_glr_auto_examples_plot_munich.py` - -.. raw:: html - -
- -.. only:: html - - .. figure:: /auto_examples/images/thumb/sphx_glr_plot_capecod_thumb.png - - :ref:`sphx_glr_auto_examples_plot_capecod.py` - -.. raw:: html - -
- -.. only:: not html - - * :ref:`sphx_glr_auto_examples_plot_capecod.py` - -.. raw:: html - -
+
.. only:: html - .. figure:: /auto_examples/images/thumb/sphx_glr_plot_exhibits_thumb.png + .. figure:: /auto_examples/images/thumb/sphx_glr_plot_stochastic_bornferg_thumb.png - :ref:`sphx_glr_auto_examples_plot_exhibits.py` + :ref:`sphx_glr_auto_examples_plot_stochastic_bornferg.py` .. raw:: html @@ -199,4 +37,4 @@ Examples using ``chainladder.load_dataset`` .. only:: not html - * :ref:`sphx_glr_auto_examples_plot_exhibits.py` + * :ref:`sphx_glr_auto_examples_plot_stochastic_bornferg.py` diff --git a/docs/modules/generated/chainladder.methods.bornferg.BornhuetterFerguson.X_.examples b/docs/modules/generated/chainladder.methods.bornferg.BornhuetterFerguson.X_.examples new file mode 100644 index 00000000..6a98f011 --- /dev/null +++ b/docs/modules/generated/chainladder.methods.bornferg.BornhuetterFerguson.X_.examples @@ -0,0 +1,22 @@ + + +Examples using ``chainladder.methods.bornferg.BornhuetterFerguson.X_`` +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. raw:: html + +
+ +.. only:: html + + .. figure:: /auto_examples/images/thumb/sphx_glr_plot_stochastic_bornferg_thumb.png + + :ref:`sphx_glr_auto_examples_plot_stochastic_bornferg.py` + +.. raw:: html + +
+ +.. only:: not html + + * :ref:`sphx_glr_auto_examples_plot_stochastic_bornferg.py` diff --git a/docs/modules/generated/chainladder.methods.bornferg.BornhuetterFerguson.full_triangle_.examples b/docs/modules/generated/chainladder.methods.bornferg.BornhuetterFerguson.full_triangle_.examples new file mode 100644 index 00000000..6f4d24b1 --- /dev/null +++ b/docs/modules/generated/chainladder.methods.bornferg.BornhuetterFerguson.full_triangle_.examples @@ -0,0 +1,22 @@ + + +Examples using ``chainladder.methods.bornferg.BornhuetterFerguson.full_triangle_`` +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. raw:: html + +
+ +.. only:: html + + .. figure:: /auto_examples/images/thumb/sphx_glr_plot_stochastic_bornferg_thumb.png + + :ref:`sphx_glr_auto_examples_plot_stochastic_bornferg.py` + +.. raw:: html + +
+ +.. only:: not html + + * :ref:`sphx_glr_auto_examples_plot_stochastic_bornferg.py` diff --git a/docs/modules/generated/chainladder.methods.chainladder.Chainladder.full_triangle_.cum_to_incr.examples b/docs/modules/generated/chainladder.methods.chainladder.Chainladder.full_triangle_.cum_to_incr.examples new file mode 100644 index 00000000..b5c4140f --- /dev/null +++ b/docs/modules/generated/chainladder.methods.chainladder.Chainladder.full_triangle_.cum_to_incr.examples @@ -0,0 +1,22 @@ + + +Examples using ``chainladder.methods.chainladder.Chainladder.full_triangle_.cum_to_incr`` +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. raw:: html + +
+ +.. only:: html + + .. figure:: /auto_examples/images/thumb/sphx_glr_plot_ibnr_runoff_thumb.png + + :ref:`sphx_glr_auto_examples_plot_ibnr_runoff.py` + +.. raw:: html + +
+ +.. only:: not html + + * :ref:`sphx_glr_auto_examples_plot_ibnr_runoff.py` diff --git a/examples/plot_bootstrap_comparison.py b/examples/plot_bootstrap_comparison.py new file mode 100644 index 00000000..3415d21f --- /dev/null +++ b/examples/plot_bootstrap_comparison.py @@ -0,0 +1,34 @@ +""" +======================== +ODP Bootstrap Comparison +======================== + +This example demonstrates how you can drop the outlier link ratios from the +BootstrapODPSample to reduce reserve variability estimates. + +""" +import chainladder as cl + +import seaborn as sns +sns.set_style('whitegrid') + +# Load triangle +triangle = cl.load_dataset('raa') + +# Use bootstrap sampler to get resampled triangles +s1 = cl.BootstrapODPSample( + n_sims=5000, random_state=42).fit(triangle).resampled_triangles_ + +## Alternatively use fit_transform() to access resampled triangles dropping +# outlier link-ratios from resampler +s2 = cl.BootstrapODPSample( + drop_high=True, drop_low=True, + n_sims=5000, random_state=42).fit_transform(triangle) + +# Summarize results of first model +results = cl.Chainladder().fit(s1).ibnr_.sum('origin').rename('columns', ['Original']) +# Add another column to triangle with second set of results. +results['Dropped'] = cl.Chainladder().fit(s2).ibnr_.sum('origin') + +# Plot both IBNR distributions +results.to_frame().plot(kind='hist', bins=50, alpha=0.5) diff --git a/examples/plot_exposure_triangle.py b/examples/plot_exposure_triangle.py new file mode 100644 index 00000000..4a2d5701 --- /dev/null +++ b/examples/plot_exposure_triangle.py @@ -0,0 +1,34 @@ +""" +================= +Exposure Triangle +================= + +Although triangles have both origin and development attributes, it is often +convenient to create premium or exposure vectors that can work with loss +triangles. The `Triangle` class treats the development parameter as +optional. This example instantiates a 'premium' triangle as a single vector. +""" + +import chainladder as cl +import pandas as pd +import seaborn as sns +sns.set_style('whitegrid') + +import chainladder as cl + +# Raw premium data in pandas +premium_df = pd.DataFrame( + {'AccYear':[item for item in range(1977, 1988)], + 'premium': [3000000]*11}) + +# Create a premium 'triangle' with no development +premium = cl.Triangle(premium_df, origin='AccYear', columns='premium') + +# Create some loss triangle +loss = cl.load_dataset('abc') +ultimate = cl.Chainladder().fit(loss).ultimate_ + +# Plot +(ultimate / premium).plot( + kind='area', title='Loss Ratio by Accident Year', + alpha=0.7, color='darkgreen', legend=False); diff --git a/examples/plot_ibnr_runoff.py b/examples/plot_ibnr_runoff.py new file mode 100644 index 00000000..70fedf59 --- /dev/null +++ b/examples/plot_ibnr_runoff.py @@ -0,0 +1,31 @@ +""" +============ +IBNR Runoff +============ + +All IBNR models spin off several results triangles including `inbr_`, +`ultimate_`, `full_expectation`, and `full_triangle_`. These can be +manipulated into a variety of formats. This example demonstrates how to +create a calendar year runoff of IBNR. +""" + +import chainladder as cl +import seaborn as sns +sns.set_style('whitegrid') + +# Create a triangle +triangle = cl.load_dataset('GenIns') + +# Fit a model +model = cl.Chainladder().fit(triangle) + +# Develop IBNR runoff triangle +runoff = (model.full_triangle_.cum_to_incr() - triangle.cum_to_incr()) + +# Convert to calendar period and aggregate across all accident years +cal_yr_runoff = runoff.dev_to_val().dropna().sum(axis='origin') + +# Plot results +cal_yr_runoff.T.plot(kind='bar', legend=False, color='red', + title='GenIns: IBNR Run-off', alpha=0.7) \ + .set(xlabel='Calendar Year', ylabel='IBNR'); diff --git a/examples/plot_stochastic_bornferg.py b/examples/plot_stochastic_bornferg.py new file mode 100644 index 00000000..7136c752 --- /dev/null +++ b/examples/plot_stochastic_bornferg.py @@ -0,0 +1,53 @@ +""" +================================ +Stochastic Bornhuetter Ferguson +================================ + +There are several aspects of the chainladder module that are demonstrated with +this example. + +1. We see how to use the `BootstrapODPSample` and `BornhuetterFerguson` to come + up with a stochastic view of the Bornhuetter-Ferguson method. +2. We see how we can use the `Triangle.values` property `numpy` to modify the + the data underlying the Triangle +3. We use the `broadcast_axis` method of the triangle class (new in 0.4.7) + +""" +import chainladder as cl +import numpy as np + +# Simulation parameters +random_state = 42 +n_sims = 1000 + +# Get data +loss = cl.load_dataset('genins') +premium = loss.latest_diagonal*0+8e6 + +# Simulate loss triangles +sim = cl.BootstrapODPSample(random_state=random_state, n_sims=n_sims) +sim.fit(loss, sample_weight=premium) + +# Repeat the premium triangle to align with simulated losses +sim_p = premium.broadcast_axis('index', sim.resampled_triangles_.index) + +# Simulate aprioris using numpy +apriori_mu = 0.65 +apriori_sigma = .10 +aprioris = np.random.normal(apriori_mu, apriori_sigma, n_sims) +sim_p.values = (sim_p.values * aprioris.reshape(n_sims,-1)[..., np.newaxis, np.newaxis]) + +# Fit Bornhuetter-Ferguson to stochastically generated data +model = cl.BornhuetterFerguson().fit(sim.resampled_triangles_, sample_weight=sim_p) + +# Grab completed triangle replacing simulated known data with actual known data +full_triangle = model.full_triangle_ - model.X_ + \ + loss.broadcast_axis('index', sim.resampled_triangles_.index) + +# Limiting to the current year for plotting +current_year = full_triangle[full_triangle.origin==full_triangle.origin.max()].to_frame().T + +# Plot the data +current_year.reset_index(drop=True).plot( + color='orange', legend=False, alpha=0.1, + title='Current Accident Year BornFerg Distribution', grid=True); diff --git a/examples/plot_triangle_from_pandas.py b/examples/plot_triangle_from_pandas.py index 14714a12..bde2efc0 100644 --- a/examples/plot_triangle_from_pandas.py +++ b/examples/plot_triangle_from_pandas.py @@ -24,10 +24,9 @@ data = data[data['DevelopmentYear']<=1997] # Create a triangle -triangle = cl.Triangle(data, origin='AccidentYear', - development='DevelopmentYear', - index=['GRNAME'], - columns=['IncurLoss_D','CumPaidLoss_D','EarnedPremDIR_D']) +triangle = cl.Triangle( + data, origin='AccidentYear', development='DevelopmentYear', + index=['GRNAME'], columns=['IncurLoss_D','CumPaidLoss_D','EarnedPremDIR_D']) # Output print('Raw data:') @@ -39,11 +38,9 @@ print('Aggregate Paid Triangle:') print(triangle['CumPaidLoss_D'].sum()) +# Plot data +ax = triangle['CumPaidLoss_D'].sum().T.plot( + marker='.', title='CAS Loss Reserve Database: Workers Compensation'); +ax.set(xlabel='Development Period', ylabel='Cumulative Paid Loss') -plot_data = triangle['CumPaidLoss_D'].sum().to_frame().unstack().reset_index() -plot_data.columns = ['Development Period', 'Accident Year', 'Cumulative Paid Loss'] - -sns.set_style('whitegrid') -plt.title('CAS Loss Reserve Database: Workers'' Compensation') -g = sns.pointplot(x='Development Period', y='Cumulative Paid Loss', - hue='Accident Year', data=plot_data, markers='.') +plt.show() diff --git a/examples/plot_value_at_risk.py b/examples/plot_value_at_risk.py new file mode 100644 index 00000000..12ca3ca1 --- /dev/null +++ b/examples/plot_value_at_risk.py @@ -0,0 +1,30 @@ +""" +====================== +Value at Risk example +====================== + +This example uses the `BootstrapODPSample` to simulate new triangles that +are then used to simulate an IBNR distribution from which we can do +Value at Risk percentile lookups. +""" + +import chainladder as cl +import seaborn as sns +sns.set_style('whitegrid') + +# Load triangle +triangle = cl.load_dataset('genins') + +# Create 1000 bootstrap samples of the triangle +resampled_triangles = cl.BootstrapODPSample().fit_transform(triangle) + +# Create 1000 IBNR estimates +sim_ibnr = cl.Chainladder().fit(resampled_triangles).ibnr_.sum('origin') + +# X - mu +sim_ibnr = (sim_ibnr - sim_ibnr.mean()).to_frame().sort_values() + +# Plot data +sim_ibnr.index = [item/1000 for item in range(1000)] +sim_ibnr.loc[0.90:].plot( + title='Bootstrap VaR (90% and above)', color='red').set(xlabel='VaR'); diff --git a/setup.py b/setup.py index 3f0bccc6..a4ca7124 100644 --- a/setup.py +++ b/setup.py @@ -9,7 +9,7 @@ descr = "Chainladder Package - P&C Loss Reserving package " name = 'chainladder' url = 'https://github.com/casact/chainladder-python' -version='0.4.5' # Put this in __init__.py +version='0.4.7' # Put this in __init__.py data_path = '' setup(