Repository navigation
[FIX] Preserve off-grid incremental rate changes in ParallelogramOLF - #1491
kadyrbekovhamit-cyber wants to merge 4 commits into
Conversation
Pyright Type CompletenessView the full Project (full
Other symbols referenced but not exported by
Symbols without documentation:
Patch (exported symbols added or changed by this PR): 75.0% fully typed (6 / 8)
Patch symbol details
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1491 +/- ##
==========================================
+ Coverage 94.34% 94.36% +0.02%
==========================================
Files 96 97 +1
Lines 5973 6198 +225
Branches 768 798 +30
==========================================
+ Hits 5635 5849 +214
- Misses 219 225 +6
- Partials 119 124 +5
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
@kadyrbekovhamit-cyber this bug is at least a year old. here is the (presumbly correct) numbers from 0.8.x.
the doc build for this PR shows that your fix puts the package much closer but not exact. of course, given the number of fixes that's been attempted on this particular block of code, it's entirely possible that 0.8.x was incorrect. could you please investigate and demonstrate which is the absolute correct number? after which, we should hardocde the correct results into one of these tests to definitively guard against any future drift. |
Add fixed rational references for the documented monthly and daily conventions in response to review on casact#1491. AI assistance disclosed in the PR; no contribution declarations are changed.
|
Thanks for pointing out the archived example. I traced the difference to a change in averaging conventions and derived independent references for the current documented model. The archived rounded results match the older implementation: it first computes I derived the reference by integrating earned exposure, using exact rational arithmetic, and independently checked it by integrating the overlap of each policy cohort with each origin year. A rate-level jump Δr at date d contributes
where For the current equal-month/as-of convention (T=12, July 15 mapped to August 1 and October 31 to November 1), the exact factors for 2016–2020 are:
For example, the 2020 share at the new rate is Daily resolution gives I added Added regression test (commit AI assistance was used in the investigation, code and writing. The original contribution-process disclosures remain unchanged. |
Wrap two long expressions. Executable AST is unchanged; repository-wide Ruff check and format checks pass (198 files).
| @@ -0,0 +1,77 @@ | |||
| # This Source Code Form is subject to the terms of the Mozilla Public | |||
There was a problem hiding this comment.
can you please put this test inside the existing test_parallelogram.py?
| ( | ||
| "M", | ||
| [ | ||
| 10284813 / 9015625, |
There was a problem hiding this comment.
could you please also document the elementary expressions, i.e. 1.1/(1+0.1×47/72)?
| @@ -0,0 +1,47 @@ | |||
| import numpy as np | |||
There was a problem hiding this comment.
can you please put these tests inside the existing test_parallelogram.py?
Address review on casact#1491: the off-grid tests and the documented rate-history reference test now live in the existing test_parallelogram.py, and the two separate files are removed. The expected on-level factors of the documented example are written as elementary parallelogram areas, e.g. 2020 monthly is L4 / (L3 * _tri(10, 12) + L4 * (1 - _tri(10, 12))) = 1.1/(1+0.1*47/72), with a comment per year naming which writings are at which rate level and the exact rational value. No source change. Co-authored-by: Xamit Kadirbekov <kadyrbekovkhamit@gmail.com> Co-authored-by: Daniyal Kadirbekov <daniyal.kadirbekov@gmail.com> Signed-off-by: kadyrbekovhamit-cyber <288885044+kadyrbekovhamit-cyber@users.noreply.github.com>
|
@henrydingliu thanks for the review. Pushed 671c87e:
Local run (Python 3.12, pandas 3.1.0, numpy 2.5.4): No change to the source fix. |

Summary of Changes
With the default monthly approximation, an incremental rate change dated between month starts is dropped completely. A +20% change on 2001-07-15 produces an on-level factor of 1.0 for the wholly earlier 2000 year, instead of 1.2.
The current incremental branch reindexes changes to month starts using exact matches, losing off-grid dates. This patch compounds the changes on their original dates, then selects the latest effective level at each grid point, matching the as-of convention already used in the cumulative branch. Before the first change the level is 1.
Minimal public-API example (main 90c7b35):
For an entirely old-rate year, current rate / old rate = 1.20 / 1.00 independently gives 1.2. Monthly approximation is still monthly: a July 15 change first affects the August 1 grid point. This patch does not claim exact daily geometry in monthly mode.
The two off-grid tests fail before the source patch. An additional documented-history test pins independent rational references under the explicit monthly and daily conventions: monthly fails on the original base, daily is a passing control. With the fix, the selected suite has 128 passed, 1 skipped:
Tests compare the off-grid input to its next-month grid equivalent and compare incremental/cumulative histories through public
ParallelogramOLFfor monthly/daily grain and both vertical-line modes. Existing approximation and policy-length tests are retained. The full project suite was not run; dependency warnings remain. Local repository-wide Ruff 0.16.1 lint and format checks pass (198 files). The historical-reference derivation and explicit calendar assumptions are documented in #1491 (comment); the numerical algorithm remains limited to the off-grid fix.Related GitHub Issue(s)
Closes #1492. Related prior work: #1181 added cumulative histories with as-of matching, but retained exact reindexing for incremental histories. #524 concerns origin-grain/leap-year handling and #686 policy length. This patch concerns off-grid incremental effective dates.
AI/LLM Usage
This submission is initiated at the explicit request of the human account owner. OpenAI Codex assisted with the code, tests, reproduction, prior-art search and this description. The tests above were actually run locally, sequentially on CPU. Independent human code review and human authorship of this form have not been established, so the human-authorship and full-governance-compliance boxes below are intentionally left unchecked. The owner requested submission unchanged after being informed of these requirements. Please advise if this contribution needs a different process; no exemption or human-review claim is implied.
Additional Context for Reviewers
Small synthetic reproduction; no production insurance data or measured financial-loss claim. AI-assisted investigation credited to Xamit Kadirbekov and Daniyal Kadirbekov. Maintainer acceptance and independent review are pending.
Submitter's Checklist
[FIX],[FEAT],[DOCS],[TST],[CHORE], or[BRK]).Reviewer's Checklist