Repository navigation
Description
BootstrapODPSample raises ValueError: Only single index triangles are supported for any triangle with more than one index row (bootstrap.py L193). The user guide states the same limit. A user with several lines of business has to loop over the rows and fit each one alone.
That loop drops the dependence between lines. Kirschner, Kerley & Isaacs bootstrap several lines together by making one random draw per accident year and development year cell and using that draw in every line (Variance 2(1), 2008, §4.5 and Tables 7 to 9). Each line keeps its own residuals, and the choice of which residual goes into a cell stays the same across lines. The aggregate reserve then carries whatever correlation the historical triangles show, with no correlation matrix to choose.
On the six clrd lines of business summed by LOB, the per-line loop with seeds 1 to 6 gives pairwise correlations between line IBNR of -0.082 to 0.067 over 500 simulations. The seeds start at 1 because random_state=0 leaves the process-variance draw unseeded, which #1568 covers.
Snippet for the error and the per-line loop
import warnings
import numpy as np
import chainladder as cl
warnings.filterwarnings("ignore")
tri = cl.load_sample("clrd").groupby("LOB").sum()["CumPaidLoss"]
print(tri.shape, list(tri.index["LOB"]))
try:
cl.BootstrapODPSample(n_sims=500, random_state=42).fit(tri)
except ValueError as e:
print("ValueError:", e)
# Workaround today: one fit per line, with seeds 1 to 6
ibnr = np.array([
cl.Chainladder()
.fit(cl.BootstrapODPSample(n_sims=500, random_state=i + 1).fit_transform(tri.iloc[i]))
.ibnr_.sum("origin").values.ravel()
for i in range(len(tri))
])
corr = np.corrcoef(ibnr)[np.triu_indices(len(tri), 1)]
print("total IBNR mean", round(ibnr.sum(0).mean()), "sd", round(ibnr.sum(0).std(ddof=1)))
print("pairwise corr", round(corr.min(), 3), "to", round(corr.max(), 3))Output at 687e329
(6, 1, 10, 10) ['comauto', 'medmal', 'othliab', 'ppauto', 'prodliab', 'wkcomp']
ValueError: Only single index triangles are supported
total IBNR mean 25148371 sd 676929
pairwise corr -0.082 to 0.067
A shared random_state does not fix this. _get_simulation draws from a pool of the finite nonzero residuals (L256 to L263). The same seed picks the same pool positions only when two lines have pools of the same size, and those positions map to the same cells only when the zero residuals sit in the same cells. On clrd the pools hold 53 or 54 residuals. With random_state=42 for every line, pairs with equal pool sizes correlate at 0.078 to 0.612 and pairs with unequal sizes at -0.031 to 0.145. Multi-column triangles already loop over columns with one shared random_state (L168), so they get the same partial alignment.
Snippet for the pool sizes and the shared-seed correlations
import warnings
import numpy as np
import chainladder as cl
warnings.filterwarnings("ignore")
tri = cl.load_sample("clrd").groupby("LOB").sum()["CumPaidLoss"]
# Record the size of the residual pool each fit draws from
sizes = []
class Recorder(np.random.RandomState):
def choice(self, a, *args, **kwargs):
sizes.append(len(a))
return super().choice(a, *args, **kwargs)
np.random.RandomState = Recorder
# The same seed for every line
ibnr = np.array([
cl.Chainladder()
.fit(cl.BootstrapODPSample(n_sims=500, random_state=42).fit_transform(tri.iloc[i]))
.ibnr_.sum("origin").values.ravel()
for i in range(len(tri))
])
pool = sizes[::500]
print("pool sizes", dict(zip(tri.index["LOB"], pool)))
corr = np.corrcoef(ibnr)
same = [corr[i, j] for i in range(6) for j in range(i + 1, 6) if pool[i] == pool[j]]
diff = [corr[i, j] for i in range(6) for j in range(i + 1, 6) if pool[i] != pool[j]]
print("corr, equal pool sizes", round(min(same), 3), "to", round(max(same), 3))
print("corr, unequal pool sizes", round(min(diff), 3), "to", round(max(diff), 3))Output at 687e329
pool sizes {'comauto': 53, 'medmal': 53, 'othliab': 54, 'ppauto': 53, 'prodliab': 54, 'wkcomp': 53}
corr, equal pool sizes 0.078 to 0.612
corr, unequal pool sizes -0.031 to 0.145
Proposal
- Accept
len(X) > 1. For each simulation, draw one set of source cells from the cells where every row has a residual, and apply that set to every row. - Label the output with the existing code that pairs
X.indexwithSimulation_#(L279 to L283). - Keep independent draws per row as an option, so users can compare the two.
The output holds n_sims × n_index dense triangles, since fit converts sparse input to numpy. Memory grows linearly in both counts. 500 simulations of the six clrd lines at 10 by 10 come to 2.4 MB in float64, the same as the per-line loop builds today.
Should synchronized draws be the default for a multi-index triangle, or sit behind a parameter?
(This issue was written with Árbol, an AI assistant, under my direction.)
Metadata
Metadata
Assignees
Labels
Type
Fields
Priority
Scope
Effort
Projects
- StatusShow more project fieldsNot Ready
Activity