Exposures Module
The Exposures module provides tools for managing and analyzing exposure data in reinsurance contexts. It includes classes for representing individual exposures, collections of exposures, and methods for calculating earned and written exposure values.
Core Classes
Exposures Data Structure
The module provides a hierarchical structure for representing exposures:
ExposureBasis: An enumeration defining different exposure bases (Earned, Written, etc.)ExposureMetaData: Contains metadata about an exposure (ID, name, dates, currency, etc.)ExposureValues: Contains financial values related to exposures (value, attachment point, limit)Exposure: Combines metadata and values for a single exposureExposures: A collection of Exposure objects with methods to access and manipulate them
Examples
Creating and Working with Exposures
from pyre.exposures.exposures import Exposure, Exposures, ExposureMetaData, ExposureValues, ExposureBasis
from datetime import date
# Create exposure metadata
metadata = ExposureMetaData(
exposure_id="EXP001",
exposure_name="Property Portfolio A",
exposure_period_start=date(2022, 1, 1),
exposure_period_end=date(2022, 12, 31),
currency="USD",
aggregate=False,
line_of_business="Property",
exposure_type=ExposureBasis.EARNED,
location="US East Coast",
peril="Hurricane"
)
# Create exposure values
values = ExposureValues(
exposure_value=10000000,
attachment_point=1000000,
limit=5000000
)
# Create an exposure
exposure = Exposure(metadata, values)
# Access exposure properties
print(f"Exposure ID: {exposure.exposure_meta.exposure_id}")
print(f"Exposure Name: {exposure.exposure_meta.exposure_name}")
print(f"Exposure Value: {exposure.exposure_values.exposure_value}")
print(f"Term Length (days): {exposure.exposure_meta.exposure_term_length_days()}")
# Calculate earned exposure as of a specific date
analysis_date = date(2022, 6, 30) # Mid-year
earned_value = exposure.earned_exposure_value(analysis_date)
print(f"Earned exposure as of {analysis_date}: {earned_value}")
# Calculate written exposure
written_value = exposure.written_exposure_value(analysis_date)
print(f"Written exposure as of {analysis_date}: {written_value}")
# Create a collection of exposures
exposures_collection = Exposures([exposure])
# Add another exposure
second_exposure = Exposure(
ExposureMetaData(
"EXP002",
"Property Portfolio B",
date(2022, 4, 1),
date(2023, 3, 31),
"EUR",
exposure_type=ExposureBasis.WRITTEN
),
ExposureValues(5000000, 500000, 2000000)
)
exposures_collection.append(second_exposure)
# Access exposures in the collection
for exp in exposures_collection:
print(f"Exposure {exp.exposure_meta.exposure_id} - "
f"Period: {exp.exposure_meta.exposure_period_start} to {exp.exposure_meta.exposure_period_end}")
# Get unique modelling years
print(f"Modelling years: {exposures_collection.modelling_years()}")
Working with Multiple Exposures
from pyre.exposures.exposures import Exposures
import pandas as pd
from datetime import date
# Assuming we have an Exposures collection called 'exposures_data'
# Calculate total earned exposure as of a specific date
analysis_date = date(2022, 12, 31)
total_earned = sum(exp.earned_exposure_value(analysis_date) for exp in exposures_data)
print(f"Total earned exposure as of {analysis_date}: {total_earned}")
# Group exposures by line of business
lob_exposures = {}
for exp in exposures_data:
lob = exp.exposure_meta.line_of_business
if lob not in lob_exposures:
lob_exposures[lob] = []
lob_exposures[lob].append(exp)
# Calculate earned exposure by line of business
for lob, exps in lob_exposures.items():
lob_earned = sum(exp.earned_exposure_value(analysis_date) for exp in exps)
print(f"Earned exposure for {lob}: {lob_earned}")
# Convert exposures to a pandas DataFrame for analysis
exposure_data = []
for exp in exposures_data:
exposure_data.append({
'id': exp.exposure_meta.exposure_id,
'name': exp.exposure_meta.exposure_name,
'lob': exp.exposure_meta.line_of_business,
'start_date': exp.exposure_meta.exposure_period_start,
'end_date': exp.exposure_meta.exposure_period_end,
'value': exp.exposure_values.exposure_value,
'earned_value': exp.earned_exposure_value(analysis_date)
})
df = pd.DataFrame(exposure_data)
print(df.head())
# Analyze exposures by various dimensions
print(f"Total exposure by LOB:\n{df.groupby('lob')['value'].sum()}")
print(f"Average exposure by LOB:\n{df.groupby('lob')['value'].mean()}")
API Reference
Exposure
Represents an insurance exposure with associated metadata and values.
This class encapsulates the metadata and values for a single exposure, providing methods to calculate earned exposure based on an analysis date.
Attributes:
| Name | Type | Description |
|---|---|---|
_exposure_meta |
ExposureMetaData
|
Metadata describing the exposure period and characteristics. |
_exposure_values |
ExposureValues
|
Values associated with the exposure. |
Properties
exposure_meta (ExposureMetaData): The metadata associated with this exposure. exposure_values (ExposureValues): The values associated with this exposure. modelling_year (int): The calendar year in which the exposure period starts.
Methods:
| Name | Description |
|---|---|
earned_exposure_value |
date) -> float: Calculates the earned portion of the exposure value as of the given analysis date. |
written_exposure_value |
date) -> float: Calculates the written exposure value as of the given analysis date. |
Source code in src\pyre\exposures\exposures.py
278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 | |
exposure_meta
property
Get the metadata associated with this exposure.
Returns:
| Name | Type | Description |
|---|---|---|
ExposureMetaData |
ExposureMetaData
|
The metadata object. |
exposure_values
property
Get the values associated with this exposure.
Returns:
| Name | Type | Description |
|---|---|---|
ExposureValues |
ExposureValues
|
The values object. |
modelling_year
property
Get the modelling year for this exposure.
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
The calendar year in which the exposure period starts. |
__init__(exposure_meta, exposure_values)
Initialize an Exposure instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
exposure_meta
|
ExposureMetaData
|
Metadata describing the exposure period and characteristics. |
required |
exposure_values
|
ExposureValues
|
Values associated with the exposure. |
required |
Source code in src\pyre\exposures\exposures.py
300 301 302 303 304 305 306 307 308 | |
earned_exposure_value(analysis_date)
Calculate the earned exposure value as of the given analysis date.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
analysis_date
|
date
|
The date for which to calculate the earned exposure value. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
float |
float
|
The earned exposure value. If the exposure type is EARNED, this is the full exposure value. Otherwise, it's the exposure value multiplied by the earned percentage. |
Source code in src\pyre\exposures\exposures.py
353 354 355 356 357 358 359 360 361 362 363 364 365 366 | |
written_exposure_value(analysis_date)
Calculate the written exposure value as of the given analysis date.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
analysis_date
|
date
|
The date for which to calculate the written exposure value. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
float |
float
|
The written exposure value. If the exposure type is EARNED, this is calculated by dividing the exposure value by the earned percentage. If the earned percentage is zero, returns the exposure value directly to avoid division by zero. |
Source code in src\pyre\exposures\exposures.py
368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 | |
ExposureBasis
Bases: Enum
Enumeration of exposure bases used in insurance calculations.
Attributes:
| Name | Type | Description |
|---|---|---|
EARNED |
Represents exposures that have been earned over a given period. |
|
WRITTEN |
Represents exposures that have been written (i.e., policies issued) during a given period. |
Source code in src\pyre\exposures\exposures.py
6 7 8 9 10 11 12 13 14 15 | |
ExposureMetaData
Represents metadata for an insurance exposure, including identification, period, and classification details.
Attributes:
| Name | Type | Description |
|---|---|---|
exposure_id |
str
|
Unique identifier for the exposure. |
exposure_name |
str
|
Human-readable name for the exposure. |
exposure_period_start |
date
|
Start date of the exposure period. |
exposure_period_end |
date
|
End date of the exposure period. |
currency |
str
|
Currency code associated with the exposure. |
aggregate |
bool
|
Indicates if the exposure is aggregated. Defaults to False. |
line_of_business |
Optional[str]
|
Line of business associated with the exposure. |
stacking_id |
Optional[str]
|
Identifier for stacking exposures. |
exposure_type |
Optional[ExposureBasis]
|
Type or basis of the exposure. Defaults to ExposureBasis.EARNED. |
location |
Optional[str]
|
Location associated with the exposure. |
peril |
Optional[str]
|
Peril associated with the exposure. |
occupancy |
Optional[str]
|
Occupancy type for the exposure. |
Properties
exposure_term_length_days (int): Number of days in the exposure period.
Source code in src\pyre\exposures\exposures.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 | |
__init__(exposure_id, exposure_name, exposure_period_start, exposure_period_end, currency, aggregate=False, line_of_business=None, stacking_id=None, exposure_type=ExposureBasis.EARNED, location=None, peril=None, occupancy=None)
Initialize an ExposureMetaData instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
exposure_id
|
str
|
Unique identifier for the exposure. |
required |
exposure_name
|
str
|
Human-readable name for the exposure. |
required |
exposure_period_start
|
date
|
Start date of the exposure period. |
required |
exposure_period_end
|
date
|
End date of the exposure period. |
required |
currency
|
str
|
Currency code associated with the exposure. |
required |
aggregate
|
bool
|
Indicates if the exposure is aggregated. Defaults to False. |
False
|
line_of_business
|
Optional[str]
|
Line of business. Defaults to None. |
None
|
stacking_id
|
Optional[str]
|
Identifier for stacking exposures. Defaults to None. |
None
|
exposure_type
|
Optional[ExposureBasis]
|
Type of exposure. Defaults to ExposureBasis.EARNED. |
EARNED
|
location
|
Optional[str]
|
Location associated with the exposure. Defaults to None. |
None
|
peril
|
Optional[str]
|
Peril associated with the exposure. Defaults to None. |
None
|
occupancy
|
Optional[str]
|
Occupancy type for the exposure. Defaults to None. |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If exposure_period_end is before exposure_period_start. |
Source code in src\pyre\exposures\exposures.py
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 | |
ExposureValues
Represents the key financial values associated with an insurance exposure.
Attributes:
| Name | Type | Description |
|---|---|---|
exposure_value |
float
|
The total value of the exposure, such as the insured amount. |
attachment_point |
float
|
The threshold amount at which coverage begins to apply. |
limit |
float
|
The maximum amount payable under the coverage. |
Source code in src\pyre\exposures\exposures.py
206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 | |
__init__(exposure_value, attachment_point, limit)
Initialize an ExposureValues instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
exposure_value
|
float
|
The total value of the exposure. |
required |
attachment_point
|
float
|
The threshold amount at which coverage begins to apply. |
required |
limit
|
float
|
The maximum amount payable under the coverage. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If attachment_point or limit is negative. |
Source code in src\pyre\exposures\exposures.py
214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 | |
Exposures
A container class for managing a collection of Exposure objects.
This class provides list-like behavior for storing and manipulating multiple Exposure instances. It supports indexing, slicing, iteration, and appending new exposures.
Attributes:
| Name | Type | Description |
|---|---|---|
exposures |
List[Exposure]
|
The list of Exposure objects managed by this container. |
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
exposures
|
List[Exposure]
|
A list of Exposure objects to initialize the container. |
required |
Methods:
| Name | Description |
|---|---|
append |
Exposure): Appends an Exposure object to the collection. |
__getitem__ |
Returns an Exposure or a new Exposures instance for slices. |
__iter__ |
Returns an iterator over the exposures. |
__len__ |
Returns the number of exposures in the collection. |
Source code in src\pyre\exposures\exposures.py
387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 | |
exposures
property
writable
Returns the list of Exposure objects managed by this container.
modelling_years
property
Returns a sorted list of unique modelling years for all exposures.
Returns:
| Type | Description |
|---|---|
List[int]
|
List[int]: A sorted list of unique modelling years. |
__getitem__(key)
Get an Exposure object by index or a slice of Exposures.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
An integer index or a slice object. |
required |
Returns:
| Type | Description |
|---|---|
|
Union[Exposure, 'Exposures']: An Exposure object if key is an integer, or a new Exposures instance if key is a slice. |
Source code in src\pyre\exposures\exposures.py
439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 | |
__iter__()
Return an iterator over the exposures.
Returns:
| Type | Description |
|---|---|
|
Iterator[Exposure]: An iterator over the Exposure objects. |
Source code in src\pyre\exposures\exposures.py
455 456 457 458 459 460 461 | |
__len__()
Return the number of exposures in the collection.
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
The number of Exposure objects. |
Source code in src\pyre\exposures\exposures.py
463 464 465 466 467 468 469 | |
append(exposure)
Append an Exposure object to the collection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
exposure
|
Exposure
|
The Exposure object to append. |
required |
Source code in src\pyre\exposures\exposures.py
431 432 433 434 435 436 437 | |