Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
John Bogaardt committed Jan 22, 2020
2 parents b845713 + 2f177cc commit c206ef4
Show file tree
Hide file tree
Showing 131 changed files with 1,831 additions and 565 deletions.
2 changes: 1 addition & 1 deletion chainladder/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
6 changes: 6 additions & 0 deletions chainladder/core/tests/test_triangle.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
28 changes: 28 additions & 0 deletions chainladder/core/triangle.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions chainladder/development/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Binary file modified docs/auto_examples/auto_examples_jupyter.zip
Binary file not shown.
Binary file modified docs/auto_examples/auto_examples_python.zip
Binary file not shown.
Binary file modified docs/auto_examples/images/sphx_glr_plot_bootstrap_001.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/auto_examples/images/thumb/sphx_glr_plot_bootstrap_thumb.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
116 changes: 108 additions & 8 deletions docs/auto_examples/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,66 @@ Gallery of Chainladder Functionality

/auto_examples/plot_triangle_slicing

.. raw:: html

<div class="sphx-glr-thumbcontainer" tooltip="This example uses the BootstrapODPSample to simulate new triangles that are then used to simula...">

.. 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

</div>


.. toctree::
:hidden:

/auto_examples/plot_value_at_risk

.. raw:: html

<div class="sphx-glr-thumbcontainer" tooltip="All IBNR models spin off several results triangles including inbr_, ultimate_, full_expectation...">

.. 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

</div>


.. toctree::
:hidden:

/auto_examples/plot_ibnr_runoff

.. raw:: html

<div class="sphx-glr-thumbcontainer" tooltip="Although triangles have both origin and development attributes, it is often convenient to creat...">

.. 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

</div>


.. toctree::
:hidden:

/auto_examples/plot_exposure_triangle

.. raw:: html

<div class="sphx-glr-thumbcontainer" tooltip="This example demonstrates testing multiple number of periods in the development transformer to ...">
Expand Down Expand Up @@ -111,6 +171,46 @@ Gallery of Chainladder Functionality

/auto_examples/plot_bf_apriori_from_cl

.. raw:: html

<div class="sphx-glr-thumbcontainer" tooltip="This example demonstrates the typical way you&#x27;d ingest data into a Triangle. Data in tabular fo...">

.. 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

</div>


.. toctree::
:hidden:

/auto_examples/plot_triangle_from_pandas

.. raw:: html

<div class="sphx-glr-thumbcontainer" tooltip="This example demonstrates how you can drop the outlier link ratios from the BootstrapODPSample ...">

.. 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

</div>


.. toctree::
:hidden:

/auto_examples/plot_bootstrap_comparison

.. raw:: html

<div class="sphx-glr-thumbcontainer" tooltip="This example demonstrates how you can slice triangle objects to perform a typical &#x27;Actual vs Ex...">
Expand Down Expand Up @@ -173,13 +273,13 @@ Gallery of Chainladder Functionality

.. raw:: html

<div class="sphx-glr-thumbcontainer" tooltip="This example demonstrates the typical way you&#x27;d ingest data into a Triangle. Data in tabular fo...">
<div class="sphx-glr-thumbcontainer" tooltip="This example demonstrates how to adjust LDFs by the relationship between Paid and Incurred usin...">

.. only:: html

.. figure:: /auto_examples/images/thumb/sphx_glr_plot_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

Expand All @@ -189,17 +289,17 @@ Gallery of Chainladder Functionality
.. toctree::
:hidden:

/auto_examples/plot_triangle_from_pandas
/auto_examples/plot_munich

.. raw:: html

<div class="sphx-glr-thumbcontainer" tooltip="This example demonstrates how to adjust LDFs by the relationship between Paid and Incurred usin...">
<div class="sphx-glr-thumbcontainer" tooltip="There are several aspects of the chainladder module that are demonstrated with this example.">

.. 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

Expand All @@ -209,7 +309,7 @@ Gallery of Chainladder Functionality
.. toctree::
:hidden:

/auto_examples/plot_munich
/auto_examples/plot_stochastic_bornferg

.. raw:: html

Expand Down
2 changes: 1 addition & 1 deletion docs/auto_examples/plot_ave_analysis.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Binary file modified docs/auto_examples/plot_ave_analysis_codeobj.pickle
Binary file not shown.
2 changes: 1 addition & 1 deletion docs/auto_examples/plot_benktander.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Binary file modified docs/auto_examples/plot_benktander_codeobj.pickle
Binary file not shown.
4 changes: 2 additions & 2 deletions docs/auto_examples/plot_bf_apriori_from_cl.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ apriori selection for the Bornhuetter-Ferguson Method.
.. code-block:: none
<matplotlib.axes._subplots.AxesSubplot object at 0x00000220F1A6C4E0>
<matplotlib.axes._subplots.AxesSubplot object at 0x000001F8552DFFD0>
Expand Down Expand Up @@ -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:
Expand Down
Binary file modified docs/auto_examples/plot_bf_apriori_from_cl_codeobj.pickle
Binary file not shown.
4 changes: 3 additions & 1 deletion docs/auto_examples/plot_bootstrap.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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:
Expand Down
Binary file modified docs/auto_examples/plot_bootstrap_codeobj.pickle
Binary file not shown.
54 changes: 54 additions & 0 deletions docs/auto_examples/plot_bootstrap_comparison.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"%matplotlib inline"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n# 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
}
34 changes: 34 additions & 0 deletions docs/auto_examples/plot_bootstrap_comparison.py
Original file line number Diff line number Diff line change
@@ -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)
1 change: 1 addition & 0 deletions docs/auto_examples/plot_bootstrap_comparison.py.md5
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
af4123840aa71f01d2fd75aee3df3e94
Loading

0 comments on commit c206ef4

Please sign in to comment.