Skip to content
Open
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
8 changes: 4 additions & 4 deletions chainladder/development/tests/test_barnzehn.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ def test_bz_2008():
exposure=np.array([[2.2], [2.4], [2.2], [2.0], [1.9], [1.6], [1.6], [1.8], [2.2], [2.5], [2.6]])
abc_adj = abc/exposure

origin_buckets = [(0,1),(2,2),(3,4),(5,10)]
dev_buckets = [(24,36),(36,48),(48,84),(84,108),(108,144)]
val_buckets = [(1,8),(8,9),(9,12)]
origin_buckets = [0,2,3,5]
dev_buckets = [12,24,36,72,96,132]
val_buckets = [0,7,8,11]

abc_formula = PTF_formula(abc_adj,alpha=origin_buckets,gamma=dev_buckets,iota=val_buckets)

model=cl.BarnettZehnwirth(formula=abc_formula, drop=('1982',72)).fit(abc_adj)
Expand Down
16 changes: 9 additions & 7 deletions chainladder/utils/utility_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -772,24 +772,26 @@ def model_diagnostics(model, name=None, groupby=None):
def PTF_formula(tri: Triangle, alpha: ArrayLike = None, gamma: ArrayLike = None, iota: ArrayLike = None):
""" Helper formula that builds a patsy formula string for the BarnettZehnwirth
estimator. Each axis's parameters can be grouped together. Groups of origin
parameters (alpha) are set equal, and are specified by a ranges (inclusive).
parameters (alpha) are set equal, and are specified by the first period in each bin.
Groups of development (gamma) and valuation (iota) parameters are fit to
separate linear trends, specified as tuples denoting ranges with shared endpoints.
separate linear trends, specified a list denoting the endpoints of the linear pieces.
In other words, development and valuation trends are fit to a piecewise linear model.
A triangle must be supplied to provide some critical information.
"""
formula_parts=[]
if(alpha):
# The intercept term takes the place of the first alpha
for ind,a in enumerate(alpha):
if(a[0]==0):
if(a==0):
alpha=alpha[:ind]+alpha[(ind+1):]
formula_parts += ['+'.join([f'I({x[0]} <= origin)' for x in alpha])]
if(gamma):
formula_parts += ['+'.join([f'I({x} <= origin)' for x in alpha])]
if(gamma):
dgrain = min(tri.development)
formula_parts += ['+'.join([f'I((np.minimum({x[1]-dgrain},development) - np.minimum({x[0]-dgrain},development))/{dgrain})' for x in gamma])]
for ind in range(1,len(gamma)):
formula_parts += ['+'.join([f'I((np.minimum({gamma[ind]},development) - np.minimum({gamma[ind-1]},development))/{dgrain})'])]
if(iota):
formula_parts += ['+'.join([f'I(np.minimum({x[1]-1},valuation) - np.minimum({x[0]-1},valuation))' for x in iota])]
for ind in range(1,len(iota)):
formula_parts += ['+'.join([f'I(np.minimum({iota[ind]},valuation) - np.minimum({iota[ind-1]},valuation))'])]
if(formula_parts):
return '+'.join(formula_parts)
return ''
Binary file added docs/images/plot_ptf_coefficients.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions docs/library/references.bib
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,11 @@ @article{shapland2016
year = {2016},
url = {https://live-casact.pantheonsite.io/sites/default/files/2021-02/04-shapland.pdf}
}

@article{barnett2008,
author = {Barnett, G. and Zehnwirth, B.},
title = {Modeling with the {M}ultivariate {P}robabilistic {T}rend {F}amily},
journal = {Casualty Actuarial Society E-Forum},
year = {2008},
url = {https://www.casact.org/sites/default/files/database/forum_08fforum_3barnett_zehnwirth.pdf}
}
Loading