actuarialpy 0.1.0__py3-none-any.whl
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.
actuarialpy/__init__.py
ADDED
actuarialpy/metrics.py
ADDED
|
@@ -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,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,6 @@
|
|
|
1
|
+
actuarialpy/__init__.py,sha256=9OdnPR4BOVVUkMs6lKrys9vis616y9v0NQvu29c5y3o,177
|
|
2
|
+
actuarialpy/metrics.py,sha256=6nzcb0X2X2bAhv7QqZno9vQ03stAtjzoSuX8fBtJ81g,1653
|
|
3
|
+
actuarialpy-0.1.0.dist-info/METADATA,sha256=6E6itgqmjvxHdaSXh0DUsdw-EW2afKHhmWoy1aGoLoU,2164
|
|
4
|
+
actuarialpy-0.1.0.dist-info/WHEEL,sha256=mffPy8wBnZQn2VnJUU5jE99KsxaSfiyMHV9Yt0aLVxs,87
|
|
5
|
+
actuarialpy-0.1.0.dist-info/licenses/LICENSE,sha256=-q9I9w9-Kw_eSDpU6vTmwX3yL6b4YeaBcSMV3yXeaf4,1151
|
|
6
|
+
actuarialpy-0.1.0.dist-info/RECORD,,
|
|
@@ -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.
|