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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions chainladder/core/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,17 @@ def pipe(self, func, *args, **kwargs):
>>> import chainladder as cl
>>> raa = cl.load_sample('raa')
>>> raa.pipe(lambda tri: tri.loc[..., 48:])
48 60 72 84 96 108 120
1981 11805.0 13539.0 16181.0 18009.0 18608.0 18662.0 18834.0
1982 10666.0 13782.0 15599.0 15496.0 16169.0 16704.0 NaN
1983 16141.0 18735.0 22214.0 22863.0 23466.0 NaN NaN
1984 21266.0 23425.0 26083.0 27067.0 NaN NaN NaN
1985 22169.0 25955.0 26180.0 NaN NaN NaN NaN
1986 12935.0 15852.0 NaN NaN NaN NaN NaN
1987 12314.0 NaN NaN NaN NaN NaN NaN
1988 NaN NaN NaN NaN NaN NaN NaN
1989 NaN NaN NaN NaN NaN NaN NaN
1990 NaN NaN NaN NaN NaN NaN NaN
"""
return func(self, *args, **kwargs)

Expand Down
32 changes: 16 additions & 16 deletions chainladder/development/clark.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,29 +134,29 @@ class ClarkLDF(DevelopmentBase):
clrd = cl.load_sample("clrd")[["CumPaidLoss"]]
print(len(clrd.index))
m = cl.ClarkLDF(groupby="LOB").fit(clrd)
print(m.omega_.round(3))
print(m.theta_.round(3))
print(m.omega_.round(2))
print(m.theta_.round(2))

.. testoutput::
:options: +NORMALIZE_WHITESPACE

775
CumPaidLoss
LOB
comauto 1.082
medmal 1.889
othliab 1.468
ppauto 1.149
prodliab 1.441
wkcomp 1.107
LOB
comauto 1.08
medmal 1.89
othliab 1.47
ppauto 1.15
prodliab 1.44
wkcomp 1.11
CumPaidLoss
LOB
comauto 20.481
medmal 35.128
othliab 37.745
ppauto 10.023
prodliab 64.352
wkcomp 20.111
LOB
comauto 20.48
medmal 35.13
othliab 37.75
ppauto 10.02
prodliab 64.35
wkcomp 20.11

"""

Expand Down
9 changes: 3 additions & 6 deletions chainladder/methods/benktander.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ class Benktander(MethodBase):
.. testcode::

xyz = cl.load_sample("xyz")

ibnr = cl.Benktander().fit(X=xyz["Paid"], sample_weight=xyz["Premium"].latest_diagonal).ibnr_
print(ibnr)

Expand All @@ -76,7 +75,6 @@ class Benktander(MethodBase):
.. testcode::

xyz = cl.load_sample("xyz")

bk_ibnr = (
cl.Benktander(n_iters=1)
.fit(X=xyz["Paid"], sample_weight=xyz["Premium"].latest_diagonal)
Expand Down Expand Up @@ -109,7 +107,6 @@ class Benktander(MethodBase):
.. testcode::

xyz = cl.load_sample("xyz")

bk_ibnr = cl.Benktander(n_iters=1000).fit(X=xyz["Paid"], sample_weight=xyz["Premium"].latest_diagonal).ibnr_
cl_ibnr = cl.Chainladder().fit(xyz["Paid"]).ibnr_
print(bk_ibnr - cl_ibnr)
Expand Down Expand Up @@ -165,7 +162,6 @@ def fit(self, X, y=None, sample_weight=None):
.. testcode::

xyz = cl.load_sample("xyz")

ultimate = (
cl.Benktander(apriori=1, n_iters=2)
.fit(X=xyz["Paid"], sample_weight=xyz["Premium"].latest_diagonal)
Expand Down Expand Up @@ -218,6 +214,7 @@ def predict(self, X, sample_weight=None):
current Triangle and a refreshed apriori.

.. testsetup::

import chainladder as cl

.. testcode::
Expand All @@ -229,8 +226,8 @@ def predict(self, X, sample_weight=None):
model = cl.Benktander(apriori=1.0, n_iters=2).fit(
tr_prior, sample_weight=apriori_prior
)

print(model.predict(tr, sample_weight=apriori).ultimate_)
ultimate = model.predict(tr, sample_weight=apriori).ultimate_
print(ultimate)

.. testoutput::

Expand Down
13 changes: 7 additions & 6 deletions chainladder/methods/bornferg.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ class BornhuetterFerguson(Benktander):

raa = cl.load_sample("raa")
premium = raa.latest_diagonal * 0 + 40_000 # zero out and add 40,000 to each origin

ibnr = cl.BornhuetterFerguson(apriori=0.7).fit(X=raa, sample_weight=premium).ibnr_
print(ibnr)

Expand All @@ -77,7 +76,6 @@ class BornhuetterFerguson(Benktander):

raa = cl.load_sample("raa")
premium = raa.latest_diagonal * 0 + 40_000 * 0.7 # premium is modified by 70%

ibnr = cl.BornhuetterFerguson().fit(X=raa, sample_weight=premium).ibnr_
print(ibnr)

Expand Down Expand Up @@ -123,13 +121,15 @@ def fit(self, X, y=None, sample_weight=None):
Fit returns the estimator itself, with ``ultimate_`` populated.

.. testsetup::

import chainladder as cl

.. testcode::

tr = cl.load_sample('ukmotor')
apriori = cl.Chainladder().fit(tr).ultimate_ * 0 + 14000
print(cl.BornhuetterFerguson(apriori=1.0).fit(tr, sample_weight=apriori))
model = cl.BornhuetterFerguson(apriori=1.0).fit(tr, sample_weight=apriori)
print(model)

.. testoutput::

Expand Down Expand Up @@ -160,6 +160,7 @@ def predict(self, X, sample_weight=None):
current Triangle and a refreshed apriori.

.. testsetup::

import chainladder as cl

.. testcode::
Expand All @@ -171,10 +172,10 @@ def predict(self, X, sample_weight=None):
model = cl.BornhuetterFerguson(apriori=1.0).fit(
tr_prior, sample_weight=apriori_prior
)
ultimate = model.predict(tr, sample_weight=apriori).ultimate_
print(ultimate)

print(model.predict(tr, sample_weight=apriori).ultimate_)

.. testoutput
.. testoutput::

2261
2007 12690.000000
Expand Down
2 changes: 1 addition & 1 deletion chainladder/methods/capecod.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ def fit(self, X, y=None, sample_weight=None):
exposure = cl.Chainladder().fit(tr).ultimate_ * 0 + 20000
print(cl.CapeCod(trend=0.05).fit(tr, sample_weight=exposure))

.. testoutput:
.. testoutput::

CapeCod(trend=0.05)
"""
Expand Down
3 changes: 2 additions & 1 deletion chainladder/methods/chainladder.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,13 @@ def fit(self, X, y=None, sample_weight=None):
attribute access.

.. testsetup::

import chainladder as cl

.. testcode::

tr = cl.load_sample('ukmotor')
cl.Chainladder().fit(tr)
print(cl.Chainladder().fit(tr))

.. testoutput::

Expand Down
Loading