You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[BUG] MackChainladder fails on a triangle fit with Development(groupby=...) #1563
Development(groupby="LOB") pools the clrd companies by line of business, and Chainladder applies each line's pattern to its companies. MackChainladder fails on the same transformed triangle with a broadcast error. sigma_ and std_err_ keep one row per line (6 rows), and the Mack recursion multiplies their raw arrays against the 775-company triangle, without the index alignment that Triangle arithmetic gives ldf_ and cdf_.
Fitting MackChainladder to clrd.groupby("LOB").sum() works, so only grouped patterns applied back to the companies are affected.
A fix has to decide what each company inherits from its line. Giving each company its line's sigma_ and std_err_ is one option, and raising a clear error that grouped patterns are not supported is another. Which would you prefer? Expanding sigma_ and std_err_ by hand is not enough on its own, because the default tail's statistics (_get_tail_stats in chainladder/tails/base.py) then hit the same mismatch.
Would you be willing to contribute this ticket?
Yes, absolutely!
Yes, but I would like some help.
No.
(This issue was written with Árbol, an AI assistant, under my direction.)
Chainladder doesn't broadcast ldf_ itself; Triangle arithmetic does it. align_pattern computes X / X * pattern. X is indexed by GRNAME and LOB and cdf_ by LOB only, so _prep_index groups both sides by LOB, and _arithmetic_mapper multiplies each line's companies by that line's row. full_triangle_ gets its company-level ldf_ the same way (common.py L44).
Mack can reuse it. Its recursion multiplies raw arrays (sigma_, w_, std_err_, ldf_, cdf_), so 6 line rows meet 775 company rows. A local branch runs the same Triangle multiplication to find each company's line, then gives the company that line's ldf_, sigma_, std_err_ and w_. On clrd CumPaidLoss with groupby="LOB":
all 775 companies' Mack figures equal, exactly, a fit of each company alone with its line's parameters;
ungrouped fits on raa, genins, clrd and mw2008 are bit-identical to main;
the fit takes 0.47 s against 0.18 s ungrouped, mostly for the lookup, which could run once per fit or be a pandas merge (same rows, about 17x faster).
The tail mismatch in the issue came only from expanding sigma_/std_err_ by hand, so the tails need no change: with TailConstant and TailCurve, a 40-company sample matches company by company. TailBondy.fit has its own grouped-pattern bug, on main too. Fits on rows out of index order, or on a line the pattern lacks, raise a clear ValueError.
The change is in mack.py and its tests. It conflicts with #1416 and #1304 there. Shall I open the PR?
(This comment was made with Árbol, an AI assistant, under my direction.)
Activity
henrydingliu commentedon Nov 10, 2026
how does regular
Chainladderbroadcast ldf_ withgroupby? can we reuse the same mechanism?scks1 commentedon Nov 11, 2026
Chainladderdoesn't broadcastldf_itself; Triangle arithmetic does it.align_patterncomputesX / X * pattern.Xis indexed by GRNAME and LOB andcdf_by LOB only, so_prep_indexgroups both sides by LOB, and_arithmetic_mappermultiplies each line's companies by that line's row.full_triangle_gets its company-levelldf_the same way (common.py L44).Mack can reuse it. Its recursion multiplies raw arrays (
sigma_,w_,std_err_,ldf_,cdf_), so 6 line rows meet 775 company rows. A local branch runs the same Triangle multiplication to find each company's line, then gives the company that line'sldf_,sigma_,std_err_andw_. On clrdCumPaidLosswithgroupby="LOB":The tail mismatch in the issue came only from expanding
sigma_/std_err_by hand, so the tails need no change: withTailConstantandTailCurve, a 40-company sample matches company by company.TailBondy.fithas its own grouped-pattern bug, on main too. Fits on rows out of index order, or on a line the pattern lacks, raise a clear ValueError.The change is in
mack.pyand its tests. It conflicts with #1416 and #1304 there. Shall I open the PR?(This comment was made with Árbol, an AI assistant, under my direction.)
henrydingliu commentedon Nov 11, 2026
let's wait till #1304 lands