Skip to main content

reserving.ChainLadderFit

A fitted chain-ladder projection of every segment of a triangle column.

Usage

Source

reserving.ChainLadderFit()

Per-origin lists (origins, latest, ultimate, reserve) run over the origins of each segment in turn, like the rows of to_frame(), so a single-segment fit has one value per origin. Per-age lists (ldf, cdf, sigma, std_err) and the tail need a single-segment fit; for several segments use development_frame() (per age), totals_frame() (tail, tail_sigma, tail_std_err) or segment(...).

Examples

>>> from prospicio.reserving import ChainLadder, Triangle
>>> tri = Triangle.from_long(
...     [2020, 2020, 2021] * 2,
...     [12, 24, 12] * 2,
...     {"paid": [100.0, 150.0, 200.0, 10.0, 20.0, 30.0]},
...     keys={"lob": ["Auto"] * 3 + ["Home"] * 3},
... )
>>> fit = ChainLadder().fit(tri, "paid")
>>> fit.index, fit.reserve

([‘Auto’, ‘Home’], [0.0, 100.0, 0.0, 30.0])

>>> fit.segment(lob="Home").ldf

[2.0]

Attributes

Name Description
blended_ldf The factors before the tail: w * selected + (1 - w) * estimated
cdf Age-to-ultimate factors, one per age, including the tail.
development Development ages in months.
estimated_ldf Age-to-age factors as estimated from the triangle, before a selected
estimated_std_err Standard error of each estimated factor.
excluded Whether n_periods or the drops left out a link ratio at some age.
index Label of each segment, as Triangle.index.
keys Names of the triangle’s key columns; empty without keys.
latest Latest observed cumulative value per origin.
ldf Selected age-to-age factors, which the projection uses: the
ldf_weight The weight on each link’s selected factor; 0 where none is
n_links Number of link ratios behind each estimated factor, after
origins Origin period of each per-origin value.
pattern_rescale For a pattern given as factors to ultimate or percents developed,
pattern_tail The tail a pattern of factors to ultimate or percents developed
reserve Reserve (ultimate minus latest) per origin.
selected_ldf The selected pattern’s age-to-age factor of each link, after
sigma Variance parameter of each factor, with unestimable ones
std_err Standard error of each factor used before the tail: (1 -</td> </tr> <tr> <td><a href="#tail" class="doc-attribute doc-label doc-label-property">tail</a></td> <td>Tail factor from the oldest age to ultimate.</td> </tr> <tr> <td><a href="#tail_attachment_age" class="doc-attribute doc-label doc-label-property">tail_attachment_age</a></td> <td>Age from whichldfholds the tail's factors rather than the</td> </tr> <tr> <td><a href="#tail_ldf" class="doc-attribute doc-label doc-label-property">tail_ldf</a></td> <td>Factors past the oldest age, which multiply totail``: one per
tail_sigma The tail’s variance parameter, extrapolated log-linearly; 0 without
tail_std_err Standard error of the tail factor, extrapolated log-linearly.
total_reserve Total reserve across segments and origins.
total_ultimate Total ultimate across segments and origins.
ultimate Projected ultimate per origin.

blended_ldf

The factors before the tail: w * selected + (1 - w) * estimated

blended_ldf: list[float]

where a factor is selected, the estimate elsewhere.


cdf

Age-to-ultimate factors, one per age, including the tail.

cdf: list[float]


development

Development ages in months.

development: list[int]


estimated_ldf

Age-to-age factors as estimated from the triangle, before a selected

estimated_ldf: list[float]

pattern or the tail replaced any.


estimated_std_err

Standard error of each estimated factor.

estimated_std_err: list[float]


excluded

Whether n_periods or the drops left out a link ratio at some age.

excluded: bool


index

Label of each segment, as Triangle.index.

index: list[Any]


keys

Names of the triangle’s key columns; empty without keys.

keys: list[str]


latest

Latest observed cumulative value per origin.

latest: list[float]


ldf

Selected age-to-age factors, which the projection uses: the

ldf: list[float]

estimated ones (or a selected pattern’s, blended_ldf), replaced by the tail’s from its attachment age. Factor k links age k to k + 1.


ldf_weight

The weight on each link’s selected factor; 0 where none is

ldf_weight: list[float]

selected.



origins

Origin period of each per-origin value.

origins: list[str]


pattern_rescale

For a pattern given as factors to ultimate or percents developed,

pattern_rescale: float | None

the factor that multiplies the given percents developed (and divides the given factors to ultimate) to reconcile the pattern’s level at its last age with the factors and tail in use: cdf_given / cdf_used there, so that a pattern given to the oldest age with a tail, rescaled, times the tail is 100%. 1 for a pattern to the oldest age with no tail, whose level is the tail (pattern_tail). At earlier ages the rescaled values are the projection’s only where every link is fully selected; with ldf_weight below 1, read cdf for the factors in use. None for an age-to-age pattern or none.


pattern_tail

The tail a pattern of factors to ultimate or percents developed

pattern_tail: float | None

implies: with no tail and a pattern to the oldest age, its factor to ultimate there (1 over its percent developed), used as a constant tail with no parameter error (tail_std_err 0, its sigma extrapolated as a constant tail’s). None with a tail, for a pattern that stops before the oldest age, an age-to-age pattern, or none.


reserve

Reserve (ultimate minus latest) per origin.

reserve: list[float]


selected_ldf

The selected pattern’s age-to-age factor of each link, after

selected_ldf: list[float | None]

conversion from ldf_kind; None where it selects none.


sigma

Variance parameter of each factor, with unestimable ones

sigma: list[float]

interpolated (nan where that is impossible).


std_err

Standard error of each factor used before the tail: ``(1 -

std_err: list[float]

ldf_weight)timesestimated_std_err``, so 0 where a selected pattern replaces the estimate.


tail

Tail factor from the oldest age to ultimate.

tail: float


tail_attachment_age

Age from which ldf holds the tail’s factors rather than the

tail_attachment_age: int

estimated ones; the oldest age when the tail replaced none.


tail_ldf

Factors past the oldest age, which multiply to tail: one per

tail_ldf: list[float]

development period of the following year and one to ultimate, as chainladder-python’s ldf_ (a single factor for TailLogLinear).


tail_sigma

The tail’s variance parameter, extrapolated log-linearly; 0 without

tail_sigma: float

a tail (a factor of 1), nan if it cannot be extrapolated. A tail below 1 is read where a tail of 1.001 would be, as chainladder-python does.


tail_std_err

Standard error of the tail factor, extrapolated log-linearly.

tail_std_err: float


total_reserve

Total reserve across segments and origins.

total_reserve: float


total_ultimate

Total ultimate across segments and origins.

total_ultimate: float


ultimate

Projected ultimate per origin.

ultimate: list[float]

Methods

Name Description
development_frame() One row per segment and age: the key columns, development,
from_json() A fit from a document written by to_json.
segment() The fit of one segment, chosen by key values (compared as str()
to_chain_ladder() The fit frozen as a ChainLadder: its factors in use (ldf) as
to_frame() One row per segment and origin: the key columns, origin,
to_json() This fit, every segment, as a JSON document that from_json reads
totals_frame() One row per segment: the key columns, the segment’s total

development_frame()

One row per segment and age: the key columns, development,

Usage

Source

development_frame()

ldf (the selected factor to the next age), cdf (to ultimate, with the tail), sigma and std_err; the oldest age has nan for ldf, sigma and std_err, and the tail factor as its cdf. With a selected pattern, also estimated_ldf, selected_ldf (nan where none), ldf_weight, blended_ldf and estimated_std_err. Needs pandas.

Returns
pandas.DataFrame

from_json()

A fit from a document written by to_json.

Usage

Source

from_json(text)
Parameters
text: str
Returns
ChainLadderFit
Raises
ValueError
If the text is not such a document, or is from a newer version.

segment()

The fit of one segment, chosen by key values (compared as str()

Usage

Source

segment(**keys)

of each value). Keys not named may take any value, so a fit with one segment needs none.

Returns
ChainLadderFit
Raises
ValueError
If a key or value is unknown, or the choice matches several segments.

to_chain_ladder()

The fit frozen as a ChainLadder: its factors in use (ldf) as

Usage

Source

to_chain_ladder()

fully selected age-to-age factors at its ages, and its tail factor as a constant tail (docs/design/reserving-v02.md, decision 17). Applied to the fit’s own latest diagonal it projects as the fit did, the factors to the bit; to another book’s (LatestDiagonal.from_triangle) it is chainladder-python’s fit(source).predict(book). Its ldf, ldf_kind and tail unpack into any method’s arguments, as BornhuetterFerguson(apriori=0.6, ldf=cl.ldf, ldf_kind=cl.ldf_kind, tail=cl.tail). It does not carry sigma, the standard errors or the tail’s form. Needs a single-segment fit: for several segments pass the fit as development to fit_diagonal, or use segment(...).

Examples
>>> from prospicio.reserving import ChainLadder, LatestDiagonal, Triangle
>>> tri = Triangle.from_long([2020, 2020, 2021], [12, 24, 12], {"paid": [100.0, 150.0, 200.0]})
>>> cl = ChainLadder(tail=1.1).fit(tri, "paid").to_chain_ladder()
>>> cl.ldf, cl.ldf_kind, cl.tail

({12: 1.5}, ‘ldf’, 1.1)


to_frame()

One row per segment and origin: the key columns, origin,

Usage

Source

to_frame()

latest, ultimate and reserve. Needs pandas.

Returns
pandas.DataFrame

to_json()

This fit, every segment, as a JSON document that from_json reads

Usage

Source

to_json()

back exactly: every number bit for bit, as Triangle.to_json does. Pickling uses it too.

Returns
str
Examples
>>> import pickle
>>> from prospicio.reserving import ChainLadder, ChainLadderFit, Triangle
>>> tri = Triangle.from_long(origin=[2020, 2020, 2021], development=[12, 24, 12],
...                          values={"paid": [100.0, 150.0, 110.0]})
>>> fit = ChainLadder().fit(tri, "paid")
>>> ChainLadderFit.from_json(fit.to_json()).ultimate == fit.ultimate

True

>>> pickle.loads(pickle.dumps(fit)).to_json() == fit.to_json()

True


totals_frame()

One row per segment: the key columns, the segment’s total

Usage

Source

totals_frame()

latest, ultimate and reserve, and its tail, tail_sigma and tail_std_err; with a selected pattern, its pattern_rescale and pattern_tail too (nan where there is none). Needs pandas.

Returns
pandas.DataFrame