def test_parallelogram():
    lob = ["wkcomp"] * 3 + ["comauto"] * 3 + ["wkcomp"] * 2
    values = [0.05, 0.02, -0.1, 0.05, 0.05, 0.05, 0.2, 1 / 1.1 - 1]
    date = [
        "1/1/1989",
        "2/14/1990",
        "10/1/1992",
        "7/1/1988",
        "1/1/1990",
        "10/1/1993",
        "1/1/1996",
        "10/1/1992",
    ]
    rates = pd.DataFrame({"LOB": lob, "effdate": date, "change": values})

    olf = cl.ParallelogramOLF(rate_history=rates,
                              change_col="change",
                              date_col="effdate")

    X = cl.load_sample("clrd")["EarnedPremNet"].latest_diagonal
    X = X[X["LOB"].isin(["wkcomp", "comauto"])]
    X = olf.fit_transform(X)
    assert X.get_array_module().all(
        X.olf_.loc["comauto", "EarnedPremNet", "1994"].values -
        (9 / 12 * 9 / 12 / 2 * 0.05 + 1) < 0.005)
    assert X.get_array_module().all(
        X.olf_.loc["wkcomp", "EarnedPremNet", "1996"].values - 1.1 < 0.005)
def test_parallelogram():
    lob = ['wkcomp'] * 3 + ['comauto'] * 3 + ['wkcomp'] * 2
    values = [.05, .02, -.1, .05, .05, .05, .2, 1 / 1.1 - 1]
    date = [
        '1/1/1989', '2/14/1990', '10/1/1992', '7/1/1988', '1/1/1990',
        '10/1/1993', '1/1/1996', '10/1/1992'
    ]
    rates = pd.DataFrame({'LOB': lob, 'effdate': date, 'change': values})

    olf = cl.ParallelogramOLF(rate_history=rates,
                              change_col='change',
                              date_col='effdate')

    X = cl.load_sample('clrd')['EarnedPremNet'].latest_diagonal
    X = X[X['LOB'].isin(['wkcomp', 'comauto'])]
    X = olf.fit_transform(X)
    assert X.get_array_module().all(
        X.olf_.loc['comauto', 'EarnedPremNet', '1994'].values -
        (9 / 12 * 9 / 12 / 2 * .05 + 1) < 0.005)
    assert X.get_array_module().all(
        X.olf_.loc['wkcomp', 'EarnedPremNet', '1996'].values - 1.1 < 0.005)
Пример #3
0
        '1/1/1999', '1/1/2000', '1/1/2001', '1/1/2002', '1/1/2003', '1/1/2004',
        '1/1/2005', '1/1/2006', '1/1/2007', '1/1/2008'
    ],
    'rate_change': [.02, .02, .02, .02, .05, .075, .15, .1, -.2, -.2]
})

# Loss on-leveling factors
tort_reform = pd.DataFrame({
    'date': ['1/1/2006', '1/1/2007'],
    'rate_change': [-0.1067, -.25]
})

# In addition to development, include onlevel estimator in pipeline for loss
pipe = cl.Pipeline(steps=[('olf',
                           cl.ParallelogramOLF(tort_reform,
                                               change_col='rate_change',
                                               date_col='date',
                                               vertical_line=True)
                           ), ('dev', cl.Development(
                               n_periods=2)), ('model',
                                               cl.CapeCod(trend=0.034))])

# Define X
X = cl.load_sample('xyz')['Incurred']

# Separately apply on-level factors for premium
sample_weight = cl.ParallelogramOLF(rate_history,
                                    change_col='rate_change',
                                    date_col='date',
                                    vertical_line=True).fit_transform(
                                        xyz['Premium'].latest_diagonal)