def test_clarkldf_weibull(genins): model = cl.ClarkLDF(growth="weibull").fit(genins) df = r('ClarkLDF(GenIns, G="weibull")').rx("THETAG") r_omega = df[0][0] r_theta = df[0][1] assert abs(model.omega_.iloc[0, 0] - r_omega) < 1e-2 assert abs(model.theta_.iloc[0, 0] / 12 - r_theta) < 1e-2
def test_clarkldf(genins): model = cl.ClarkLDF().fit(genins) df = r("ClarkLDF(GenIns)").rx("THETAG") r_omega = df[0][0] r_theta = df[0][1] assert abs(model.omega_.iloc[0, 0] - r_omega) < 1e-2 assert abs(model.theta_.iloc[0, 0] / 12 - r_theta) < 1e-2
def test_pipeline(): tri = cl.load_sample('clrd').groupby('LOB').sum()[[ 'CumPaidLoss', 'IncurLoss', 'EarnedPremDIR' ]] tri['CaseIncurredLoss'] = tri['IncurLoss'] - tri['CumPaidLoss'] X = tri[['CumPaidLoss', 'CaseIncurredLoss']] sample_weight = tri['EarnedPremDIR'].latest_diagonal dev = [ cl.Development(), cl.ClarkLDF(), cl.Trend(), cl.IncrementalAdditive(), cl.MunichAdjustment(paid_to_incurred=('CumPaidLoss', 'CaseIncurredLoss')), cl.CaseOutstanding(paid_to_incurred=('CumPaidLoss', 'CaseIncurredLoss')) ] tail = [cl.TailCurve(), cl.TailConstant(), cl.TailBondy(), cl.TailClark()] ibnr = [ cl.Chainladder(), cl.BornhuetterFerguson(), cl.Benktander(n_iters=2), cl.CapeCod() ] for model in list(itertools.product(dev, tail, ibnr)): print(model) cl.Pipeline( steps=[('dev', model[0]), ('tail', model[1]), ('ibnr', model[2])]).fit_predict( X, sample_weight=sample_weight).ibnr_.sum( 'origin').sum('columns').sum()
def test_basic_transform(raa): cl.Development().fit_transform(raa) cl.ClarkLDF().fit_transform(raa) cl.TailClark().fit_transform(raa) cl.TailBondy().fit_transform(raa) cl.TailConstant().fit_transform(raa) cl.TailCurve().fit_transform(raa) cl.BootstrapODPSample().fit_transform(raa) cl.IncrementalAdditive().fit_transform(raa, sample_weight=raa.latest_diagonal)
def test_basic_transform(): tri = cl.load_sample("raa") cl.Development().fit_transform(tri) cl.ClarkLDF().fit_transform(tri) cl.TailClark().fit_transform(tri) cl.TailBondy().fit_transform(tri) cl.TailConstant().fit_transform(tri) cl.TailCurve().fit_transform(tri) cl.BootstrapODPSample().fit_transform(tri) cl.IncrementalAdditive().fit_transform(tri, sample_weight=tri.latest_diagonal)
def test_clarkcapcod_weibull(genins): df = r('ClarkCapeCod(GenIns, Premium=10000000+400000*0:9, G="weibull")') r_omega = df.rx("THETAG")[0][0] r_theta = df.rx("THETAG")[0][1] r_elr = df.rx("ELR")[0][0] premium = genins.latest_diagonal * 0 + 1 premium.values = (np.arange(10) * 400000 + 10000000)[None, None, :, None] model = cl.ClarkLDF(growth="weibull").fit(genins, sample_weight=premium) assert abs(model.omega_.iloc[0, 0] - r_omega) < 1e-2 assert abs(model.theta_.iloc[0, 0] / 12 - r_theta) < 1e-2 assert abs(model.elr_.iloc[0, 0] - r_elr) < 1e-2
""" ==================== Clark Growth Curves ==================== This example demonstrates one of the attributes of the :class:`ClarkLDF`. We can use the growth curve ``G_`` to estimate the percent of ultimate at any given age. """ import chainladder as cl import numpy as np # Grab Industry triangles clrd = cl.load_sample('clrd').groupby('LOB').sum() # Fit Clark Cape Cod method model = cl.ClarkLDF(growth='loglogistic').fit( clrd['CumPaidLoss'], sample_weight=clrd['EarnedPremDIR'].latest_diagonal) # sample ages ages = np.linspace(1, 300, 30) # Plot results model.G_(ages).T.plot(title='Loglogistic Growth Curves', grid=True).set(xlabel='Age', ylabel='% of Ultimate')
""" ==================== Clark Residual Plots ==================== This example demonstrates how to recreate the normalized residual plots in Clarks LDF Curve-Fitting paper (2003). """ import chainladder as cl import matplotlib.pyplot as plt # Fit the basic model genins = cl.load_sample('genins') genins = cl.ClarkLDF().fit(genins) # Grab Normalized Residuals as a DataFrame norm_resid = genins.norm_resid_.melt( var_name='Development Age', value_name='Normalized Residual').dropna() # Grab Fitted Incremental values as a DataFrame incremental_fits = genins.incremental_fits_.melt( var_name='Development Age', value_name='Expected Incremental Loss').dropna() # Plot the residuals vs Age and vs Expected Incrementals fig, ((ax0, ax1)) = plt.subplots(ncols=2, figsize=(15, 5)) # Left plot norm_resid.plot(x='Development Age', y='Normalized Residual', kind='scatter', grid=True,