from prospicio.reserving import (
Benktander, BornhuetterFerguson, CapeCod, ChainLadder, ExpectedLoss, TailCurve, Triangle,
)
US_YEARS = list(range(1998, 2008))
US_REPORTED = [
[37017487, 43169009, 45568919, 46784558, 47337318, 47533264, 47634419, 47689655, 47724678, 47742304],
[38954484, 46045718, 48882924, 50219672, 50729292, 50926779, 51069285, 51163540, 51185767],
[41155776, 49371478, 52358476, 53780322, 54303086, 54582950, 54742188, 54837929],
[42394069, 50584112, 53704296, 55150118, 55895583, 56156727, 56299562],
[44755243, 52971643, 56102312, 57703851, 58363564, 58592712],
[45163102, 52497731, 55468551, 57015411, 57565344],
[45417309, 52640322, 55553673, 56976657],
[46360869, 53790061, 56786410],
[46582684, 54641339],
[48853563],
]
US_PAID = [
[18539254, 33231039, 40062008, 43892039, 45896535, 46765422, 47221322, 47446877, 47555456, 47644187],
[20410193, 36090684, 43259402, 47159241, 49208532, 50162043, 50625757, 50878808, 51000534],
[22120843, 38976014, 46389282, 50562385, 52735280, 53740101, 54284334, 54533225],
[22992259, 40096198, 47767835, 52093916, 54363436, 55378801, 55878421],
[24092782, 41795313, 49903803, 54352884, 56754376, 57807215],
[24084451, 41399612, 49070332, 53584201, 55930654],
[24369770, 41489863, 49236678, 53774672],
[25100697, 42702229, 50644994],
[25608776, 43606497],
[27229969],
]
US_PREMIUM = [68574209, 68544981, 68907977, 72544955, 79228887,
86643542, 91763523, 94115312, 95272279, 95176240]
XYZ_YEARS = list(range(1998, 2009))
XYZ_FIRST_AGE = [36, 24] + [12] * 9 # months at the first observed cell of each row
XYZ_REPORTED = [
[11171, 12380, 13216, 14067, 14688, 16366, 16163, 15835, 15822],
[13255, 16405, 19639, 22473, 23764, 25094, 24795, 25071, 25107],
[15676, 18749, 21900, 27144, 29488, 34458, 36949, 37505, 37246],
[11827, 16004, 21022, 26578, 34205, 37136, 38541, 38798],
[12811, 20370, 26656, 37667, 44414, 48701, 48169],
[9651, 16995, 30354, 40594, 44231, 44373],
[16995, 40180, 58866, 71707, 70288],
[28674, 47432, 70340, 70655],
[27066, 46783, 48804],
[19477, 31732],
[18632],
]
XYZ_PAID = [
[6309, 8521, 10082, 11620, 13242, 14419, 15311, 15764, 15822],
[4666, 9861, 13971, 18127, 22032, 23511, 24146, 24592, 24817],
[1302, 6513, 12139, 17828, 24030, 28853, 33222, 35902, 36782],
[1539, 5952, 12319, 18609, 24387, 31090, 37070, 38519],
[2318, 7932, 13822, 22095, 31945, 40629, 44437],
[1743, 6240, 12683, 22892, 34505, 39320],
[2221, 9898, 25950, 43439, 52811],
[3043, 12219, 27073, 40026],
[3531, 11778, 22819],
[3529, 11865],
[3409],
]
XYZ_PREMIUM = [20000, 31500, 45000, 50000, 61183, 69175, 99322, 138151, 107578, 62438, 47797]
def triangle(years, columns, exposures=None, first_age=None):
"""A Triangle from rows of cumulative values; exposures are repeated on every cell."""
exposures = exposures or {}
first_age = first_age or [12] * len(years)
origin, age = [], []
values = {name: [] for name in [*columns, *exposures]}
rows = next(iter(columns.values()))
for i, year in enumerate(years):
for k in range(len(rows[i])):
months = first_age[i] + 12 * k
origin.append(year)
age.append(months)
for name, table in columns.items():
values[name].append(float(table[i][k]))
for name, column in exposures.items():
values[name].append(float(column[i]))
return Triangle.from_long(origin, age, values)
us = triangle(US_YEARS, {"reported": US_REPORTED, "paid": US_PAID}, {"premium": US_PREMIUM})
xyz = triangle(XYZ_YEARS, {"reported": XYZ_REPORTED, "paid": XYZ_PAID},
{"premium": XYZ_PREMIUM}, first_age=XYZ_FIRST_AGE)
print(us)
print(xyz.view("reported").iloc[:3, :5])