tieback 0.2.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- tieback-0.2.0/.github/workflows/ci.yml +15 -0
- tieback-0.2.0/.github/workflows/publish.yml +38 -0
- tieback-0.2.0/.gitignore +8 -0
- tieback-0.2.0/LICENSE +202 -0
- tieback-0.2.0/PKG-INFO +158 -0
- tieback-0.2.0/README.md +134 -0
- tieback-0.2.0/pyproject.toml +36 -0
- tieback-0.2.0/src/tieback/__init__.py +49 -0
- tieback-0.2.0/src/tieback/checks.py +281 -0
- tieback-0.2.0/src/tieback/cli.py +80 -0
- tieback-0.2.0/src/tieback/demo.py +281 -0
- tieback-0.2.0/src/tieback/keys.py +567 -0
- tieback-0.2.0/src/tieback/plan.py +891 -0
- tieback-0.2.0/src/tieback/repair.py +277 -0
- tieback-0.2.0/src/tieback/report.py +148 -0
- tieback-0.2.0/tests/test_keys.py +326 -0
- tieback-0.2.0/tests/test_messy.py +175 -0
- tieback-0.2.0/tests/test_plan.py +163 -0
- tieback-0.2.0/tests/test_report.py +60 -0
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
name: tests
|
|
2
|
+
on: [push, pull_request]
|
|
3
|
+
jobs:
|
|
4
|
+
test:
|
|
5
|
+
runs-on: ubuntu-latest
|
|
6
|
+
strategy:
|
|
7
|
+
matrix:
|
|
8
|
+
python: ["3.10", "3.11", "3.12", "3.13"]
|
|
9
|
+
steps:
|
|
10
|
+
- uses: actions/checkout@v4
|
|
11
|
+
- uses: actions/setup-python@v5
|
|
12
|
+
with:
|
|
13
|
+
python-version: ${{ matrix.python }}
|
|
14
|
+
- run: pip install -e ".[dev]"
|
|
15
|
+
- run: pytest -q
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
name: publish
|
|
2
|
+
# Tag a release (git tag v0.2.0 && git push --tags) and this builds the
|
|
3
|
+
# package, runs the tests, and uploads to PyPI through Trusted Publishing:
|
|
4
|
+
# PyPI trusts this workflow directly, so no token is stored anywhere.
|
|
5
|
+
on:
|
|
6
|
+
push:
|
|
7
|
+
tags: ["v*"]
|
|
8
|
+
jobs:
|
|
9
|
+
build:
|
|
10
|
+
runs-on: ubuntu-latest
|
|
11
|
+
steps:
|
|
12
|
+
- uses: actions/checkout@v4
|
|
13
|
+
- uses: actions/setup-python@v5
|
|
14
|
+
with:
|
|
15
|
+
python-version: "3.12"
|
|
16
|
+
- name: Check the tag matches the version
|
|
17
|
+
run: |
|
|
18
|
+
v=$(python -c "import tomllib;print(tomllib.load(open('pyproject.toml','rb'))['project']['version'])")
|
|
19
|
+
test "v$v" = "${GITHUB_REF_NAME}" || { echo "tag ${GITHUB_REF_NAME} != version $v"; exit 1; }
|
|
20
|
+
- run: pip install -e ".[dev]" build
|
|
21
|
+
- run: pytest -q
|
|
22
|
+
- run: python -m build
|
|
23
|
+
- uses: actions/upload-artifact@v4
|
|
24
|
+
with:
|
|
25
|
+
name: dist
|
|
26
|
+
path: dist/
|
|
27
|
+
pypi:
|
|
28
|
+
needs: build
|
|
29
|
+
runs-on: ubuntu-latest
|
|
30
|
+
environment: pypi
|
|
31
|
+
permissions:
|
|
32
|
+
id-token: write
|
|
33
|
+
steps:
|
|
34
|
+
- uses: actions/download-artifact@v4
|
|
35
|
+
with:
|
|
36
|
+
name: dist
|
|
37
|
+
path: dist/
|
|
38
|
+
- uses: pypa/gh-action-pypi-publish@release/v1
|
tieback-0.2.0/.gitignore
ADDED
tieback-0.2.0/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
tieback-0.2.0/PKG-INFO
ADDED
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: tieback
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: Reconcile insurance extracts: join any number of files, correct mistyped keys, find what is wrong, and prove the result ties back to the totals.
|
|
5
|
+
Project-URL: Homepage, https://actuariallabs.com
|
|
6
|
+
Project-URL: Source, https://github.com/actuariallabs/tieback
|
|
7
|
+
Project-URL: Issues, https://github.com/actuariallabs/tieback/issues
|
|
8
|
+
Author: Actuarial Labs
|
|
9
|
+
License-Expression: Apache-2.0
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Keywords: actuarial,data-quality,insurance,polars,pricing,reconciliation
|
|
12
|
+
Classifier: Development Status :: 3 - Alpha
|
|
13
|
+
Classifier: Intended Audience :: Financial and Insurance Industry
|
|
14
|
+
Classifier: Intended Audience :: Science/Research
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Topic :: Office/Business :: Financial
|
|
17
|
+
Classifier: Topic :: Scientific/Engineering :: Information Analysis
|
|
18
|
+
Requires-Python: >=3.10
|
|
19
|
+
Requires-Dist: numpy>=1.24
|
|
20
|
+
Requires-Dist: polars>=1.0
|
|
21
|
+
Provides-Extra: dev
|
|
22
|
+
Requires-Dist: pytest>=8; extra == 'dev'
|
|
23
|
+
Description-Content-Type: text/markdown
|
|
24
|
+
|
|
25
|
+
# tieback
|
|
26
|
+
|
|
27
|
+
**Reconcile insurance extracts. Join any number of files, correct the mistyped keys the data can vouch for, find everything else that is wrong, and prove the result ties back to the totals.**
|
|
28
|
+
|
|
29
|
+
A pricing or reserving project never starts with one clean file. It starts with five, from systems that were never designed to meet:
|
|
30
|
+
|
|
31
|
+
| Extract | Grain | The policy is called |
|
|
32
|
+
|---|---|---|
|
|
33
|
+
| Policy admin | one row per policy **term** | `ON-0482113` |
|
|
34
|
+
| Vehicle schedule | one row per vehicle per term, with the exposure | `482113` |
|
|
35
|
+
| Claims | one row per claim per **coverage**, a loss date, no term | `P0482113` |
|
|
36
|
+
| Finance premium | one row per policy term | `0482113/1` |
|
|
37
|
+
| Driver convictions | one row per conviction, per **policy**, dated | `0482113` |
|
|
38
|
+
|
|
39
|
+
And the files are wrong in the ways real files are wrong: a policy number typed `P0428113`, a vehicle exported twice, a region spelt `Toronto`, `TORONTO` and `Otawa`, a claim reported before it happened, paid above incurred, exposure longer than the term.
|
|
40
|
+
|
|
41
|
+
Join them naively and every one of those moves a rate without ever showing up as an error. `tieback` joins them, says what it did and why, and lists what is wrong with the numbers it affects.
|
|
42
|
+
|
|
43
|
+
```
|
|
44
|
+
$ pip install tieback
|
|
45
|
+
$ tieback demo sample # five extracts with the problems real ones have
|
|
46
|
+
$ tieback sample/*.csv -o book.parquet --plan plan.json --findings findings.json
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
```
|
|
50
|
+
base: vehicles.csv (22,067 rows), exposure EARNED_CAR_YRS
|
|
51
|
+
|
|
52
|
+
claims.csv [rollup] on POLICY_REF = POL_NUM + VEHICLE = UNIT_NO, LOSS_DATE within [TERM_START, TERM_EXP)
|
|
53
|
+
POLICY_REF ↔ POL_NUM: 'P0123423' and '123423' are the same policy once the prefix and leading zeros are dropped.
|
|
54
|
+
claims has no term, only dates: LOSS_DATE between TERM_START and TERM_EXP places each row in one term.
|
|
55
|
+
7 mistyped key values corrected first (9 rows). Chance check: a key that is missing, not mistyped,
|
|
56
|
+
finds a convincing near match 0.5% of the time on this book, so about 0.2 of them could be wrong.
|
|
57
|
+
CLAIM_NO: 2,144 in file = 2,074 attached + 35 no matching key + 35 outside every term + 0 ambiguous ok
|
|
58
|
+
INCURRED: 31,394,525 in file = 30,315,213 in table + 1,079,312 unattached ok
|
|
59
|
+
|
|
60
|
+
premium.csv [per group] on GL_POLICY_TERM (part 1) = POL_NUM + BOOKED_FROM = TERM_START
|
|
61
|
+
Each row belongs to a group of 1.49 vehicles rows on average (the rows sharing POL_NUM and TERM_START).
|
|
62
|
+
Split across each group's rows by EARNED_CAR_YRS, so the total still ties: WRITTEN_PREMIUM.
|
|
63
|
+
WRITTEN_PREMIUM: 29,034,341 in file = 29,013,424 in table + 20,917 unattached ok
|
|
64
|
+
|
|
65
|
+
exposure: 21,125 in, 21,125 out ok
|
|
66
|
+
|
|
67
|
+
findings: 4 errors, 9 to review, 10 fixed
|
|
68
|
+
ERROR claims.csv has 4 rows that repeat another row exactly.
|
|
69
|
+
affects INCURRED 52,299, PAID 33,787
|
|
70
|
+
ERROR 3 vehicles.csv rows overlap an earlier period of the same POL_NUM and UNIT_NO: exposure counted twice.
|
|
71
|
+
ERROR 2 vehicles.csv rows carry more EARNED_CAR_YRS than their period is long.
|
|
72
|
+
REVIEW policies.csv.REGION spells 2 values two ways: 'TORONTO' (20) looks like 'Toronto' (3,182); 'Otawa' (5) looks like 'Ottawa' (1,711).
|
|
73
|
+
REVIEW 6 claims.csv rows have PAID above INCURRED.
|
|
74
|
+
REVIEW 3 claims.csv rows were reported before the loss happened (REPORTED_DATE < LOSS_DATE).
|
|
75
|
+
REVIEW claims.csv.POLICY_REF: 8 values match nothing but sit one character from a real key whose other columns
|
|
76
|
+
and dates fit, and only that one. Not applied: a policy missing from the extract can sit one digit from a real one by chance.
|
|
77
|
+
FIXED claims.csv.POLICY_REF: 'P9016838' read as 'P0916838' (swapped neighbours; its other keys and dates match only this one).
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
That is real output on the sample book (trimmed). Five files, 22,000 exposure rows, about two seconds.
|
|
81
|
+
|
|
82
|
+
## What it does
|
|
83
|
+
|
|
84
|
+
**Joins any number of files.** It starts from the file that carries exposure and attaches every other one, in the order the data allows:
|
|
85
|
+
|
|
86
|
+
- **Keys from values, not names.** `POLICY_NO` and `POL_NUM` join because their values overlap. `ON-0482113`, `482113` and `P0482113` are recognised as the same policy.
|
|
87
|
+
- **Two numbers in one id.** `0482113/1` is split into policy and term, and each part is matched.
|
|
88
|
+
- **Refines until each row has one partner.** Renewals repeat the policy number, so the key is narrowed by another column, then by a date window: a loss belongs to the term it falls inside.
|
|
89
|
+
- **Three ways to attach.** Attributes look up one row each. Events (claims) roll up, counted once per claim id, amounts summed. Events at a coarser grain than the exposure (convictions per policy term, premium per term) attach to the whole group: counts as a per-group attribute, money split across the group by exposure so it still adds up to the file.
|
|
90
|
+
|
|
91
|
+
**Corrects mistyped keys, and tells you how far to trust it.** For each key that matches nothing it looks for real keys one keystroke away, of three kinds: case and spacing, swapped neighbours, one changed character.
|
|
92
|
+
|
|
93
|
+
- A candidate counts only if the rest of the row vouches for it: with the corrected number, the claim's vehicle and loss date fall in exactly one term. If two candidates fit, nothing is changed.
|
|
94
|
+
- Case, spacing and swapped neighbours are applied by default. A single changed character is listed as a likely correction and applied only with `--repair all`, because a policy simply missing from the extract often sits one digit from a real one.
|
|
95
|
+
- **The chance check.** `tieback` gives real rows random keys that exist nowhere and counts how often they would still be "corrected". That rate, on your own book, becomes the expected number of wrong corrections, printed next to the corrections. If it is too high, none are applied.
|
|
96
|
+
- A key that appears in another of your files is a real policy missing from this one, not a typo, and is left alone.
|
|
97
|
+
|
|
98
|
+
**Finds what else is wrong**, with what it does to the numbers:
|
|
99
|
+
|
|
100
|
+
| Check | Why it matters |
|
|
101
|
+
|---|---|
|
|
102
|
+
| Rows exported twice | Double exposure or double losses |
|
|
103
|
+
| Overlapping periods for the same unit | Exposure counted twice |
|
|
104
|
+
| Exposure longer than its period | Inflated exposure |
|
|
105
|
+
| Periods that end before they start | Broken terms |
|
|
106
|
+
| Negative amounts | Sign errors, or recoveries to treat on purpose |
|
|
107
|
+
| Paid above incurred | Stale reserves or mis-keyed amounts |
|
|
108
|
+
| Reported before the loss date | Swapped dates that move a claim to the wrong term |
|
|
109
|
+
| One category spelt several ways | Each spelling becomes its own rating level |
|
|
110
|
+
| Fields that disagree between files | Which system is the source of truth |
|
|
111
|
+
| Events with no exposure to sit on | Losses outside the book |
|
|
112
|
+
| Totals that do not tie to finance | `--control EARNED_CAR_YRS=21130` |
|
|
113
|
+
|
|
114
|
+
**Accounts for everything.** Base rows and exposure are unchanged. Every claim and every dollar is in the table or listed as unattached, with its reason.
|
|
115
|
+
|
|
116
|
+
**Saves its decisions.** The plan is JSON: keys, windows and every correction. Replay it on next quarter's extracts with `tieback --replay plan.json` and it lists every row that did not make it in.
|
|
117
|
+
|
|
118
|
+
## In Python
|
|
119
|
+
|
|
120
|
+
```python
|
|
121
|
+
import tieback
|
|
122
|
+
|
|
123
|
+
tables = tieback.read(["policies.csv", "vehicles.csv", "claims.csv", "premium.csv", "convictions.csv"])
|
|
124
|
+
book, plan = tieback.assemble(tables, controls={"EARNED_CAR_YRS": 21_130})
|
|
125
|
+
print(tieback.report(plan))
|
|
126
|
+
|
|
127
|
+
for f in plan.findings: # dicts: check, severity, table, column, count, impact, examples, action
|
|
128
|
+
if f["severity"] == "error":
|
|
129
|
+
print(f["message"])
|
|
130
|
+
|
|
131
|
+
tieback.save_plan(plan, "plan.json")
|
|
132
|
+
result = tieback.replay(next_quarter_tables, tieback.load_plan("plan.json"))
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
Options: `repair=False` changes no key, `repair="all"` also applies single-character corrections, `exposure_hints={"vehicles.csv": "EARNED_CAR_YRS"}` names the exposure column if it is not detected.
|
|
136
|
+
|
|
137
|
+
## What it does not do
|
|
138
|
+
|
|
139
|
+
- It does not guess. Ambiguous keys, ambiguous rows and tables it cannot join are listed with the reason, never forced.
|
|
140
|
+
- It does not change your rating variables. Misspelt categories are reported with the mapping to use; applying it is your call.
|
|
141
|
+
- It does not decide what to do with orphan claims. Whether losses with no exposure are kept or dropped is an actuarial judgment.
|
|
142
|
+
- It does not send anything anywhere. No network, no telemetry. Polars and NumPy on your machine.
|
|
143
|
+
|
|
144
|
+
## How we test it
|
|
145
|
+
|
|
146
|
+
The demo book is generated with every problem above planted, and the tests check `tieback` against what was planted, not against its own report. Over four random books with about 50 planted typos: every typo in the exposure file and 26 of 32 swapped digits in the claims file were corrected, and 2 of 38 applied corrections were wrong. Both were claims on missing policies that sat, by chance, one swap from a real one whose vehicle and dates fit. The chance check estimated about one per book on those books.
|
|
147
|
+
|
|
148
|
+
On a book ten times denser (60,000 policies), coincidences are common (12.5%), and `tieback` declined to correct and listed the candidates instead. That is the intended behaviour: on dense numbering, keys and dates alone cannot vouch for a correction.
|
|
149
|
+
|
|
150
|
+
## Status
|
|
151
|
+
|
|
152
|
+
Version 0.2, alpha. The API may change before 1.0. CI runs on Python 3.10 to 3.13. About 10 seconds for five files and 380,000 rows on a laptop. If it gets a join wrong on your data, an issue describing the column shapes (not the data) is the most useful thing you can send.
|
|
153
|
+
|
|
154
|
+
## Who made this
|
|
155
|
+
|
|
156
|
+
[Actuarial Labs](https://actuariallabs.com) is an actuarial science research lab. `tieback` is the reconciliation step from Pia, our Chief AI Actuary, released on its own because every pricing, reserving and data team needs it.
|
|
157
|
+
|
|
158
|
+
Apache 2.0.
|
tieback-0.2.0/README.md
ADDED
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
# tieback
|
|
2
|
+
|
|
3
|
+
**Reconcile insurance extracts. Join any number of files, correct the mistyped keys the data can vouch for, find everything else that is wrong, and prove the result ties back to the totals.**
|
|
4
|
+
|
|
5
|
+
A pricing or reserving project never starts with one clean file. It starts with five, from systems that were never designed to meet:
|
|
6
|
+
|
|
7
|
+
| Extract | Grain | The policy is called |
|
|
8
|
+
|---|---|---|
|
|
9
|
+
| Policy admin | one row per policy **term** | `ON-0482113` |
|
|
10
|
+
| Vehicle schedule | one row per vehicle per term, with the exposure | `482113` |
|
|
11
|
+
| Claims | one row per claim per **coverage**, a loss date, no term | `P0482113` |
|
|
12
|
+
| Finance premium | one row per policy term | `0482113/1` |
|
|
13
|
+
| Driver convictions | one row per conviction, per **policy**, dated | `0482113` |
|
|
14
|
+
|
|
15
|
+
And the files are wrong in the ways real files are wrong: a policy number typed `P0428113`, a vehicle exported twice, a region spelt `Toronto`, `TORONTO` and `Otawa`, a claim reported before it happened, paid above incurred, exposure longer than the term.
|
|
16
|
+
|
|
17
|
+
Join them naively and every one of those moves a rate without ever showing up as an error. `tieback` joins them, says what it did and why, and lists what is wrong with the numbers it affects.
|
|
18
|
+
|
|
19
|
+
```
|
|
20
|
+
$ pip install tieback
|
|
21
|
+
$ tieback demo sample # five extracts with the problems real ones have
|
|
22
|
+
$ tieback sample/*.csv -o book.parquet --plan plan.json --findings findings.json
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
```
|
|
26
|
+
base: vehicles.csv (22,067 rows), exposure EARNED_CAR_YRS
|
|
27
|
+
|
|
28
|
+
claims.csv [rollup] on POLICY_REF = POL_NUM + VEHICLE = UNIT_NO, LOSS_DATE within [TERM_START, TERM_EXP)
|
|
29
|
+
POLICY_REF ↔ POL_NUM: 'P0123423' and '123423' are the same policy once the prefix and leading zeros are dropped.
|
|
30
|
+
claims has no term, only dates: LOSS_DATE between TERM_START and TERM_EXP places each row in one term.
|
|
31
|
+
7 mistyped key values corrected first (9 rows). Chance check: a key that is missing, not mistyped,
|
|
32
|
+
finds a convincing near match 0.5% of the time on this book, so about 0.2 of them could be wrong.
|
|
33
|
+
CLAIM_NO: 2,144 in file = 2,074 attached + 35 no matching key + 35 outside every term + 0 ambiguous ok
|
|
34
|
+
INCURRED: 31,394,525 in file = 30,315,213 in table + 1,079,312 unattached ok
|
|
35
|
+
|
|
36
|
+
premium.csv [per group] on GL_POLICY_TERM (part 1) = POL_NUM + BOOKED_FROM = TERM_START
|
|
37
|
+
Each row belongs to a group of 1.49 vehicles rows on average (the rows sharing POL_NUM and TERM_START).
|
|
38
|
+
Split across each group's rows by EARNED_CAR_YRS, so the total still ties: WRITTEN_PREMIUM.
|
|
39
|
+
WRITTEN_PREMIUM: 29,034,341 in file = 29,013,424 in table + 20,917 unattached ok
|
|
40
|
+
|
|
41
|
+
exposure: 21,125 in, 21,125 out ok
|
|
42
|
+
|
|
43
|
+
findings: 4 errors, 9 to review, 10 fixed
|
|
44
|
+
ERROR claims.csv has 4 rows that repeat another row exactly.
|
|
45
|
+
affects INCURRED 52,299, PAID 33,787
|
|
46
|
+
ERROR 3 vehicles.csv rows overlap an earlier period of the same POL_NUM and UNIT_NO: exposure counted twice.
|
|
47
|
+
ERROR 2 vehicles.csv rows carry more EARNED_CAR_YRS than their period is long.
|
|
48
|
+
REVIEW policies.csv.REGION spells 2 values two ways: 'TORONTO' (20) looks like 'Toronto' (3,182); 'Otawa' (5) looks like 'Ottawa' (1,711).
|
|
49
|
+
REVIEW 6 claims.csv rows have PAID above INCURRED.
|
|
50
|
+
REVIEW 3 claims.csv rows were reported before the loss happened (REPORTED_DATE < LOSS_DATE).
|
|
51
|
+
REVIEW claims.csv.POLICY_REF: 8 values match nothing but sit one character from a real key whose other columns
|
|
52
|
+
and dates fit, and only that one. Not applied: a policy missing from the extract can sit one digit from a real one by chance.
|
|
53
|
+
FIXED claims.csv.POLICY_REF: 'P9016838' read as 'P0916838' (swapped neighbours; its other keys and dates match only this one).
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
That is real output on the sample book (trimmed). Five files, 22,000 exposure rows, about two seconds.
|
|
57
|
+
|
|
58
|
+
## What it does
|
|
59
|
+
|
|
60
|
+
**Joins any number of files.** It starts from the file that carries exposure and attaches every other one, in the order the data allows:
|
|
61
|
+
|
|
62
|
+
- **Keys from values, not names.** `POLICY_NO` and `POL_NUM` join because their values overlap. `ON-0482113`, `482113` and `P0482113` are recognised as the same policy.
|
|
63
|
+
- **Two numbers in one id.** `0482113/1` is split into policy and term, and each part is matched.
|
|
64
|
+
- **Refines until each row has one partner.** Renewals repeat the policy number, so the key is narrowed by another column, then by a date window: a loss belongs to the term it falls inside.
|
|
65
|
+
- **Three ways to attach.** Attributes look up one row each. Events (claims) roll up, counted once per claim id, amounts summed. Events at a coarser grain than the exposure (convictions per policy term, premium per term) attach to the whole group: counts as a per-group attribute, money split across the group by exposure so it still adds up to the file.
|
|
66
|
+
|
|
67
|
+
**Corrects mistyped keys, and tells you how far to trust it.** For each key that matches nothing it looks for real keys one keystroke away, of three kinds: case and spacing, swapped neighbours, one changed character.
|
|
68
|
+
|
|
69
|
+
- A candidate counts only if the rest of the row vouches for it: with the corrected number, the claim's vehicle and loss date fall in exactly one term. If two candidates fit, nothing is changed.
|
|
70
|
+
- Case, spacing and swapped neighbours are applied by default. A single changed character is listed as a likely correction and applied only with `--repair all`, because a policy simply missing from the extract often sits one digit from a real one.
|
|
71
|
+
- **The chance check.** `tieback` gives real rows random keys that exist nowhere and counts how often they would still be "corrected". That rate, on your own book, becomes the expected number of wrong corrections, printed next to the corrections. If it is too high, none are applied.
|
|
72
|
+
- A key that appears in another of your files is a real policy missing from this one, not a typo, and is left alone.
|
|
73
|
+
|
|
74
|
+
**Finds what else is wrong**, with what it does to the numbers:
|
|
75
|
+
|
|
76
|
+
| Check | Why it matters |
|
|
77
|
+
|---|---|
|
|
78
|
+
| Rows exported twice | Double exposure or double losses |
|
|
79
|
+
| Overlapping periods for the same unit | Exposure counted twice |
|
|
80
|
+
| Exposure longer than its period | Inflated exposure |
|
|
81
|
+
| Periods that end before they start | Broken terms |
|
|
82
|
+
| Negative amounts | Sign errors, or recoveries to treat on purpose |
|
|
83
|
+
| Paid above incurred | Stale reserves or mis-keyed amounts |
|
|
84
|
+
| Reported before the loss date | Swapped dates that move a claim to the wrong term |
|
|
85
|
+
| One category spelt several ways | Each spelling becomes its own rating level |
|
|
86
|
+
| Fields that disagree between files | Which system is the source of truth |
|
|
87
|
+
| Events with no exposure to sit on | Losses outside the book |
|
|
88
|
+
| Totals that do not tie to finance | `--control EARNED_CAR_YRS=21130` |
|
|
89
|
+
|
|
90
|
+
**Accounts for everything.** Base rows and exposure are unchanged. Every claim and every dollar is in the table or listed as unattached, with its reason.
|
|
91
|
+
|
|
92
|
+
**Saves its decisions.** The plan is JSON: keys, windows and every correction. Replay it on next quarter's extracts with `tieback --replay plan.json` and it lists every row that did not make it in.
|
|
93
|
+
|
|
94
|
+
## In Python
|
|
95
|
+
|
|
96
|
+
```python
|
|
97
|
+
import tieback
|
|
98
|
+
|
|
99
|
+
tables = tieback.read(["policies.csv", "vehicles.csv", "claims.csv", "premium.csv", "convictions.csv"])
|
|
100
|
+
book, plan = tieback.assemble(tables, controls={"EARNED_CAR_YRS": 21_130})
|
|
101
|
+
print(tieback.report(plan))
|
|
102
|
+
|
|
103
|
+
for f in plan.findings: # dicts: check, severity, table, column, count, impact, examples, action
|
|
104
|
+
if f["severity"] == "error":
|
|
105
|
+
print(f["message"])
|
|
106
|
+
|
|
107
|
+
tieback.save_plan(plan, "plan.json")
|
|
108
|
+
result = tieback.replay(next_quarter_tables, tieback.load_plan("plan.json"))
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
Options: `repair=False` changes no key, `repair="all"` also applies single-character corrections, `exposure_hints={"vehicles.csv": "EARNED_CAR_YRS"}` names the exposure column if it is not detected.
|
|
112
|
+
|
|
113
|
+
## What it does not do
|
|
114
|
+
|
|
115
|
+
- It does not guess. Ambiguous keys, ambiguous rows and tables it cannot join are listed with the reason, never forced.
|
|
116
|
+
- It does not change your rating variables. Misspelt categories are reported with the mapping to use; applying it is your call.
|
|
117
|
+
- It does not decide what to do with orphan claims. Whether losses with no exposure are kept or dropped is an actuarial judgment.
|
|
118
|
+
- It does not send anything anywhere. No network, no telemetry. Polars and NumPy on your machine.
|
|
119
|
+
|
|
120
|
+
## How we test it
|
|
121
|
+
|
|
122
|
+
The demo book is generated with every problem above planted, and the tests check `tieback` against what was planted, not against its own report. Over four random books with about 50 planted typos: every typo in the exposure file and 26 of 32 swapped digits in the claims file were corrected, and 2 of 38 applied corrections were wrong. Both were claims on missing policies that sat, by chance, one swap from a real one whose vehicle and dates fit. The chance check estimated about one per book on those books.
|
|
123
|
+
|
|
124
|
+
On a book ten times denser (60,000 policies), coincidences are common (12.5%), and `tieback` declined to correct and listed the candidates instead. That is the intended behaviour: on dense numbering, keys and dates alone cannot vouch for a correction.
|
|
125
|
+
|
|
126
|
+
## Status
|
|
127
|
+
|
|
128
|
+
Version 0.2, alpha. The API may change before 1.0. CI runs on Python 3.10 to 3.13. About 10 seconds for five files and 380,000 rows on a laptop. If it gets a join wrong on your data, an issue describing the column shapes (not the data) is the most useful thing you can send.
|
|
129
|
+
|
|
130
|
+
## Who made this
|
|
131
|
+
|
|
132
|
+
[Actuarial Labs](https://actuariallabs.com) is an actuarial science research lab. `tieback` is the reconciliation step from Pia, our Chief AI Actuary, released on its own because every pricing, reserving and data team needs it.
|
|
133
|
+
|
|
134
|
+
Apache 2.0.
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling>=1.24"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "tieback"
|
|
7
|
+
version = "0.2.0"
|
|
8
|
+
description = "Reconcile insurance extracts: join any number of files, correct mistyped keys, find what is wrong, and prove the result ties back to the totals."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = "Apache-2.0"
|
|
11
|
+
requires-python = ">=3.10"
|
|
12
|
+
authors = [{ name = "Actuarial Labs" }]
|
|
13
|
+
keywords = ["insurance", "actuarial", "reconciliation", "data-quality", "polars", "pricing"]
|
|
14
|
+
classifiers = [
|
|
15
|
+
"Development Status :: 3 - Alpha",
|
|
16
|
+
"Intended Audience :: Financial and Insurance Industry",
|
|
17
|
+
"Intended Audience :: Science/Research",
|
|
18
|
+
"Programming Language :: Python :: 3",
|
|
19
|
+
"Topic :: Office/Business :: Financial",
|
|
20
|
+
"Topic :: Scientific/Engineering :: Information Analysis",
|
|
21
|
+
]
|
|
22
|
+
dependencies = ["polars>=1.0", "numpy>=1.24"]
|
|
23
|
+
|
|
24
|
+
[project.optional-dependencies]
|
|
25
|
+
dev = ["pytest>=8"]
|
|
26
|
+
|
|
27
|
+
[project.scripts]
|
|
28
|
+
tieback = "tieback.cli:main"
|
|
29
|
+
|
|
30
|
+
[project.urls]
|
|
31
|
+
Homepage = "https://actuariallabs.com"
|
|
32
|
+
Source = "https://github.com/actuariallabs/tieback"
|
|
33
|
+
Issues = "https://github.com/actuariallabs/tieback/issues"
|
|
34
|
+
|
|
35
|
+
[tool.pytest.ini_options]
|
|
36
|
+
testpaths = ["tests"]
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"""tieback: join insurance extracts that were never meant to be joined, and
|
|
2
|
+
prove the result ties back to the totals.
|
|
3
|
+
|
|
4
|
+
import tieback
|
|
5
|
+
tables = tieback.read(["policies.csv", "vehicles.csv", "claims.csv"])
|
|
6
|
+
book, plan = tieback.assemble(tables)
|
|
7
|
+
print(tieback.report(plan))
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
from __future__ import annotations
|
|
11
|
+
|
|
12
|
+
from pathlib import Path
|
|
13
|
+
|
|
14
|
+
import polars as pl
|
|
15
|
+
|
|
16
|
+
from tieback.keys import (
|
|
17
|
+
JoinCandidate,
|
|
18
|
+
JoinDiagnostics,
|
|
19
|
+
JoinSpec,
|
|
20
|
+
ReconciliationResult,
|
|
21
|
+
detect_join_keys,
|
|
22
|
+
execute_join,
|
|
23
|
+
normalize_key,
|
|
24
|
+
)
|
|
25
|
+
from tieback.plan import KeyPair, Plan, Step, Window, assemble, parse_dates, replay
|
|
26
|
+
from tieback.report import TieOut, check_total, load_plan, report, save_plan
|
|
27
|
+
|
|
28
|
+
__version__ = "0.2.0"
|
|
29
|
+
|
|
30
|
+
__all__ = [
|
|
31
|
+
"JoinCandidate", "JoinDiagnostics", "JoinSpec", "KeyPair", "Plan", "ReconciliationResult", "Step",
|
|
32
|
+
"TieOut", "Window", "assemble", "check_total", "detect_join_keys", "execute_join", "load_plan",
|
|
33
|
+
"normalize_key", "parse_dates", "read", "replay", "report", "save_plan",
|
|
34
|
+
]
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def read(paths: list[str | Path]) -> dict[str, pl.DataFrame]:
|
|
38
|
+
"""Read CSV or Parquet files into the {name: frame} mapping `assemble` takes.
|
|
39
|
+
Text dates are parsed later, by the plan. Ids that differ only by a prefix
|
|
40
|
+
or leading zeros ('ON-0482113' and 482113) are matched by the plan too."""
|
|
41
|
+
out: dict[str, pl.DataFrame] = {}
|
|
42
|
+
for p in map(Path, paths):
|
|
43
|
+
if p.name in out:
|
|
44
|
+
raise ValueError(f"Two files are named {p.name}; rename one.")
|
|
45
|
+
if p.suffix.lower() == ".parquet":
|
|
46
|
+
out[p.name] = pl.read_parquet(p)
|
|
47
|
+
else:
|
|
48
|
+
out[p.name] = pl.read_csv(p, infer_schema_length=10_000)
|
|
49
|
+
return out
|