open-rating-engine 0.1.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.
Files changed (44) hide show
  1. open_rating_engine-0.1.0/LICENSE +201 -0
  2. open_rating_engine-0.1.0/PKG-INFO +144 -0
  3. open_rating_engine-0.1.0/README.md +105 -0
  4. open_rating_engine-0.1.0/pyproject.toml +79 -0
  5. open_rating_engine-0.1.0/setup.cfg +4 -0
  6. open_rating_engine-0.1.0/src/open_rating_engine/__init__.py +67 -0
  7. open_rating_engine-0.1.0/src/open_rating_engine/_lazy.py +58 -0
  8. open_rating_engine-0.1.0/src/open_rating_engine/data_processing/__init__.py +13 -0
  9. open_rating_engine-0.1.0/src/open_rating_engine/data_processing/data_aging.py +96 -0
  10. open_rating_engine-0.1.0/src/open_rating_engine/optimization/__init__.py +35 -0
  11. open_rating_engine-0.1.0/src/open_rating_engine/optimization/_decision_space.py +419 -0
  12. open_rating_engine-0.1.0/src/open_rating_engine/optimization/_horizon_engine.py +729 -0
  13. open_rating_engine-0.1.0/src/open_rating_engine/optimization/individual_price_optimizer.py +236 -0
  14. open_rating_engine-0.1.0/src/open_rating_engine/optimization/multi_period_individual_price_optimizer.py +897 -0
  15. open_rating_engine-0.1.0/src/open_rating_engine/optimization/multi_period_rating_factor_price_optimizer.py +897 -0
  16. open_rating_engine-0.1.0/src/open_rating_engine/optimization/rating_factor_price_optimizer.py +366 -0
  17. open_rating_engine-0.1.0/src/open_rating_engine/optimization/simulate_adjustment_grid.py +188 -0
  18. open_rating_engine-0.1.0/src/open_rating_engine/rating_engine/__init__.py +51 -0
  19. open_rating_engine-0.1.0/src/open_rating_engine/rating_engine/binning.py +87 -0
  20. open_rating_engine-0.1.0/src/open_rating_engine/rating_engine/layer_registry.py +35 -0
  21. open_rating_engine-0.1.0/src/open_rating_engine/rating_engine/pricing_layers.py +2483 -0
  22. open_rating_engine-0.1.0/src/open_rating_engine/rating_engine/pricing_pipeline.py +859 -0
  23. open_rating_engine-0.1.0/src/open_rating_engine.egg-info/PKG-INFO +144 -0
  24. open_rating_engine-0.1.0/src/open_rating_engine.egg-info/SOURCES.txt +42 -0
  25. open_rating_engine-0.1.0/src/open_rating_engine.egg-info/dependency_links.txt +1 -0
  26. open_rating_engine-0.1.0/src/open_rating_engine.egg-info/requires.txt +29 -0
  27. open_rating_engine-0.1.0/src/open_rating_engine.egg-info/top_level.txt +1 -0
  28. open_rating_engine-0.1.0/tests/test_binning_thermometer.py +68 -0
  29. open_rating_engine-0.1.0/tests/test_data_aging.py +262 -0
  30. open_rating_engine-0.1.0/tests/test_multi_period_forward_sim.py +1177 -0
  31. open_rating_engine-0.1.0/tests/test_multi_period_individual.py +915 -0
  32. open_rating_engine-0.1.0/tests/test_multi_period_monte_carlo.py +212 -0
  33. open_rating_engine-0.1.0/tests/test_multi_period_optimizer.py +297 -0
  34. open_rating_engine-0.1.0/tests/test_optimization.py +31 -0
  35. open_rating_engine-0.1.0/tests/test_package_imports.py +79 -0
  36. open_rating_engine-0.1.0/tests/test_pipeline_h2o.py +178 -0
  37. open_rating_engine-0.1.0/tests/test_pipeline_onnx.py +125 -0
  38. open_rating_engine-0.1.0/tests/test_pipeline_serialization.py +115 -0
  39. open_rating_engine-0.1.0/tests/test_pricing_layers.py +834 -0
  40. open_rating_engine-0.1.0/tests/test_pricing_override_source.py +88 -0
  41. open_rating_engine-0.1.0/tests/test_pricing_pipeline.py +268 -0
  42. open_rating_engine-0.1.0/tests/test_pricing_pipeline_extra.py +144 -0
  43. open_rating_engine-0.1.0/tests/test_public_api.py +134 -0
  44. open_rating_engine-0.1.0/tests/test_rating_factor_optimizer.py +340 -0
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,144 @@
1
+ Metadata-Version: 2.4
2
+ Name: open-rating-engine
3
+ Version: 0.1.0
4
+ Summary: A DAG-based insurance/banking rating engine with price optimisation
5
+ Author-email: bhavek jamnadas <bhavek.jamnadas.actuary@gmail.com>
6
+ License-Expression: Apache-2.0
7
+ Project-URL: Homepage, https://github.com/bhavek-jamnadas/open-rating-engine
8
+ Project-URL: Issues, https://github.com/bhavek-jamnadas/open-rating-engine/issues
9
+ Keywords: actuarial,actuary,pricing,rating engine,price optimisation,insurance
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: Operating System :: OS Independent
12
+ Requires-Python: >=3.9
13
+ Description-Content-Type: text/markdown
14
+ License-File: LICENSE
15
+ Requires-Dist: numpy>=1.20
16
+ Requires-Dist: pandas<3
17
+ Requires-Dist: mlflow
18
+ Requires-Dist: tqdm
19
+ Requires-Dist: scipy
20
+ Requires-Dist: numba
21
+ Provides-Extra: h2o
22
+ Requires-Dist: h2o; extra == "h2o"
23
+ Requires-Dist: jpype1; extra == "h2o"
24
+ Provides-Extra: onnx
25
+ Requires-Dist: onnxruntime; extra == "onnx"
26
+ Provides-Extra: viz
27
+ Requires-Dist: plotly; extra == "viz"
28
+ Requires-Dist: networkx; extra == "viz"
29
+ Provides-Extra: notebook
30
+ Requires-Dist: ipywidgets; extra == "notebook"
31
+ Provides-Extra: all
32
+ Requires-Dist: open-rating-engine[h2o,notebook,onnx,viz]; extra == "all"
33
+ Provides-Extra: test
34
+ Requires-Dist: pytest>=8.0; extra == "test"
35
+ Requires-Dist: pytest-cov; extra == "test"
36
+ Requires-Dist: pytest-mock; extra == "test"
37
+ Requires-Dist: jpype1; extra == "test"
38
+ Dynamic: license-file
39
+
40
+ # open-rating-engine
41
+
42
+ An insurance/banking rating engine for Python. You describe a pricing algorithm as a set of
43
+ typed layers; the engine builds a dependency graph (DAG) from them and scores policies through
44
+ it. It also ships price optimisers that run on top of a pipeline.
45
+
46
+ A pipeline is an MLflow `PythonModel`, so you log, version, load and serve it with standard
47
+ MLflow tooling.
48
+
49
+ ## Install
50
+
51
+ ```bash
52
+ pip install open-rating-engine # core: pipeline, layers, optimisers
53
+ pip install "open-rating-engine[all]" # plus every optional extra
54
+ ```
55
+
56
+ | Extra | Adds | Needed for |
57
+ |---|---|---|
58
+ | `h2o` | `h2o`, `jpype1` | `H2OScoringParameter` (H2O MOJO scoring) |
59
+ | `onnx` | `onnxruntime` | `OnnxScoring` |
60
+ | `viz` | `plotly`, `networkx` | `PyfuncPricingPipeline.plot_dag()` |
61
+ | `notebook` | `ipywidgets` | optimiser progress bars in Jupyter |
62
+
63
+ Optional dependencies are imported lazily, so `import open_rating_engine` works on a core-only
64
+ install.
65
+
66
+ ## Imports
67
+
68
+ The headline names (the pipeline, every layer class, the layer exceptions and `apply_aging`) are
69
+ available from the top-level package. Everything else lives in its subpackage:
70
+
71
+ ```python
72
+ from open_rating_engine import PyfuncPricingPipeline, RatingTablesLayer, apply_aging
73
+ from open_rating_engine.optimization import PriceOptimizerRatingFactor
74
+ from open_rating_engine.rating_engine.binning import thermometer_column_names
75
+ ```
76
+
77
+ Package `__init__` modules load their names on first use, so `import open_rating_engine` is
78
+ near-instant. You pay for mlflow only when you touch the pipeline or a layer. Each module's
79
+ `__all__` defines its public API.
80
+
81
+ ## Rating engine
82
+
83
+ `PyfuncPricingPipeline` (`open_rating_engine.rating_engine.pricing_pipeline`):
84
+
85
+ - `add_parameter()` / `remove_parameter()` register and remove layers.
86
+ - Layers are topologically sorted, and cycles are reported. Independent column calculations run
87
+ in parallel waves. Structural layers (joins, drops, renames, aggregations) run in sequence so
88
+ that tables stay consistent.
89
+ - `predict(context, model_input)` is the MLflow-compatible scoring entry point.
90
+ - `load_context(context)` expects every artifact in `context.artifacts` to be a local file
91
+ path. The engine fetches nothing remote, so download artifacts from blob storage or a model
92
+ registry before building the context.
93
+ - `profile_predict()` returns how long each layer took. `plot_dag()` draws the graph.
94
+
95
+ Pipeline state is a dict of named DataFrames. Each layer declares what it reads (`depends_on`)
96
+ and what it writes, and the pipeline builds the DAG from those declarations.
97
+
98
+ Layer types (`open_rating_engine.rating_engine.pricing_layers`), all extending `BasePricingLayer`:
99
+
100
+ | Layer | Purpose |
101
+ |---|---|
102
+ | `SourceColumn` | Declares an input column supplied in the scoring payload |
103
+ | `ColumnCalculation` | Computes a new column from an expression string (restricted builtins) or a callable |
104
+ | `TableTransform` | Creates or replaces a table with a callable |
105
+ | `TableAggregation` | Group-by with named aggregations, e.g. `{"total": ("cost", "sum")}` |
106
+ | `TableJoin` | Merges two tables; the key names can differ on each side |
107
+ | `RenameColumns` / `DropColumns` | Column-level changes |
108
+ | `TableDrop` | Removes an intermediate table from the pipeline state |
109
+ | `RatingTablesLayer` | Looks up rating factors from several tables and multiplies them together |
110
+ | `GlmScoring` | Scores a GLM or other additive model in closed form, with no JVM |
111
+ | `H2OScoringParameter` | Scores an H2O MOJO model (regression / binomial / multinomial) |
112
+ | `OnnxScoring` | Scores an ONNX model |
113
+ | `CustomLayer` | Runs any callable that doesn't fit a typed layer |
114
+
115
+ `open_rating_engine.rating_engine.binning` holds the thermometer (cumulative) encoding. Training
116
+ and scoring both use it, so they produce identical columns.
117
+
118
+ ## Price optimisation
119
+
120
+ `open_rating_engine.optimization`:
121
+
122
+ | Optimiser | Decision |
123
+ |---|---|
124
+ | `PriceOptimizerIndividual` | A multiplier for each policy, for a single period |
125
+ | `PriceOptimizerRatingFactor` | A multiplier for each rating-factor level, for a single period |
126
+ | `PriceOptimizerIndividualMultiPeriod` | A lifetime multiplier for each policy, chosen against multi-period NPV |
127
+ | `PriceOptimizerRatingFactorMultiPeriod` | A rating-factor overlay, chosen by forward-simulating the horizon |
128
+
129
+ Helpers: `simulate_adjustment_grid`, `make_demand_emulation`, `make_log_multiplier_penalty` and
130
+ `make_log_multiplier_regularizer`.
131
+
132
+ Multi-period optimisers age the book each period with
133
+ `open_rating_engine.data_processing.data_aging.apply_aging`.
134
+
135
+ ## Development
136
+
137
+ ```bash
138
+ pip install -e ".[all,test]"
139
+ pytest
140
+ ```
141
+
142
+ ## License
143
+
144
+ Apache License 2.0. See [LICENSE](LICENSE).
@@ -0,0 +1,105 @@
1
+ # open-rating-engine
2
+
3
+ An insurance/banking rating engine for Python. You describe a pricing algorithm as a set of
4
+ typed layers; the engine builds a dependency graph (DAG) from them and scores policies through
5
+ it. It also ships price optimisers that run on top of a pipeline.
6
+
7
+ A pipeline is an MLflow `PythonModel`, so you log, version, load and serve it with standard
8
+ MLflow tooling.
9
+
10
+ ## Install
11
+
12
+ ```bash
13
+ pip install open-rating-engine # core: pipeline, layers, optimisers
14
+ pip install "open-rating-engine[all]" # plus every optional extra
15
+ ```
16
+
17
+ | Extra | Adds | Needed for |
18
+ |---|---|---|
19
+ | `h2o` | `h2o`, `jpype1` | `H2OScoringParameter` (H2O MOJO scoring) |
20
+ | `onnx` | `onnxruntime` | `OnnxScoring` |
21
+ | `viz` | `plotly`, `networkx` | `PyfuncPricingPipeline.plot_dag()` |
22
+ | `notebook` | `ipywidgets` | optimiser progress bars in Jupyter |
23
+
24
+ Optional dependencies are imported lazily, so `import open_rating_engine` works on a core-only
25
+ install.
26
+
27
+ ## Imports
28
+
29
+ The headline names (the pipeline, every layer class, the layer exceptions and `apply_aging`) are
30
+ available from the top-level package. Everything else lives in its subpackage:
31
+
32
+ ```python
33
+ from open_rating_engine import PyfuncPricingPipeline, RatingTablesLayer, apply_aging
34
+ from open_rating_engine.optimization import PriceOptimizerRatingFactor
35
+ from open_rating_engine.rating_engine.binning import thermometer_column_names
36
+ ```
37
+
38
+ Package `__init__` modules load their names on first use, so `import open_rating_engine` is
39
+ near-instant. You pay for mlflow only when you touch the pipeline or a layer. Each module's
40
+ `__all__` defines its public API.
41
+
42
+ ## Rating engine
43
+
44
+ `PyfuncPricingPipeline` (`open_rating_engine.rating_engine.pricing_pipeline`):
45
+
46
+ - `add_parameter()` / `remove_parameter()` register and remove layers.
47
+ - Layers are topologically sorted, and cycles are reported. Independent column calculations run
48
+ in parallel waves. Structural layers (joins, drops, renames, aggregations) run in sequence so
49
+ that tables stay consistent.
50
+ - `predict(context, model_input)` is the MLflow-compatible scoring entry point.
51
+ - `load_context(context)` expects every artifact in `context.artifacts` to be a local file
52
+ path. The engine fetches nothing remote, so download artifacts from blob storage or a model
53
+ registry before building the context.
54
+ - `profile_predict()` returns how long each layer took. `plot_dag()` draws the graph.
55
+
56
+ Pipeline state is a dict of named DataFrames. Each layer declares what it reads (`depends_on`)
57
+ and what it writes, and the pipeline builds the DAG from those declarations.
58
+
59
+ Layer types (`open_rating_engine.rating_engine.pricing_layers`), all extending `BasePricingLayer`:
60
+
61
+ | Layer | Purpose |
62
+ |---|---|
63
+ | `SourceColumn` | Declares an input column supplied in the scoring payload |
64
+ | `ColumnCalculation` | Computes a new column from an expression string (restricted builtins) or a callable |
65
+ | `TableTransform` | Creates or replaces a table with a callable |
66
+ | `TableAggregation` | Group-by with named aggregations, e.g. `{"total": ("cost", "sum")}` |
67
+ | `TableJoin` | Merges two tables; the key names can differ on each side |
68
+ | `RenameColumns` / `DropColumns` | Column-level changes |
69
+ | `TableDrop` | Removes an intermediate table from the pipeline state |
70
+ | `RatingTablesLayer` | Looks up rating factors from several tables and multiplies them together |
71
+ | `GlmScoring` | Scores a GLM or other additive model in closed form, with no JVM |
72
+ | `H2OScoringParameter` | Scores an H2O MOJO model (regression / binomial / multinomial) |
73
+ | `OnnxScoring` | Scores an ONNX model |
74
+ | `CustomLayer` | Runs any callable that doesn't fit a typed layer |
75
+
76
+ `open_rating_engine.rating_engine.binning` holds the thermometer (cumulative) encoding. Training
77
+ and scoring both use it, so they produce identical columns.
78
+
79
+ ## Price optimisation
80
+
81
+ `open_rating_engine.optimization`:
82
+
83
+ | Optimiser | Decision |
84
+ |---|---|
85
+ | `PriceOptimizerIndividual` | A multiplier for each policy, for a single period |
86
+ | `PriceOptimizerRatingFactor` | A multiplier for each rating-factor level, for a single period |
87
+ | `PriceOptimizerIndividualMultiPeriod` | A lifetime multiplier for each policy, chosen against multi-period NPV |
88
+ | `PriceOptimizerRatingFactorMultiPeriod` | A rating-factor overlay, chosen by forward-simulating the horizon |
89
+
90
+ Helpers: `simulate_adjustment_grid`, `make_demand_emulation`, `make_log_multiplier_penalty` and
91
+ `make_log_multiplier_regularizer`.
92
+
93
+ Multi-period optimisers age the book each period with
94
+ `open_rating_engine.data_processing.data_aging.apply_aging`.
95
+
96
+ ## Development
97
+
98
+ ```bash
99
+ pip install -e ".[all,test]"
100
+ pytest
101
+ ```
102
+
103
+ ## License
104
+
105
+ Apache License 2.0. See [LICENSE](LICENSE).
@@ -0,0 +1,79 @@
1
+ [build-system]
2
+ requires = ["setuptools>=77.0", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "open-rating-engine"
7
+ version = "0.1.0"
8
+ description = "A DAG-based insurance/banking rating engine with price optimisation"
9
+ readme = "README.md"
10
+ authors = [
11
+ { name = "bhavek jamnadas", email = "bhavek.jamnadas.actuary@gmail.com" }
12
+ ]
13
+ license = "Apache-2.0"
14
+ license-files = ["LICENSE"]
15
+ requires-python = ">=3.9"
16
+ keywords = ["actuarial", "actuary", "pricing", "rating engine", "price optimisation", "insurance"]
17
+ classifiers = [
18
+ "Programming Language :: Python :: 3",
19
+ "Operating System :: OS Independent",
20
+ ]
21
+ dependencies = [
22
+ "numpy>=1.20",
23
+ "pandas<3", # RatingTablesLayer key validation assumes object-dtype strings
24
+ "mlflow",
25
+ "tqdm",
26
+ "scipy",
27
+ "numba",
28
+ ]
29
+
30
+ [project.optional-dependencies]
31
+ h2o = [
32
+ "h2o",
33
+ "jpype1",
34
+ ]
35
+ onnx = [
36
+ "onnxruntime",
37
+ ]
38
+ viz = [
39
+ "plotly",
40
+ "networkx",
41
+ ]
42
+ notebook = [
43
+ "ipywidgets",
44
+ ]
45
+ all = [
46
+ "open-rating-engine[h2o,onnx,viz,notebook]",
47
+ ]
48
+ test = [
49
+ "pytest>=8.0",
50
+ "pytest-cov",
51
+ "pytest-mock",
52
+ "jpype1",
53
+ ]
54
+
55
+ [project.urls]
56
+ Homepage = "https://github.com/bhavek-jamnadas/open-rating-engine"
57
+ Issues = "https://github.com/bhavek-jamnadas/open-rating-engine/issues"
58
+
59
+ [tool.setuptools.packages.find]
60
+ where = ["src"]
61
+
62
+ [tool.pytest.ini_options]
63
+ testpaths = ["tests"]
64
+ pythonpath = ["src", "."]
65
+ addopts = "-ra -q"
66
+ filterwarnings = [
67
+ "ignore::UserWarning",
68
+ "ignore::DeprecationWarning",
69
+ ]
70
+
71
+ [tool.coverage.run]
72
+ source = ["open_rating_engine"]
73
+
74
+ [tool.coverage.report]
75
+ exclude_lines = [
76
+ "pragma: no cover",
77
+ "raise NotImplementedError",
78
+ "if __name__ == .__main__.:",
79
+ ]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,67 @@
1
+ """open-rating-engine: a DAG-based insurance/banking rating engine.
2
+
3
+ Names below are loaded on first access (see ``_lazy.py``), so ``import
4
+ open_rating_engine`` is cheap and pulls in mlflow only once the pipeline or a layer
5
+ is actually used.
6
+ """
7
+
8
+ from importlib.metadata import PackageNotFoundError, version
9
+ from typing import TYPE_CHECKING
10
+
11
+ from ._lazy import attach
12
+
13
+ try:
14
+ __version__ = version("open-rating-engine")
15
+ except PackageNotFoundError: # running from a source checkout that isn't installed
16
+ __version__ = "0+unknown"
17
+
18
+ __getattr__, __dir__, _exports = attach(
19
+ __name__,
20
+ exports={
21
+ ".rating_engine.pricing_pipeline": ["PyfuncPricingPipeline"],
22
+ ".rating_engine.pricing_layers": [
23
+ "BasePricingLayer",
24
+ "ColumnCalculation",
25
+ "CustomLayer",
26
+ "DropColumns",
27
+ "GlmScoring",
28
+ "H2OScoringParameter",
29
+ "OnnxScoring",
30
+ "RatingTablesLayer",
31
+ "RenameColumns",
32
+ "SourceColumn",
33
+ "TableAggregation",
34
+ "TableDrop",
35
+ "TableJoin",
36
+ "TableTransform",
37
+ "DependencyError",
38
+ "LayerCalculationError",
39
+ ],
40
+ ".data_processing.data_aging": ["apply_aging", "AgingRuleError"],
41
+ },
42
+ submodules=["data_processing", "optimization", "rating_engine"],
43
+ )
44
+ __all__ = ["__version__", *_exports]
45
+
46
+ if TYPE_CHECKING:
47
+ from . import data_processing, optimization, rating_engine
48
+ from .data_processing.data_aging import AgingRuleError, apply_aging
49
+ from .rating_engine.pricing_layers import (
50
+ BasePricingLayer,
51
+ ColumnCalculation,
52
+ CustomLayer,
53
+ DependencyError,
54
+ DropColumns,
55
+ GlmScoring,
56
+ H2OScoringParameter,
57
+ LayerCalculationError,
58
+ OnnxScoring,
59
+ RatingTablesLayer,
60
+ RenameColumns,
61
+ SourceColumn,
62
+ TableAggregation,
63
+ TableDrop,
64
+ TableJoin,
65
+ TableTransform,
66
+ )
67
+ from .rating_engine.pricing_pipeline import PyfuncPricingPipeline
@@ -0,0 +1,58 @@
1
+ """Lazy re-exports for package ``__init__`` modules (PEP 562).
2
+
3
+ A package ``__init__`` that eagerly imports its submodules makes every import of
4
+ anything in the package pay for all of them: ``from open_rating_engine.rating_engine
5
+ .binning import ...`` would load mlflow just to run the parent ``__init__``. Instead
6
+ each ``__init__`` declares which names it re-exports from which submodule, and the
7
+ submodule is imported the first time one of those names is accessed.
8
+
9
+ Each ``__init__`` also repeats the re-exports under ``if TYPE_CHECKING:`` so IDEs and
10
+ type checkers see real imports. ``tests/test_public_api.py`` keeps the two in sync.
11
+ """
12
+
13
+ import sys
14
+ from importlib import import_module
15
+
16
+
17
+ def attach(package, exports, submodules=()):
18
+ """Return ``(__getattr__, __dir__, __all__)`` for ``package``.
19
+
20
+ Parameters
21
+ ----------
22
+ package : str
23
+ The package's ``__name__``.
24
+ exports : dict[str, list[str]]
25
+ Maps a module path relative to ``package`` (e.g. ``".pricing_layers"``) to
26
+ the public names re-exported from it.
27
+ submodules : iterable of str
28
+ Child module names (e.g. ``"optimization"``) made reachable as attributes,
29
+ so ``open_rating_engine.optimization`` works after a bare
30
+ ``import open_rating_engine``.
31
+ """
32
+ name_to_module = {}
33
+ for module, names in exports.items():
34
+ for name in names:
35
+ if name in name_to_module:
36
+ raise ValueError(
37
+ f"{package}: {name!r} is exported from both "
38
+ f"{name_to_module[name]!r} and {module!r}"
39
+ )
40
+ name_to_module[name] = module
41
+ submodules = frozenset(submodules)
42
+ __all__ = sorted(set(name_to_module) | submodules)
43
+
44
+ def __getattr__(name):
45
+ if name in name_to_module:
46
+ value = getattr(import_module(name_to_module[name], package), name)
47
+ elif name in submodules:
48
+ value = import_module(f".{name}", package)
49
+ else:
50
+ raise AttributeError(f"module {package!r} has no attribute {name!r}")
51
+ # Cache on the package so __getattr__ runs at most once per name.
52
+ setattr(sys.modules[package], name, value)
53
+ return value
54
+
55
+ def __dir__():
56
+ return list(__all__)
57
+
58
+ return __getattr__, __dir__, __all__
@@ -0,0 +1,13 @@
1
+ """Data preparation applied before scoring. Loaded lazily; see ``.._lazy``."""
2
+
3
+ from typing import TYPE_CHECKING
4
+
5
+ from .._lazy import attach
6
+
7
+ __getattr__, __dir__, __all__ = attach(
8
+ __name__,
9
+ exports={".data_aging": ["apply_aging", "AgingRuleError"]},
10
+ )
11
+
12
+ if TYPE_CHECKING:
13
+ from .data_aging import AgingRuleError, apply_aging