ParallelogramOLF#

class chainladder.ParallelogramOLF(rate_history=None, change_col='', date_col='', approximation_grain='M', policy_length=12, vertical_line=False)[source]#

Estimator to create and apply on-level factors to a Triangle object. This is commonly used for premium vectors expressed as a Triangle object.

Parameters:
rate_history: pd.DataFrame

A DataFrame with two columns: one containing the effective dates of the rate changes and the other containing the rate changes expressed as a decimal. For example, 5% decrease should be stated as -0.05.

change_col: str

The column containing the rate changes expressed as a decimal. For example, 5% decrease should be stated as -0.05.

date_col: str

A list-like set of effective dates corresponding to each of the changes.

approximation_grain: str {“M”, “D”} (default=”M”)

The resolution of the internal calendar spacing used to calculate on-level factors can be set to monthly (‘M’) or daily (‘D’). Under each approximation_grain, periods are treated as discrete intervals and a weighted current rate level is estimated. In monthly mode, each month is treated as an equal-length period, consistent with the methodology presented in the Friedland text, although this assumes that all months within a year contain the same number of days. In daily mode, each calendar day is treated as a full period, providing finer granularity and more accurately accounting for differences in month length and leap years when assigning factors to origin periods.

policy_length: int (default=12)

The length of the policy in months.

vertical_line: bool (default=False)

Rates are typically stated on an effective date basis and premiums on and earned basis. By default, this argument is False and produces parallelogram OLFs. If True, Parallelograms become squares. This is commonly seen in Workers Compensation with benefit on-leveling or if the premium origin is also stated on an effective date basis.

Attributes:
olf_:

A triangle representation of the on-level factors

Examples

Premium vectors are expressed as a Triangle object. This example shows how to create and apply on-level factors to a Triangle object with one rate change.

import pandas as pd
import numpy as np

xyz = cl.load_sample("xyz")
olf = (
    cl.ParallelogramOLF(
        rate_history=pd.DataFrame(
            {
                "EffDate": ["2001-07-01"],
                "RateChange": [0.20],
            }
        ),
        change_col="RateChange",
        date_col="EffDate",
    )
    .fit_transform(xyz["Premium"])
    .olf_
)
xyz["Leveled Premium"] = xyz["Premium"] * olf
print(np.round(xyz["Leveled Premium"], 0))
           12        24        36        48       60       72       84       96       108      120      132
1998       NaN       NaN   24000.0   24000.0  24000.0  24000.0  24000.0  24000.0  24000.0  24000.0  24000.0
1999       NaN   37800.0   37800.0   37800.0  37800.0  37800.0  37800.0  37800.0  37800.0  37800.0      NaN
2000   54000.0   54000.0   54000.0   54000.0  54000.0  54000.0  54000.0  54000.0  54000.0      NaN      NaN
2001   58537.0   58537.0   58537.0   58537.0  58537.0  58537.0  58537.0  58537.0      NaN      NaN      NaN
2002   62485.0   62485.0   62485.0   62485.0  62485.0  62485.0  62485.0      NaN      NaN      NaN      NaN
2003   69175.0   69175.0   69175.0   69175.0  69175.0  69175.0      NaN      NaN      NaN      NaN      NaN
2004   99322.0   99322.0   99322.0   99322.0  99322.0      NaN      NaN      NaN      NaN      NaN      NaN
2005  138151.0  138151.0  138151.0  138151.0      NaN      NaN      NaN      NaN      NaN      NaN      NaN
2006  107578.0  107578.0  107578.0       NaN      NaN      NaN      NaN      NaN      NaN      NaN      NaN
2007   62438.0   62438.0       NaN       NaN      NaN      NaN      NaN      NaN      NaN      NaN      NaN
2008   47797.0       NaN       NaN       NaN      NaN      NaN      NaN      NaN      NaN      NaN      NaN

Of course, we can have multiple rate changes, or assuems that policies are 24 months long with policy_length. We can also get more accurate OLFs by using the approximation_grain argument to set the resolution of the internal calendar spacing used to calculate on-level factors.

xyz = cl.load_sample("xyz")
olf = (
    cl.ParallelogramOLF(
        rate_history=pd.DataFrame(
            {
                "EffDate": ["2001-07-01", "2023-10-01"],
                "RateChange": [0.20, -0.05],
            }
        ),
        change_col="RateChange",
        date_col="EffDate",
        policy_length=24,
        approximation_grain="D",
    )
    .fit_transform(xyz["Premium"])
    .olf_
)
xyz["Leveled Premium"] = xyz["Premium"] * olf
print(np.round(xyz["Leveled Premium"], 0))
           12        24        36        48       60       72       84       96       108      120      132
1998       NaN       NaN   24000.0   24000.0  24000.0  24000.0  24000.0  24000.0  24000.0  24000.0  24000.0
1999       NaN   37800.0   37800.0   37800.0  37800.0  37800.0  37800.0  37800.0  37800.0  37800.0      NaN
2000   54000.0   54000.0   54000.0   54000.0  54000.0  54000.0  54000.0  54000.0  54000.0      NaN      NaN
2001   59247.0   59247.0   59247.0   59247.0  59247.0  59247.0  59247.0  59247.0      NaN      NaN      NaN
2002   66720.0   66720.0   66720.0   66720.0  66720.0  66720.0  66720.0      NaN      NaN      NaN      NaN
2003   69891.0   69891.0   69891.0   69891.0  69891.0  69891.0      NaN      NaN      NaN      NaN      NaN
2004   99322.0   99322.0   99322.0   99322.0  99322.0      NaN      NaN      NaN      NaN      NaN      NaN
2005  138151.0  138151.0  138151.0  138151.0      NaN      NaN      NaN      NaN      NaN      NaN      NaN
2006  107578.0  107578.0  107578.0       NaN      NaN      NaN      NaN      NaN      NaN      NaN      NaN
2007   62438.0   62438.0       NaN       NaN      NaN      NaN      NaN      NaN      NaN      NaN      NaN
2008   47797.0       NaN       NaN       NaN      NaN      NaN      NaN      NaN      NaN      NaN      NaN
fit(X, y=None, sample_weight=None)[source]#

Fit the model with X.

Parameters:
X: Triangle-like

Data to which the model will be applied.

y: Ignored
sample_weight: Ignored
Returns:
self: object

Returns the instance itself.

transform(X, y=None, sample_weight=None)[source]#

If X and self are of different shapes, align self to X, else return self.

Parameters:
X: Triangle

The triangle to be transformed

Returns:
X_new: New triangle with transformed attributes.

Inherited Methods

ParallelogramOLF.fit_transform

Fit to data, then transform it.

ParallelogramOLF.get_metadata_routing

Get metadata routing of this object.

ParallelogramOLF.get_params

Get parameters for this estimator.

ParallelogramOLF.set_output

Set output container.

ParallelogramOLF.set_params

Set the parameters of this estimator.

ParallelogramOLF.to_json

Serializes triangle object to json format

ParallelogramOLF.to_pickle

Serializes triangle object to pickle.