smerisk 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 (147) hide show
  1. smerisk-0.1.0/.gitignore +31 -0
  2. smerisk-0.1.0/CHANGELOG.md +64 -0
  3. smerisk-0.1.0/LICENSE +201 -0
  4. smerisk-0.1.0/PKG-INFO +152 -0
  5. smerisk-0.1.0/README.md +125 -0
  6. smerisk-0.1.0/docs/README.md +62 -0
  7. smerisk-0.1.0/docs/data-contracts.md +100 -0
  8. smerisk-0.1.0/docs/formulas/benford.md +95 -0
  9. smerisk-0.1.0/docs/formulas/beta_binomial.md +90 -0
  10. smerisk-0.1.0/docs/formulas/brier.md +88 -0
  11. smerisk-0.1.0/docs/formulas/credibility.md +120 -0
  12. smerisk-0.1.0/docs/formulas/erlang_c.md +95 -0
  13. smerisk-0.1.0/docs/formulas/expected_loss.md +100 -0
  14. smerisk-0.1.0/docs/formulas/fixed_price_completion.md +131 -0
  15. smerisk-0.1.0/docs/formulas/kaplan_meier.md +128 -0
  16. smerisk-0.1.0/docs/formulas/kupiec.md +85 -0
  17. smerisk-0.1.0/docs/formulas/markov_payments.md +119 -0
  18. smerisk-0.1.0/docs/formulas/newsvendor.md +107 -0
  19. smerisk-0.1.0/docs/formulas/pert_estimate.md +98 -0
  20. smerisk-0.1.0/docs/formulas/risk_measures.md +97 -0
  21. smerisk-0.1.0/docs/formulas/simulate_aggregate.md +137 -0
  22. smerisk-0.1.0/docs/formulas/utilization_forecast.md +146 -0
  23. smerisk-0.1.0/docs/parameter-preparation.md +128 -0
  24. smerisk-0.1.0/docs/service.md +195 -0
  25. smerisk-0.1.0/docs/usecases/attrition.md +76 -0
  26. smerisk-0.1.0/docs/usecases/cash_at_risk.md +121 -0
  27. smerisk-0.1.0/docs/usecases/counter_staffing.md +76 -0
  28. smerisk-0.1.0/docs/usecases/fixed_price_risk.md +98 -0
  29. smerisk-0.1.0/docs/usecases/forecast_reliability.md +99 -0
  30. smerisk-0.1.0/docs/usecases/fresh_orders.md +76 -0
  31. smerisk-0.1.0/docs/usecases/ledger_audit.md +83 -0
  32. smerisk-0.1.0/docs/usecases/payroll_at_risk.md +95 -0
  33. smerisk-0.1.0/docs/usecases/rate_credibility.md +95 -0
  34. smerisk-0.1.0/docs/usecases/receivables_risk.md +102 -0
  35. smerisk-0.1.0/docs/usecases/utilization_forecast.md +117 -0
  36. smerisk-0.1.0/examples/attrition/expected.json +386 -0
  37. smerisk-0.1.0/examples/attrition/input.json +185 -0
  38. smerisk-0.1.0/examples/cash_at_risk/expected.json +436 -0
  39. smerisk-0.1.0/examples/cash_at_risk/input.json +899 -0
  40. smerisk-0.1.0/examples/counter_staffing/expected.json +223 -0
  41. smerisk-0.1.0/examples/counter_staffing/input.json +200 -0
  42. smerisk-0.1.0/examples/fixed_price_risk/expected.json +192 -0
  43. smerisk-0.1.0/examples/fixed_price_risk/input.json +65 -0
  44. smerisk-0.1.0/examples/forecast_reliability/expected.json +182 -0
  45. smerisk-0.1.0/examples/forecast_reliability/input.json +179 -0
  46. smerisk-0.1.0/examples/fresh_orders/expected.json +153 -0
  47. smerisk-0.1.0/examples/fresh_orders/input.json +190 -0
  48. smerisk-0.1.0/examples/ledger_audit/expected.json +423 -0
  49. smerisk-0.1.0/examples/ledger_audit/input.json +2407 -0
  50. smerisk-0.1.0/examples/payroll_at_risk/expected.json +283 -0
  51. smerisk-0.1.0/examples/payroll_at_risk/input.json +2909 -0
  52. smerisk-0.1.0/examples/rate_credibility/expected.json +369 -0
  53. smerisk-0.1.0/examples/rate_credibility/input.json +449 -0
  54. smerisk-0.1.0/examples/receivables_risk/expected.json +320 -0
  55. smerisk-0.1.0/examples/receivables_risk/input.json +997 -0
  56. smerisk-0.1.0/examples/utilization_forecast/expected.json +334 -0
  57. smerisk-0.1.0/examples/utilization_forecast/input.json +94 -0
  58. smerisk-0.1.0/pyproject.toml +96 -0
  59. smerisk-0.1.0/src/smerisk/__init__.py +37 -0
  60. smerisk-0.1.0/src/smerisk/_version.py +1 -0
  61. smerisk-0.1.0/src/smerisk/contracts/__init__.py +64 -0
  62. smerisk-0.1.0/src/smerisk/contracts/_base.py +77 -0
  63. smerisk-0.1.0/src/smerisk/contracts/accounting.py +137 -0
  64. smerisk-0.1.0/src/smerisk/contracts/consulting.py +150 -0
  65. smerisk-0.1.0/src/smerisk/contracts/fec_reader.py +96 -0
  66. smerisk-0.1.0/src/smerisk/contracts/forecasts.py +59 -0
  67. smerisk-0.1.0/src/smerisk/contracts/payroll.py +107 -0
  68. smerisk-0.1.0/src/smerisk/contracts/retail.py +33 -0
  69. smerisk-0.1.0/src/smerisk/core/__init__.py +1 -0
  70. smerisk-0.1.0/src/smerisk/core/correlation.py +104 -0
  71. smerisk-0.1.0/src/smerisk/core/distributions.py +268 -0
  72. smerisk-0.1.0/src/smerisk/core/envelope.py +73 -0
  73. smerisk-0.1.0/src/smerisk/core/errors.py +62 -0
  74. smerisk-0.1.0/src/smerisk/core/montecarlo.py +88 -0
  75. smerisk-0.1.0/src/smerisk/core/random.py +29 -0
  76. smerisk-0.1.0/src/smerisk/core/types.py +40 -0
  77. smerisk-0.1.0/src/smerisk/core/warnings.py +14 -0
  78. smerisk-0.1.0/src/smerisk/formulas/__init__.py +1 -0
  79. smerisk-0.1.0/src/smerisk/formulas/audit.py +150 -0
  80. smerisk-0.1.0/src/smerisk/formulas/bayes.py +263 -0
  81. smerisk-0.1.0/src/smerisk/formulas/credit.py +320 -0
  82. smerisk-0.1.0/src/smerisk/formulas/operations.py +261 -0
  83. smerisk-0.1.0/src/smerisk/formulas/pert.py +122 -0
  84. smerisk-0.1.0/src/smerisk/formulas/projects.py +183 -0
  85. smerisk-0.1.0/src/smerisk/formulas/risk.py +71 -0
  86. smerisk-0.1.0/src/smerisk/formulas/simulation.py +307 -0
  87. smerisk-0.1.0/src/smerisk/formulas/survival.py +253 -0
  88. smerisk-0.1.0/src/smerisk/formulas/utilization.py +370 -0
  89. smerisk-0.1.0/src/smerisk/formulas/validation.py +156 -0
  90. smerisk-0.1.0/src/smerisk/prepare/__init__.py +70 -0
  91. smerisk-0.1.0/src/smerisk/prepare/_base.py +24 -0
  92. smerisk-0.1.0/src/smerisk/prepare/correlations.py +79 -0
  93. smerisk-0.1.0/src/smerisk/prepare/demand.py +134 -0
  94. smerisk-0.1.0/src/smerisk/prepare/employment.py +144 -0
  95. smerisk-0.1.0/src/smerisk/prepare/overrides.py +77 -0
  96. smerisk-0.1.0/src/smerisk/prepare/projects.py +87 -0
  97. smerisk-0.1.0/src/smerisk/prepare/quality.py +113 -0
  98. smerisk-0.1.0/src/smerisk/prepare/rates.py +225 -0
  99. smerisk-0.1.0/src/smerisk/prepare/receivables.py +205 -0
  100. smerisk-0.1.0/src/smerisk/prepare/series.py +241 -0
  101. smerisk-0.1.0/src/smerisk/py.typed +0 -0
  102. smerisk-0.1.0/src/smerisk/usecases/__init__.py +27 -0
  103. smerisk-0.1.0/src/smerisk/usecases/_base.py +120 -0
  104. smerisk-0.1.0/src/smerisk/usecases/attrition.py +87 -0
  105. smerisk-0.1.0/src/smerisk/usecases/cash_at_risk.py +384 -0
  106. smerisk-0.1.0/src/smerisk/usecases/counter_staffing.py +117 -0
  107. smerisk-0.1.0/src/smerisk/usecases/fixed_price_risk.py +155 -0
  108. smerisk-0.1.0/src/smerisk/usecases/forecast_reliability.py +119 -0
  109. smerisk-0.1.0/src/smerisk/usecases/fresh_orders.py +109 -0
  110. smerisk-0.1.0/src/smerisk/usecases/ledger_audit.py +82 -0
  111. smerisk-0.1.0/src/smerisk/usecases/payroll_at_risk.py +162 -0
  112. smerisk-0.1.0/src/smerisk/usecases/rate_credibility.py +184 -0
  113. smerisk-0.1.0/src/smerisk/usecases/receivables_risk.py +127 -0
  114. smerisk-0.1.0/src/smerisk/usecases/utilization_forecast.py +271 -0
  115. smerisk-0.1.0/tests/__init__.py +0 -0
  116. smerisk-0.1.0/tests/contracts/__init__.py +0 -0
  117. smerisk-0.1.0/tests/contracts/test_fec_reader.py +93 -0
  118. smerisk-0.1.0/tests/contracts/test_records.py +274 -0
  119. smerisk-0.1.0/tests/core/__init__.py +0 -0
  120. smerisk-0.1.0/tests/core/test_correlation.py +52 -0
  121. smerisk-0.1.0/tests/core/test_distributions.py +145 -0
  122. smerisk-0.1.0/tests/core/test_random.py +21 -0
  123. smerisk-0.1.0/tests/formulas/__init__.py +0 -0
  124. smerisk-0.1.0/tests/formulas/test_audit.py +101 -0
  125. smerisk-0.1.0/tests/formulas/test_bayes.py +191 -0
  126. smerisk-0.1.0/tests/formulas/test_credit.py +229 -0
  127. smerisk-0.1.0/tests/formulas/test_operations.py +131 -0
  128. smerisk-0.1.0/tests/formulas/test_pert.py +89 -0
  129. smerisk-0.1.0/tests/formulas/test_projects.py +145 -0
  130. smerisk-0.1.0/tests/formulas/test_risk.py +51 -0
  131. smerisk-0.1.0/tests/formulas/test_simulation.py +355 -0
  132. smerisk-0.1.0/tests/formulas/test_survival.py +130 -0
  133. smerisk-0.1.0/tests/formulas/test_utilization.py +197 -0
  134. smerisk-0.1.0/tests/formulas/test_validation.py +123 -0
  135. smerisk-0.1.0/tests/prepare/__init__.py +0 -0
  136. smerisk-0.1.0/tests/prepare/test_correlations_overrides.py +123 -0
  137. smerisk-0.1.0/tests/prepare/test_employment_demand_projects.py +170 -0
  138. smerisk-0.1.0/tests/prepare/test_quality.py +51 -0
  139. smerisk-0.1.0/tests/prepare/test_rates.py +155 -0
  140. smerisk-0.1.0/tests/prepare/test_receivables.py +127 -0
  141. smerisk-0.1.0/tests/prepare/test_series.py +158 -0
  142. smerisk-0.1.0/tests/test_docs.py +46 -0
  143. smerisk-0.1.0/tests/test_package.py +5 -0
  144. smerisk-0.1.0/tests/usecases/__init__.py +0 -0
  145. smerisk-0.1.0/tests/usecases/test_examples.py +43 -0
  146. smerisk-0.1.0/tests/usecases/test_simple_usecases.py +296 -0
  147. smerisk-0.1.0/tests/usecases/test_simulated_usecases.py +516 -0
@@ -0,0 +1,31 @@
1
+ __pycache__/
2
+ *.py[cod]
3
+ .venv/
4
+ dist/
5
+ build/
6
+ *.egg-info/
7
+ .pytest_cache/
8
+ .mypy_cache/
9
+ .ruff_cache/
10
+ .hypothesis/
11
+ .coverage
12
+ coverage.xml
13
+ htmlcov/
14
+
15
+ # Secrets and local configuration (API tokens, dataset key)
16
+ .env
17
+ .env.*
18
+ *.pem
19
+ *.key
20
+
21
+ # Generated files
22
+ openapi.json
23
+ *.log
24
+
25
+ # Editors and operating systems
26
+ .vscode/
27
+ .idea/
28
+ .DS_Store
29
+ Thumbs.db
30
+
31
+
@@ -0,0 +1,64 @@
1
+ # Changelog
2
+
3
+ This project follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/) and
4
+ [Semantic Versioning](https://semver.org/). Changing the random-number generator is a major-version change.
5
+
6
+ ## [Unreleased]
7
+
8
+ ## [0.1.0] - 2026-10-25
9
+
10
+ First release.
11
+
12
+ ### Added
13
+
14
+ - Repository scaffold: `smerisk` library, `smerisk-service`, and continuous integration.
15
+ - `simulate_aggregate`: Monte Carlo aggregate simulation, rank correlations using a Gaussian copula, and variance contributions.
16
+ Each ungrouped component and each correlation group has its own random stream.
17
+ - `risk_measures`: VaR, Expected Shortfall, and CFaR for a sample.
18
+ - `pert_estimate`: classical PERT three-point estimate, total effort at confidence levels, and contingency.
19
+ - `fixed_price_completion`: Monte Carlo final cost, margin, budget and deadline probabilities, and task and risk
20
+ variance contributions, with one random stream per task and risk.
21
+ - `utilization_forecast`: Monte Carlo team utilization, bench days, per-consultant bench probability, and
22
+ unstaffed deal days, with month-by-month staffing of won deals.
23
+ - `credibility`: Bühlmann-Straub credibility in `estimate` and `reference` modes.
24
+ - `beta_binomial`: conjugate Beta-Binomial rate with prior, equal-tailed credible interval, and prior weight.
25
+ - `kaplan_meier`: Kaplan-Meier survival with Greenwood variance, log-log confidence limits, small-group
26
+ suppression, and the log-rank test.
27
+ - `markov_payments`: absorbing Markov chain of receivables with smoothed transitions, monthly projection, and
28
+ default probabilities and payment delays by ageing state.
29
+ - `expected_loss`: expected credit loss by segment and concentration, with optional Monte Carlo loss quantiles
30
+ and expected shortfall under independent defaults.
31
+ - `benford`: first-digit and first-two-digit Benford tests with Nigrini's MAD bands, z statistics, chi-square, and
32
+ flagged labels.
33
+ - `newsvendor`: optimal perishable order quantity with expected sales, leftovers, shortage, and profit.
34
+ - `erlang_c`: M/M/c waiting probability, mean wait, service level, recommended team size, and staffing table.
35
+ - `brier`: Brier score, skill score against climatology or a given rate, and calibration bins.
36
+ - `kupiec`: proportion-of-failures likelihood-ratio test with verdict.
37
+ - Raw data contracts (`smerisk.contracts`): Pydantic models for payroll, accounting, consulting, retail, and
38
+ forecast-log records; `parse_records` sets invalid records aside with their reason; `read_fec` reads FEC files
39
+ (tab, `|`, or `;`, UTF-8 or Windows-1252, `Debit`/`Credit` or `Montant`/`Sens`) and drops labels.
40
+ - Parameter preparation (`smerisk.prepare`): monthly series to distributions (outliers, seasonality, trend,
41
+ distribution choice), shrunk Spearman correlations, renewal, stage, and on-time payment rates, receivables
42
+ transitions and invoices rebuilt from a lettered FEC, employment durations, arrivals and product demand, team
43
+ daily cost, the data quality report, and traced overrides.
44
+ - Common foundation: response envelope, errors, warning codes, PCG64 seed management, nine probability distributions,
45
+ and correlation-matrix adjustment.
46
+ - Business use cases (`smerisk.usecases`): `payroll_at_risk`, `cash_at_risk`, `rate_credibility`,
47
+ `receivables_risk`, `attrition`, `ledger_audit`, `fixed_price_risk`, `utilization_forecast`, `fresh_orders`,
48
+ `counter_staffing`, and `forecast_reliability`. Each takes raw records and settings, prepares the parameters, calls
49
+ the formulas, and returns the envelope with `derived_parameters` and `data_quality`; overrides apply by path.
50
+ - HTTP service (`smerisk-service`, run from a clone of the repository; only the library goes to PyPI): the 15 formula routes and 11 use case routes under `/v1`, generated from the
51
+ library's input models; bearer tokens, one per calling application; jobs for simulations (`GET /v1/jobs/{id}`,
52
+ results kept 24 hours); reusable datasets encrypted in memory (`/v1/datasets`, FEC upload in multipart); errors
53
+ 422, 409, 413, 429, and 500 with a trace identifier; request size limit; OpenAPI contract written by the CI. Datasets can be sent in numbered pages
54
+ (`PUT /v1/datasets/{id}/pages/{n}`, safe to retry, any order) with the number of pages given at creation or with
55
+ `complete`; a use case answers 409 `DATASET_INCOMPLETE` while a page is missing. Requests can be compressed with gzip, with a limit on
56
+ the decompressed size. Structured logs (JSON or text): one event per request, job, and dataset operation, with an
57
+ `X-Request-ID` that is also the trace id of a 500; no body, record, token, or exception message is ever logged.
58
+ - `simulate_aggregate`: optional `persistent` components and groups (one draw for the whole horizon) and
59
+ `orientation` (`lower_is_better` measures the risk of a cost overrun). Results of existing inputs are unchanged.
60
+
61
+ ### Changed
62
+
63
+ - Translated package source comments, docstrings, validation messages, and project documentation into English.
64
+ - Added English formula documentation for all contracts in the API specification.
smerisk-0.1.0/LICENSE ADDED
@@ -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.
smerisk-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,152 @@
1
+ Metadata-Version: 2.5
2
+ Name: smerisk
3
+ Version: 0.1.0
4
+ Summary: Probabilistic and statistical calculations for managing small and medium-sized businesses: cash at risk, fixed-price projects, credibility, survival, unpaid receivables, Benford, newsvendor, Erlang C.
5
+ Project-URL: Homepage, https://github.com/OussamaELGUERRAOUI/smerisk
6
+ Project-URL: Source, https://github.com/OussamaELGUERRAOUI/smerisk
7
+ Project-URL: Documentation, https://github.com/OussamaELGUERRAOUI/smerisk/tree/main/docs
8
+ Project-URL: Changelog, https://github.com/OussamaELGUERRAOUI/smerisk/blob/main/CHANGELOG.md
9
+ Project-URL: Issues, https://github.com/OussamaELGUERRAOUI/smerisk/issues
10
+ License-Expression: Apache-2.0
11
+ License-File: LICENSE
12
+ Classifier: Development Status :: 3 - Alpha
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: Intended Audience :: Financial and Insurance Industry
15
+ Classifier: Operating System :: OS Independent
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Programming Language :: Python :: 3.13
20
+ Classifier: Topic :: Scientific/Engineering :: Mathematics
21
+ Classifier: Typing :: Typed
22
+ Requires-Python: >=3.11
23
+ Requires-Dist: numpy>=2.0
24
+ Requires-Dist: pydantic>=2.7
25
+ Requires-Dist: scipy>=1.13
26
+ Description-Content-Type: text/markdown
27
+
28
+ # smerisk
29
+
30
+ Probability and statistical calculations for small and medium-sized businesses: cash-flow and payroll risk,
31
+ fixed-price projects, utilization, rate estimation with sparse data, survival, receivables, accounting anomalies,
32
+ perishable goods, service staffing, and forecast reliability.
33
+
34
+ Two ways to use it:
35
+
36
+ - **Python library** (`pip install smerisk`): pure functions with no database or network access.
37
+ - **HTTP service** (FastAPI): clone this repository and run the service to call the same functions under `/v1/...`
38
+ from any language; see [Running the HTTP service](#running-the-http-service).
39
+
40
+ Documentation of each formula and use case is in [`docs/`](https://github.com/OussamaELGUERRAOUI/smerisk/blob/main/docs/README.md).
41
+
42
+ > **Status:** first release (`0.1.0`, alpha). All the functions of the specification are implemented: the formulas,
43
+ > the raw data contracts, parameter preparation, the eleven business use cases, and the HTTP service. The API may
44
+ > still change before 1.0; see the [changelog](https://github.com/OussamaELGUERRAOUI/smerisk/blob/main/CHANGELOG.md).
45
+
46
+ ## Installation
47
+
48
+ ```bash
49
+ pip install smerisk
50
+ ```
51
+
52
+ ## Example
53
+
54
+ ```python
55
+ from smerisk import risk_measures
56
+
57
+ result = risk_measures(
58
+ samples=[float(value) for value in range(1, 101)],
59
+ confidence=0.95,
60
+ )
61
+
62
+ print(round(result.result.quantile, 2)) # 5.95
63
+ print(round(result.result.var, 2)) # 44.55
64
+ print(result.result.expected_shortfall) # 3.0
65
+ print(result.assumptions)
66
+ ```
67
+
68
+ ## Running the HTTP service
69
+
70
+ ### Prerequisites
71
+
72
+ - **Python 3.11 or newer** (`python --version`) and **Git**.
73
+ - Nothing else to install by hand: `pip install ./ ./service` installs the library and the service with all their
74
+ dependencies (FastAPI, Uvicorn, Pydantic, NumPy, SciPy, cryptography, python-multipart).
75
+
76
+ ### 1. Get the code and install it
77
+
78
+ Linux and macOS:
79
+
80
+ ```bash
81
+ git clone https://github.com/OussamaELGUERRAOUI/smerisk.git
82
+ cd smerisk
83
+ python3 -m venv .venv
84
+ .venv/bin/python -m pip install ./ ./service
85
+ ```
86
+
87
+ Windows (PowerShell):
88
+
89
+ ```powershell
90
+ git clone https://github.com/OussamaELGUERRAOUI/smerisk.git
91
+ cd smerisk
92
+ python -m venv .venv
93
+ .venv\Scripts\python -m pip install ./ ./service
94
+ ```
95
+
96
+ The commands call the Python of `.venv` directly, so there is no environment to activate.
97
+
98
+ ### 2. Choose a token and start the service
99
+
100
+ Each application that calls the service uses a token: a secret string that you choose. To create one:
101
+
102
+ ```bash
103
+ python -c "import secrets; print(secrets.token_urlsafe(32))"
104
+ ```
105
+
106
+ Linux and macOS:
107
+
108
+ ```bash
109
+ export SMERISK_API_TOKENS="paste-the-token-here"
110
+ .venv/bin/python -m uvicorn smerisk_service.main:app --host 127.0.0.1 --port 8000 --workers 1
111
+ ```
112
+
113
+ Windows (PowerShell):
114
+
115
+ ```powershell
116
+ $env:SMERISK_API_TOKENS = "paste-the-token-here"
117
+ .venv\Scripts\python -m uvicorn smerisk_service.main:app --host 127.0.0.1 --port 8000 --workers 1
118
+ ```
119
+
120
+ Several applications: separate their tokens with commas. `127.0.0.1` keeps the service on your machine; on a server,
121
+ use `--host 0.0.0.0` behind a reverse proxy that serves HTTPS. Keep `--workers 1`. Stop the service with `Ctrl+C`.
122
+
123
+ ### 3. Check that it works
124
+
125
+ - `http://127.0.0.1:8000/health` answers `{"status": "ok", ...}`.
126
+ - `http://127.0.0.1:8000/docs` shows every route; the **Authorize** button takes the token.
127
+ - A first calculation:
128
+
129
+ ```bash
130
+ curl -X POST http://127.0.0.1:8000/v1/pert/estimate \
131
+ -H "Authorization: Bearer paste-the-token-here" -H "Content-Type: application/json" \
132
+ -d '{"tasks": [{"id": "design", "optimistic": 2, "most_likely": 4, "pessimistic": 9}]}'
133
+ ```
134
+
135
+ ```powershell
136
+ $body = '{"tasks": [{"id": "design", "optimistic": 2, "most_likely": 4, "pessimistic": 9}]}'
137
+ Invoke-RestMethod -Method Post -Uri http://127.0.0.1:8000/v1/pert/estimate `
138
+ -Headers @{ Authorization = "Bearer paste-the-token-here" } -ContentType "application/json" -Body $body
139
+ ```
140
+
141
+ The answer contains `"expected": 4.5` in `result.total`.
142
+
143
+ To update: `git pull`, then run the install command of step 1 again. With Docker instead of Python:
144
+ `docker build -f service/Dockerfile -t smerisk-service .` then
145
+ `docker run -p 8000:8000 -e SMERISK_API_TOKENS=paste-the-token-here smerisk-service`.
146
+
147
+ The full guide (configuration, use cases, jobs, large datasets, errors, logs) is
148
+ [docs/service.md](https://github.com/OussamaELGUERRAOUI/smerisk/blob/main/docs/service.md).
149
+
150
+ ## License
151
+
152
+ Apache 2.0; see [LICENSE](https://github.com/OussamaELGUERRAOUI/smerisk/blob/main/LICENSE).
@@ -0,0 +1,125 @@
1
+ # smerisk
2
+
3
+ Probability and statistical calculations for small and medium-sized businesses: cash-flow and payroll risk,
4
+ fixed-price projects, utilization, rate estimation with sparse data, survival, receivables, accounting anomalies,
5
+ perishable goods, service staffing, and forecast reliability.
6
+
7
+ Two ways to use it:
8
+
9
+ - **Python library** (`pip install smerisk`): pure functions with no database or network access.
10
+ - **HTTP service** (FastAPI): clone this repository and run the service to call the same functions under `/v1/...`
11
+ from any language; see [Running the HTTP service](#running-the-http-service).
12
+
13
+ Documentation of each formula and use case is in [`docs/`](https://github.com/OussamaELGUERRAOUI/smerisk/blob/main/docs/README.md).
14
+
15
+ > **Status:** first release (`0.1.0`, alpha). All the functions of the specification are implemented: the formulas,
16
+ > the raw data contracts, parameter preparation, the eleven business use cases, and the HTTP service. The API may
17
+ > still change before 1.0; see the [changelog](https://github.com/OussamaELGUERRAOUI/smerisk/blob/main/CHANGELOG.md).
18
+
19
+ ## Installation
20
+
21
+ ```bash
22
+ pip install smerisk
23
+ ```
24
+
25
+ ## Example
26
+
27
+ ```python
28
+ from smerisk import risk_measures
29
+
30
+ result = risk_measures(
31
+ samples=[float(value) for value in range(1, 101)],
32
+ confidence=0.95,
33
+ )
34
+
35
+ print(round(result.result.quantile, 2)) # 5.95
36
+ print(round(result.result.var, 2)) # 44.55
37
+ print(result.result.expected_shortfall) # 3.0
38
+ print(result.assumptions)
39
+ ```
40
+
41
+ ## Running the HTTP service
42
+
43
+ ### Prerequisites
44
+
45
+ - **Python 3.11 or newer** (`python --version`) and **Git**.
46
+ - Nothing else to install by hand: `pip install ./ ./service` installs the library and the service with all their
47
+ dependencies (FastAPI, Uvicorn, Pydantic, NumPy, SciPy, cryptography, python-multipart).
48
+
49
+ ### 1. Get the code and install it
50
+
51
+ Linux and macOS:
52
+
53
+ ```bash
54
+ git clone https://github.com/OussamaELGUERRAOUI/smerisk.git
55
+ cd smerisk
56
+ python3 -m venv .venv
57
+ .venv/bin/python -m pip install ./ ./service
58
+ ```
59
+
60
+ Windows (PowerShell):
61
+
62
+ ```powershell
63
+ git clone https://github.com/OussamaELGUERRAOUI/smerisk.git
64
+ cd smerisk
65
+ python -m venv .venv
66
+ .venv\Scripts\python -m pip install ./ ./service
67
+ ```
68
+
69
+ The commands call the Python of `.venv` directly, so there is no environment to activate.
70
+
71
+ ### 2. Choose a token and start the service
72
+
73
+ Each application that calls the service uses a token: a secret string that you choose. To create one:
74
+
75
+ ```bash
76
+ python -c "import secrets; print(secrets.token_urlsafe(32))"
77
+ ```
78
+
79
+ Linux and macOS:
80
+
81
+ ```bash
82
+ export SMERISK_API_TOKENS="paste-the-token-here"
83
+ .venv/bin/python -m uvicorn smerisk_service.main:app --host 127.0.0.1 --port 8000 --workers 1
84
+ ```
85
+
86
+ Windows (PowerShell):
87
+
88
+ ```powershell
89
+ $env:SMERISK_API_TOKENS = "paste-the-token-here"
90
+ .venv\Scripts\python -m uvicorn smerisk_service.main:app --host 127.0.0.1 --port 8000 --workers 1
91
+ ```
92
+
93
+ Several applications: separate their tokens with commas. `127.0.0.1` keeps the service on your machine; on a server,
94
+ use `--host 0.0.0.0` behind a reverse proxy that serves HTTPS. Keep `--workers 1`. Stop the service with `Ctrl+C`.
95
+
96
+ ### 3. Check that it works
97
+
98
+ - `http://127.0.0.1:8000/health` answers `{"status": "ok", ...}`.
99
+ - `http://127.0.0.1:8000/docs` shows every route; the **Authorize** button takes the token.
100
+ - A first calculation:
101
+
102
+ ```bash
103
+ curl -X POST http://127.0.0.1:8000/v1/pert/estimate \
104
+ -H "Authorization: Bearer paste-the-token-here" -H "Content-Type: application/json" \
105
+ -d '{"tasks": [{"id": "design", "optimistic": 2, "most_likely": 4, "pessimistic": 9}]}'
106
+ ```
107
+
108
+ ```powershell
109
+ $body = '{"tasks": [{"id": "design", "optimistic": 2, "most_likely": 4, "pessimistic": 9}]}'
110
+ Invoke-RestMethod -Method Post -Uri http://127.0.0.1:8000/v1/pert/estimate `
111
+ -Headers @{ Authorization = "Bearer paste-the-token-here" } -ContentType "application/json" -Body $body
112
+ ```
113
+
114
+ The answer contains `"expected": 4.5` in `result.total`.
115
+
116
+ To update: `git pull`, then run the install command of step 1 again. With Docker instead of Python:
117
+ `docker build -f service/Dockerfile -t smerisk-service .` then
118
+ `docker run -p 8000:8000 -e SMERISK_API_TOKENS=paste-the-token-here smerisk-service`.
119
+
120
+ The full guide (configuration, use cases, jobs, large datasets, errors, logs) is
121
+ [docs/service.md](https://github.com/OussamaELGUERRAOUI/smerisk/blob/main/docs/service.md).
122
+
123
+ ## License
124
+
125
+ Apache 2.0; see [LICENSE](https://github.com/OussamaELGUERRAOUI/smerisk/blob/main/LICENSE).
@@ -0,0 +1,62 @@
1
+ # smerisk documentation
2
+
3
+ There is one page per formula and per use case. Each page describes its purpose, input and output contracts,
4
+ calculation, warnings, errors, and limitations. The contracts are based on the specification (§3–§12). The specification is currently
5
+ kept outside this repository and remains the source of truth.
6
+
7
+ **Implementation status:** all fifteen formulas and eleven use cases are implemented in the Python package and served
8
+ by the HTTP service under the endpoints below; see [HTTP service](service.md).
9
+
10
+ ## Formula reference
11
+
12
+ | Domain | Function | Endpoint | Documentation | Status |
13
+ | --- | --- | --- | --- | --- |
14
+ | Simulation | `simulate_aggregate` | `POST /v1/simulation/aggregate` | [simulate_aggregate](formulas/simulate_aggregate.md) | Implemented |
15
+ | Simulation | `risk_measures` | `POST /v1/risk/measures` | [risk_measures](formulas/risk_measures.md) | Implemented |
16
+ | Projects | `pert_estimate` | `POST /v1/pert/estimate` | [pert_estimate](formulas/pert_estimate.md) | Implemented |
17
+ | Projects | `fixed_price_completion` | `POST /v1/projects/fixed-price-completion` | [fixed_price_completion](formulas/fixed_price_completion.md) | Implemented |
18
+ | Projects | `utilization_forecast` | `POST /v1/utilization/forecast` | [utilization_forecast](formulas/utilization_forecast.md) | Implemented |
19
+ | Rates | `credibility` | `POST /v1/bayes/credibility` | [credibility](formulas/credibility.md) | Implemented |
20
+ | Rates | `beta_binomial` | `POST /v1/bayes/beta-binomial` | [beta_binomial](formulas/beta_binomial.md) | Implemented |
21
+ | Durations | `kaplan_meier` | `POST /v1/survival/kaplan-meier` | [kaplan_meier](formulas/kaplan_meier.md) | Implemented |
22
+ | Receivables | `markov_payments` | `POST /v1/credit/markov-payments` | [markov_payments](formulas/markov_payments.md) | Implemented |
23
+ | Receivables | `expected_loss` | `POST /v1/credit/expected-loss` | [expected_loss](formulas/expected_loss.md) | Implemented |
24
+ | Audit | `benford` | `POST /v1/audit/benford` | [benford](formulas/benford.md) | Implemented |
25
+ | Operations | `newsvendor` | `POST /v1/operations/newsvendor` | [newsvendor](formulas/newsvendor.md) | Implemented |
26
+ | Operations | `erlang_c` | `POST /v1/operations/erlang-c` | [erlang_c](formulas/erlang_c.md) | Implemented |
27
+ | Forecast reliability | `brier` | `POST /v1/validation/brier` | [brier](formulas/brier.md) | Implemented |
28
+ | Forecast reliability | `kupiec` | `POST /v1/validation/kupiec` | [kupiec](formulas/kupiec.md) | Implemented |
29
+
30
+ ## Use cases
31
+
32
+ The use cases (specification §12) take raw data, prepare the parameters, call the formulas, and return the usual
33
+ envelope with `derived_parameters` (each parameter used, with its source) and `data_quality`. They are implemented in
34
+ `smerisk.usecases` and served under `/v1/usecases/…`.
35
+
36
+ | Function | Endpoint | Answers | Documentation |
37
+ | --- | --- | --- | --- |
38
+ | `payroll_at_risk` | `POST /v1/usecases/payroll-at-risk` | payroll cost of the coming months, variable parts and hires | [payroll_at_risk](usecases/payroll_at_risk.md) |
39
+ | `cash_at_risk` | `POST /v1/usecases/cash-at-risk` | weekly bank balance and probability of running short | [cash_at_risk](usecases/cash_at_risk.md) |
40
+ | `rate_credibility` | `POST /v1/usecases/rate-credibility` | credible absenteeism or turnover rate per group | [rate_credibility](usecases/rate_credibility.md) |
41
+ | `receivables_risk` | `POST /v1/usecases/receivables-risk` | ageing of receivables and expected loss | [receivables_risk](usecases/receivables_risk.md) |
42
+ | `attrition` | `POST /v1/usecases/attrition` | retention curves of employees | [attrition](usecases/attrition.md) |
43
+ | `ledger_audit` | `POST /v1/usecases/ledger-audit` | Benford's test on ledger amounts | [ledger_audit](usecases/ledger_audit.md) |
44
+ | `fixed_price_risk` | `POST /v1/usecases/fixed-price-risk` | final cost, margin, and deadline of fixed-price projects | [fixed_price_risk](usecases/fixed_price_risk.md) |
45
+ | `utilization_forecast` | `POST /v1/usecases/utilization-forecast` | billable utilization and bench of a consulting team | [utilization_forecast](usecases/utilization_forecast.md) |
46
+ | `fresh_orders` | `POST /v1/usecases/fresh-orders` | quantities of perishable products to prepare | [fresh_orders](usecases/fresh_orders.md) |
47
+ | `counter_staffing` | `POST /v1/usecases/counter-staffing` | agents needed at the counter by hour | [counter_staffing](usecases/counter_staffing.md) |
48
+ | `forecast_reliability` | `POST /v1/usecases/forecast-reliability` | reliability of past probabilities and intervals | [forecast_reliability](usecases/forecast_reliability.md) |
49
+
50
+ ## Raw data and service
51
+
52
+ The use cases (specification §12) take the records a business application already stores rather than parameters.
53
+ [Raw data contracts](data-contracts.md) describes them, the handling of invalid records, and how a FEC file is read.
54
+ [Parameter preparation](parameter-preparation.md) describes how the parameters of the formulas are estimated from
55
+ them, the data quality report, and overrides. [HTTP service](service.md) describes how to run the service, its
56
+ tokens, jobs, datasets, and errors.
57
+
58
+ ## Shared conventions
59
+
60
+ The specified response envelope contains `result`, `assumptions`, `warnings`, and `meta`. Randomized calculations
61
+ record their seed in `assumptions`. Shared error and warning contracts are described in the external API
62
+ specification (§2.1–§2.6).