Skip to content

Conversation

@danielfong-act
Copy link
Contributor

This PR is intended to close #623.

The heavy lifting by @henrydingliu of replicating the model specified in this paper has been generalized and placed into the helper function PTF_formula located in chainladder.utils.utility_functions.

Also, the slapdash multicollinearity warning I added a while ago was removed, because any formula constructed by PTF_formula will trigger it.

Things that aren't done:

  1. The documentation and examples haven't been updated yet. They should show how to build patsy formulas to create models akin to those of the papers.
  2. Coefficient names in coef_ aren't so great. I'd like to replace them with numbered alphas, gammas and iotas to make what's going on more obvious. Pandas.DataFrame.rename seemed like the right tool for that job, but I had no luck with it.

Things to consider:

  1. The docstring for PTF_formula could be made clearer. Feel free to suggest edits.
  2. Should the functionality of PTF_formula be inside BarnettZehnwirth itself? I opted to place it outside to avoid dealing with the internal interaction between user specified formulas and Greek parameters.
  3. Should how alpha, gamma, and iota are specified to PTF_formula be tweaked? Currently, origin groups are disjoint while development and valuation groups overlap.

danielfong-act added 3 commits January 6, 2026 11:37
…TF_formula. Removes first year's origin trend group, if specified (intercept term takes its place).
@codecov
Copy link

codecov bot commented Jan 7, 2026

Codecov Report

❌ Patch coverage is 68.75000% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 85.05%. Comparing base (2e38f15) to head (bb8d301).
⚠️ Report is 2 commits behind head on BZ_w_drop.

Files with missing lines Patch % Lines
chainladder/utils/utility_functions.py 66.66% 1 Missing and 4 partials ⚠️
Additional details and impacted files
@@              Coverage Diff              @@
##           BZ_w_drop     #642      +/-   ##
=============================================
+ Coverage      85.04%   85.05%   +0.01%     
=============================================
  Files             85       85              
  Lines           4855     4865      +10     
  Branches         616      619       +3     
=============================================
+ Hits            4129     4138       +9     
+ Misses           521      518       -3     
- Partials         205      209       +4     
Flag Coverage Δ
unittests 85.05% <68.75%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@danielfong-act danielfong-act marked this pull request as ready for review January 7, 2026 03:03
@henrydingliu
Copy link
Collaborator

some recommendations

  • since the ptf formulas are only used in constructing a patsy formula, we can build the ptf formulas directly into the patsyformula class. the three lists can be 3 optional parameters, and create terms that are added to the main formula (which could be left as empty so only the ptf terms are used).
  • if we did the above, we'd also need to add those lists as optional parameters to glm and bz
  • renaming can be done directly within the design matrix specification. this becomes possible if we incorporate the ptf formulas into the patsyformula class. see their doc for info.
  • we can simplify the ptf formula specification to lists of numbers [2,3,8], rather than the lists of tuples [(2,3),(3,8),(8,99)]. then we dont have to worry about overlaps etc.

@kennethshsu
Copy link
Collaborator

@henrydingliu do you want to be the reviewer for this one?

Copy link
Collaborator

@henrydingliu henrydingliu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please modify the PTF test to use PTF_formula

…e formula for test_bz_2008. Tweaks alpha parameters to be additive again.
@danielfong-act
Copy link
Contributor Author

Done. Also, I changed back how the origin coefficients are fitted. The way PTF_formula fits origin parameters differs from the specification of alphas in the papers. First, we fit an intercept, which seems to me to be a necessary way to get the first alpha, $\alpha_0$, to fit properly. Each later origin coefficient is fit as an incremental value, with the intercept acting as a baseline. Thus, $\alpha_i$ in the paper corresponds to the sum of the intercept and the first $i$ origin coefficients. Stated differently, origin coefficient $i$ is the difference $\alpha_i-\alpha_{i-1}$.

I tried to reformulate things a number of different ways to bring the origin coefficients in line with the paper. I gave up after a few tries, but inadvertently left things so that origin coefficent $i$ was actually equal to $\alpha_i-\alpha_0$. I think that's a lot more confusing, so thanks for making me check.

@henrydingliu henrydingliu merged commit 79231bf into casact:BZ_w_drop Jan 7, 2026
5 of 6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants