chainladder.Triangle

Contents

chainladder.Triangle#

class chainladder.Triangle(data=None, origin=None, development=None, columns=None, index=None, origin_format=None, development_format=None, cumulative=None, array_backend=None, pattern=False, trailing=True, *args, **kwargs)#

The core data structure of the chainladder package

Parameters:
data: DataFrame

A single dataframe that contains columns represeting all other arguments to the Triangle constructor

origin: str or list

A representation of the accident, reporting or more generally the origin period of the triangle that will map to the Origin dimension

development: str or list

A representation of the development/valuation periods of the triangle that will map to the Development dimension

columns: str or list

A representation of the numeric data of the triangle that will map to the columns dimension. If None, then a single ‘Total’ key will be generated.

index: str or list or None

A representation of the index of the triangle that will map to the index dimension. If None, then a single ‘Total’ key will be generated.

origin_format: optional str

A string representation of the date format of the origin arg. If omitted then date format will be inferred by pandas.

development_format: optional str

A string representation of the date format of the development arg. If omitted then date format will be inferred by pandas.

cumulative: bool

Whether the triangle is cumulative or incremental. This attribute is required to use the grain and dev_to_val methods and will be automatically set when invoking cum_to_incr or incr_to_cum methods.

trailing: bool

When partial origin periods are present, setting trailing to True will ensure the most recent origin period is a full period and the oldest origin is partial. If full origin periods are present in the data, then trailing has no effect.

Attributes:
index: Series

Represents all available levels of the index dimension.

columns: Series

Represents all available levels of the value dimension.

origin: DatetimeIndex

Represents all available levels of the origin dimension.

development: Series

Represents all available levels of the development dimension.

key_labels: list

Represents the index axis labels

virtual_columns: Series

Represents the subset of columns of the triangle that are virtual.

valuation: DatetimeIndex

Represents all valuation dates of each cell in the Triangle.

origin_grain: str

The grain of the origin vector (‘Y’, ‘S’, ‘Q’, ‘M’)

development_grain: str

The grain of the development vector (‘Y’, ‘S’, ‘Q’, ‘M’)

shape: tuple

The 4D shape of the triangle instance with axes corresponding to (index, columns, origin, development)

link_ratio, age_to_age

Displays age-to-age ratios for the triangle.

valuation_datedate

The latest valuation date of the data

loc: Triangle

pandas-style loc accessor

iloc: Triangle

pandas-style iloc accessor

latest_diagonal: Triangle

The latest diagonal of the triangle

is_cumulative: bool

Whether the triangle is cumulative or not

is_ultimate: bool

Whether the triangle has an ultimate valuation

is_full: bool

Whether lower half of Triangle has been filled in

is_val_tri:

Whether the triangle development period is expressed as valuation periods.

values: array

4D numpy array underlying the Triangle instance

T: Triangle

Transpose index and columns of object. Only available when Triangle is convertible to DataFrame.

Methods

append(other)

Append rows of other to the end of caller, returning a new object.

astype(dtype[, inplace])

Copy of the array, cast to a specified type.

cum_to_incr([inplace])

Method to convert an cumlative triangle into a incremental triangle.

cumsum([axis])

Refer to pandas for cumsum functionality.

describe(*args, **kwargs)

Refer to pandas for describe functionality.

dev_to_val([inplace])

Converts triangle from a development lag triangle to a valuation triangle.

development_correlation([p_critical])

Mack (1997) test for correlations between subsequent development factors.

diff([axis])

Refer to pandas for diff functionality.

drop([labels, axis])

Drop specified labels from rows or columns.

drop_duplicates(*args, **kwargs)

Refer to pandas for drop_duplicates functionality.

dropna()

Method that removes orgin/development vectors from edge of a triangle that are all missing values.

fillna([value, inplace])

Fill nan with 'value' by axis. Parameters ---------- value: single value or array-like values, default = None Value(s) to fill across the axis.

grain([grain, trailing, inplace])

Changes the grain of a cumulative triangle.

groupby(by[, axis])

Group Triangle by index values.

heatmap([cmap, low, high, axis, subset])

Color the background in a gradient according to the data in each column (optionally row).

hvplot(*args, **kwargs)

Passthrough of pandas functionality

incr_to_cum([inplace])

Method to convert an incremental triangle into a cumulative triangle.

max([axis])

Refer to pandas for max functionality.

mean([axis])

Refer to pandas for mean functionality.

median([axis])

Refer to pandas for median functionality.

melt(*args, **kwargs)

Refer to pandas for melt functionality.

min([axis])

Refer to pandas for min functionality.

pct_chg(*args, **kwargs)

Refer to pandas for pct_chg functionality.

pivot(*args, **kwargs)

Refer to pandas for pivot functionality.

plot(*args, **kwargs)

Passthrough of pandas functionality

prod([axis])

Refer to pandas for prod functionality.

quantile([axis])

Refer to pandas for quantile functionality.

rename(axis, value)

Alter axes labels.

set_backend(backend[, inplace, deep])

Converts triangle array_backend.

set_index(value[, inplace])

Sets the index of the Triangle

shift([periods, axis])

Shift elements along an axis by desired number of periods.

sort_axis(axis)

Method to sort a Triangle along a given axis

std([axis])

Refer to pandas for std functionality.

sum([axis])

Refer to pandas for sum functionality.

to_clipboard(*args, **kwargs)

Refer to pandas for to_clipboard functionality.

to_csv(*args, **kwargs)

Refer to pandas for to_csv functionality.

to_dict(*args, **kwargs)

Refer to pandas for to_dict functionality.

to_excel(*args, **kwargs)

Refer to pandas for to_excel functionality.

to_frame([origin_as_datetime, keepdims, ...])

Converts a triangle to a pandas.DataFrame. Parameters ---------- origin_as_datetime : bool Whether the origin vector should be converted from PeriodIndex into a datetime dtype. Default is False. keepdims : bool If True, the triangle will be converted to a DataFrame with all dimensions intact. The argument will force a consistent DataFrame format regardless of whether any dimensions are of length 1. implicit_axis : bool When keepdims is True, this denotes whether to include the implicit valuation axis in addition to the origin and development. Returns ------- pandas.DataFrame representation of the Triangle.

to_html(*args, **kwargs)

Refer to pandas for to_html functionality.

to_json()

Serializes triangle object to json format

to_pickle(path[, protocol])

Serializes triangle object to pickle.

trend([trend, axis, start, end, ultimate_lag])

Allows for the trending of a Triangle object along either a valuation or origin axis.

unstack(*args, **kwargs)

Refer to pandas for unstack functionality.

val_to_dev([inplace])

Converts triangle from a valuation triangle to a development lag triangle.

valuation_correlation([p_critical, total])

Mack test for calendar year effect A calendar period has impact across developments if the probability of the number of small (or large) development factors in that period occurring randomly is less than p_critical

var([axis])

Refer to pandas for var functionality.

broadcast_axis

compute

copy

exp

get_array_module

head

log

maximum

minimum

pipe

round

sort_index

sqrt

tail