actuarialpy 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.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Michael Bryant
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,90 @@
1
+ Metadata-Version: 2.4
2
+ Name: actuarialpy
3
+ Version: 0.1.0
4
+ Summary: Python tools for actuarial analysis.
5
+ Project-URL: Homepage, https://github.com/actuarialpy/actuarialpy-core
6
+ Project-URL: Repository, https://github.com/actuarialpy/actuarialpy-core
7
+ Project-URL: Issues, https://github.com/actuarialpy/actuarialpy-core/issues
8
+ Author: Michael Bryant
9
+ License-Expression: MIT
10
+ License-File: LICENSE
11
+ Keywords: actuarial,analytics,insurance,loss ratio,risk
12
+ Classifier: Development Status :: 3 - Alpha
13
+ Classifier: Intended Audience :: Financial and Insurance Industry
14
+ Classifier: Intended Audience :: Science/Research
15
+ Classifier: License :: OSI Approved :: MIT License
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Programming Language :: Python :: 3.9
18
+ Classifier: Programming Language :: Python :: 3.10
19
+ Classifier: Programming Language :: Python :: 3.11
20
+ Classifier: Programming Language :: Python :: 3.12
21
+ Classifier: Topic :: Office/Business :: Financial
22
+ Classifier: Topic :: Scientific/Engineering :: Mathematics
23
+ Requires-Python: >=3.9
24
+ Requires-Dist: numpy>=1.23
25
+ Description-Content-Type: text/markdown
26
+
27
+ # ActuarialPy
28
+
29
+ **ActuarialPy** is a Python package for general actuarial analysis.
30
+
31
+ The initial version includes a basic loss ratio calculation. Future modules may include experience summaries, trend tools, actual-to-expected analysis, exposure-based metrics, validation, and reporting.
32
+
33
+ ## Installation
34
+
35
+ ```bash
36
+ pip install actuarialpy
37
+ ```
38
+
39
+ ## Usage
40
+
41
+ ```python
42
+ from actuarialpy import loss_ratio
43
+
44
+ lr = loss_ratio(expenses=850_000, revenue=1_000_000)
45
+
46
+ print(lr)
47
+ # 0.85
48
+ ```
49
+
50
+ ## Loss ratio
51
+
52
+ ```python
53
+ loss_ratio(expenses, revenue)
54
+ ```
55
+
56
+ Calculates:
57
+
58
+ ```text
59
+ loss ratio = expenses / revenue
60
+ ```
61
+
62
+ Examples of use:
63
+
64
+ - health MLR: claims / premium
65
+ - P&C loss ratio: losses / earned premium
66
+ - combined-style ratios: losses plus expenses / revenue, if expenses are pre-summed before calling the function
67
+
68
+ ## Development
69
+
70
+ Install locally in editable mode:
71
+
72
+ ```bash
73
+ pip install -e .
74
+ ```
75
+
76
+ Run tests:
77
+
78
+ ```bash
79
+ pip install pytest
80
+ pytest
81
+ ```
82
+
83
+ Build for PyPI:
84
+
85
+ ```bash
86
+ python -m pip install --upgrade build twine
87
+ python -m build
88
+ twine check dist/*
89
+ twine upload dist/*
90
+ ```
@@ -0,0 +1,64 @@
1
+ # ActuarialPy
2
+
3
+ **ActuarialPy** is a Python package for general actuarial analysis.
4
+
5
+ The initial version includes a basic loss ratio calculation. Future modules may include experience summaries, trend tools, actual-to-expected analysis, exposure-based metrics, validation, and reporting.
6
+
7
+ ## Installation
8
+
9
+ ```bash
10
+ pip install actuarialpy
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ ```python
16
+ from actuarialpy import loss_ratio
17
+
18
+ lr = loss_ratio(expenses=850_000, revenue=1_000_000)
19
+
20
+ print(lr)
21
+ # 0.85
22
+ ```
23
+
24
+ ## Loss ratio
25
+
26
+ ```python
27
+ loss_ratio(expenses, revenue)
28
+ ```
29
+
30
+ Calculates:
31
+
32
+ ```text
33
+ loss ratio = expenses / revenue
34
+ ```
35
+
36
+ Examples of use:
37
+
38
+ - health MLR: claims / premium
39
+ - P&C loss ratio: losses / earned premium
40
+ - combined-style ratios: losses plus expenses / revenue, if expenses are pre-summed before calling the function
41
+
42
+ ## Development
43
+
44
+ Install locally in editable mode:
45
+
46
+ ```bash
47
+ pip install -e .
48
+ ```
49
+
50
+ Run tests:
51
+
52
+ ```bash
53
+ pip install pytest
54
+ pytest
55
+ ```
56
+
57
+ Build for PyPI:
58
+
59
+ ```bash
60
+ python -m pip install --upgrade build twine
61
+ python -m build
62
+ twine check dist/*
63
+ twine upload dist/*
64
+ ```
@@ -0,0 +1,7 @@
1
+ """ActuarialPy: Python tools for actuarial analysis."""
2
+
3
+ from actuarialpy.metrics import loss_ratio, safe_divide
4
+
5
+ __all__ = ["loss_ratio", "safe_divide"]
6
+
7
+ __version__ = "0.1.0"
@@ -0,0 +1,71 @@
1
+ """Core actuarial metrics."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from numbers import Number
6
+ from typing import Any
7
+
8
+ import numpy as np
9
+
10
+
11
+ def safe_divide(numerator: Any, denominator: Any) -> Any:
12
+ """Safely divide numerator by denominator.
13
+
14
+ Returns ``np.nan`` where the denominator is zero.
15
+
16
+ Parameters
17
+ ----------
18
+ numerator:
19
+ Scalar or array-like numerator.
20
+ denominator:
21
+ Scalar or array-like denominator.
22
+
23
+ Returns
24
+ -------
25
+ Any
26
+ Division result. Scalars return scalars; array-like inputs return NumPy arrays.
27
+
28
+ Examples
29
+ --------
30
+ >>> safe_divide(10, 2)
31
+ 5.0
32
+ >>> np.isnan(safe_divide(10, 0))
33
+ True
34
+ """
35
+ if isinstance(numerator, Number) and isinstance(denominator, Number):
36
+ return np.nan if denominator == 0 else numerator / denominator
37
+
38
+ numerator_arr = np.asarray(numerator, dtype=float)
39
+ denominator_arr = np.asarray(denominator, dtype=float)
40
+
41
+ return np.divide(
42
+ numerator_arr,
43
+ denominator_arr,
44
+ out=np.full_like(numerator_arr, np.nan, dtype=float),
45
+ where=denominator_arr != 0,
46
+ )
47
+
48
+
49
+ def loss_ratio(expenses: Any, revenue: Any) -> Any:
50
+ """Calculate a loss ratio.
51
+
52
+ The loss ratio is defined generally as expenses divided by revenue.
53
+
54
+ Parameters
55
+ ----------
56
+ expenses:
57
+ Claims, losses, benefits, or other expense amount.
58
+ revenue:
59
+ Premium, earned premium, revenue, or other denominator amount.
60
+
61
+ Returns
62
+ -------
63
+ Any
64
+ Loss ratio as a decimal.
65
+
66
+ Examples
67
+ --------
68
+ >>> loss_ratio(850_000, 1_000_000)
69
+ 0.85
70
+ """
71
+ return safe_divide(expenses, revenue)
@@ -0,0 +1,48 @@
1
+ [build-system]
2
+ requires = ["hatchling"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "actuarialpy"
7
+ version = "0.1.0"
8
+ description = "Python tools for actuarial analysis."
9
+ readme = "README.md"
10
+ requires-python = ">=3.9"
11
+ license = "MIT"
12
+ authors = [
13
+ { name = "Michael Bryant" }
14
+ ]
15
+ keywords = [
16
+ "actuarial",
17
+ "insurance",
18
+ "loss ratio",
19
+ "risk",
20
+ "analytics"
21
+ ]
22
+ classifiers = [
23
+ "Development Status :: 3 - Alpha",
24
+ "Intended Audience :: Financial and Insurance Industry",
25
+ "Intended Audience :: Science/Research",
26
+ "License :: OSI Approved :: MIT License",
27
+ "Programming Language :: Python :: 3",
28
+ "Programming Language :: Python :: 3.9",
29
+ "Programming Language :: Python :: 3.10",
30
+ "Programming Language :: Python :: 3.11",
31
+ "Programming Language :: Python :: 3.12",
32
+ "Topic :: Office/Business :: Financial",
33
+ "Topic :: Scientific/Engineering :: Mathematics"
34
+ ]
35
+ dependencies = [
36
+ "numpy>=1.23"
37
+ ]
38
+
39
+ [project.urls]
40
+ Homepage = "https://github.com/actuarialpy/actuarialpy-core"
41
+ Repository = "https://github.com/actuarialpy/actuarialpy-core"
42
+ Issues = "https://github.com/actuarialpy/actuarialpy-core/issues"
43
+
44
+ [tool.hatch.build.targets.wheel]
45
+ packages = ["actuarialpy"]
46
+
47
+ [tool.pytest.ini_options]
48
+ testpaths = ["tests"]
@@ -0,0 +1,23 @@
1
+ import numpy as np
2
+
3
+ from actuarialpy import loss_ratio, safe_divide
4
+
5
+
6
+ def test_safe_divide_scalar():
7
+ assert safe_divide(10, 2) == 5
8
+
9
+
10
+ def test_safe_divide_zero_denominator():
11
+ assert np.isnan(safe_divide(10, 0))
12
+
13
+
14
+ def test_loss_ratio_scalar():
15
+ assert loss_ratio(850_000, 1_000_000) == 0.85
16
+
17
+
18
+ def test_loss_ratio_array():
19
+ result = loss_ratio([50, 80, 100], [100, 100, 0])
20
+
21
+ assert result[0] == 0.5
22
+ assert result[1] == 0.8
23
+ assert np.isnan(result[2])