Alloc rule 2 bug - #412
Open
Ha-Ree wants to merge 2 commits into
Open
Conversation
runtests.sh and ctrl.sha1 already reference these files. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes the back-allocation half of OasisLMF#2055 — under
-a2, per item losses depend on which policy happens to be layer 1, so per location IL depends on the row order ofaccount.csv. Also fixes a segmentation fault in the same code path.The bug
compute_item_proportionshas two ways of working out the item proportions used to back-allocate a level's loss:Under rule 2 nothing ever fills in
agg_vecs[level][layer].item_propfor the intermediate levels of layers above 1, so when the final level chains through the level below it finds a null and falls back to layer 1's proportions:Every layer therefore gets back-allocated using layer 1's distribution of loss over items. Since
layer_idfollows the row order ofaccount.csv, reordering the file changes which policy is layer 1 and so changes every layer's item split. Rule 3 was unaffected because it never leaves the gap.The two rules were never intended to differ. Rule 3 was added in
7bbb5a6as a lazy variant of the existing rule, and817eee8("switch alloc rules 2 and 3") swapped the numbering so the lazy implementation became the default2. The loop bodies carry identical comments.Second bug in the same place
The layer 1 pass skips aggregations with no loss (
allowzeros == falseon the sampled path), leaving theiritem_propnull. If a later layer does have loss at such an aggregation, the fallback above hands it a null pointer and fmcalc dereferences it. Released 3.12.4 segfaults on 8 of 250 random multi-layer structures under-a2.The fix
In the per-layer branch of
compute_item_proportions:Alloc rules 0, 1 and 3 are untouched.
Verification
-a2-a3and to fmpy-a2vs-a3-a2vs-a2 -Oand-a2 -o-a2vs fmpy-a2-a2validation/cases,-a0/1/2/3make check_alloc2.csvchecksExisting runs are only affected where a programme has more than one layer and layer specific terms below the top level that distribute loss over items differently. Single layer programmes, and layers whose terms are all blanket, are bit for bit unchanged.
Performance
No measurable change on single layer structures. About 15% slower on a 4 level, 4 layer structure, which is the cost of doing the per-layer work that rule 3 always did — still cheaper than rule 3, which recomputes the layer 1 chain at every level.
Tests
ktest had no back-allocation coverage at all:
fmcalcwas only ever run with the default-a0. This adds two small cases underexamples/fm_alloc, each run through-a1,-a2and-a3:The expected
-a2and-a3outputs are identical, which is the invariant this PR restores.Docs
One sentence in
docs/md/fmprofiles.mdrecording that rules 2 and 3 are the same calculation with different evaluation strategies, since the table's "(reinsurance)" label reads as though they differ.