Skip to content

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 exposure
  • Exposures: 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
class 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:
        _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:
        earned_exposure_value(analysis_date: date) -> float:
            Calculates the earned portion of the exposure value as of the given analysis date.
        written_exposure_value(analysis_date: date) -> float:
            Calculates the written exposure value as of the given analysis date.
    """

    def __init__(self, exposure_meta: ExposureMetaData, exposure_values: ExposureValues) -> None:
        """Initialize an Exposure instance.

        Args:
            exposure_meta (ExposureMetaData): Metadata describing the exposure period and characteristics.
            exposure_values (ExposureValues): Values associated with the exposure.
        """
        self._exposure_meta = exposure_meta
        self._exposure_values = exposure_values

    @property
    def exposure_meta(self) -> ExposureMetaData:
        """Get the metadata associated with this exposure.

        Returns:
            ExposureMetaData: The metadata object.
        """
        return self._exposure_meta

    @property
    def exposure_values(self) -> ExposureValues:
        """Get the values associated with this exposure.

        Returns:
            ExposureValues: The values object.
        """
        return self._exposure_values

    @property
    def modelling_year(self) -> int:
        """Get the modelling year for this exposure.

        Returns:
            int: The calendar year in which the exposure period starts.
        """
        return self._exposure_meta.exposure_period_start.year

    def _earned_pct(self, analysis_date: date) -> float:
        """Calculate the earned percentage of the exposure as of the given analysis date.

        Args:
            analysis_date (date): The date for which to calculate the earned percentage.

        Returns:
            float: The earned percentage (0.0 to 1.0). Returns 0.0 if the exposure term length is 0
                  or if the exposure is aggregate.
        """
        if self._exposure_meta.exposure_term_length_days == 0:
            return 0.0
        if self._exposure_meta.aggregate:  # No need for == True
            return 0.0  # TODO: Implement parallelogram method when handling aggregate exposures
        return min((analysis_date - self._exposure_meta.exposure_period_start).days / self._exposure_meta.exposure_term_length_days, 1.0)

    def earned_exposure_value(self, analysis_date: date) -> float:
        """Calculate the earned exposure value as of the given analysis date.

        Args:
            analysis_date (date): The date for which to calculate the earned exposure value.

        Returns:
            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.
        """
        if self._exposure_meta.exposure_type == ExposureBasis.EARNED:
            return self._exposure_values.exposure_value
        else:
            return self._exposure_values.exposure_value * self._earned_pct(analysis_date)

    def written_exposure_value(self, analysis_date: date) -> float:
        """Calculate the written exposure value as of the given analysis date.

        Args:
            analysis_date (date): The date for which to calculate the written exposure value.

        Returns:
            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.
        """
        if self._exposure_meta.exposure_type == ExposureBasis.EARNED:
            earned_pct = self._earned_pct(analysis_date)
            if earned_pct > 0:
                return self._exposure_values.exposure_value / earned_pct
            return self._exposure_values.exposure_value  # Avoid division by zero
        else:
            return self._exposure_values.exposure_value

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
def __init__(self, exposure_meta: ExposureMetaData, exposure_values: ExposureValues) -> None:
    """Initialize an Exposure instance.

    Args:
        exposure_meta (ExposureMetaData): Metadata describing the exposure period and characteristics.
        exposure_values (ExposureValues): Values associated with the exposure.
    """
    self._exposure_meta = exposure_meta
    self._exposure_values = exposure_values

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
def earned_exposure_value(self, analysis_date: date) -> float:
    """Calculate the earned exposure value as of the given analysis date.

    Args:
        analysis_date (date): The date for which to calculate the earned exposure value.

    Returns:
        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.
    """
    if self._exposure_meta.exposure_type == ExposureBasis.EARNED:
        return self._exposure_values.exposure_value
    else:
        return self._exposure_values.exposure_value * self._earned_pct(analysis_date)

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
def written_exposure_value(self, analysis_date: date) -> float:
    """Calculate the written exposure value as of the given analysis date.

    Args:
        analysis_date (date): The date for which to calculate the written exposure value.

    Returns:
        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.
    """
    if self._exposure_meta.exposure_type == ExposureBasis.EARNED:
        earned_pct = self._earned_pct(analysis_date)
        if earned_pct > 0:
            return self._exposure_values.exposure_value / earned_pct
        return self._exposure_values.exposure_value  # Avoid division by zero
    else:
        return self._exposure_values.exposure_value

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
class ExposureBasis(Enum):
    """Enumeration of exposure bases used in insurance calculations.

    Attributes:
        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.
    """

    EARNED = auto()
    WRITTEN = auto()

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
class ExposureMetaData:
    """Represents metadata for an insurance exposure, including identification, period, and classification details.

    Attributes:
        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.
    """
    def __init__(
        self,
        exposure_id: str,
        exposure_name: str,
        exposure_period_start: date,
        exposure_period_end: date,
        currency: str,
        aggregate: bool = False,
        line_of_business: Optional[str] = None,
        stacking_id: Optional[str] = None,
        exposure_type: Optional[ExposureBasis] = ExposureBasis.EARNED,
        location: Optional[str] = None,
        peril: Optional[str] = None,
        occupancy: Optional[str] = None
    ):
        """Initialize an ExposureMetaData instance.

        Args:
            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, optional): Indicates if the exposure is aggregated. Defaults to False.
            line_of_business (Optional[str], optional): Line of business. Defaults to None.
            stacking_id (Optional[str], optional): Identifier for stacking exposures. Defaults to None.
            exposure_type (Optional[ExposureBasis], optional): Type of exposure. Defaults to ExposureBasis.EARNED.
            location (Optional[str], optional): Location associated with the exposure. Defaults to None.
            peril (Optional[str], optional): Peril associated with the exposure. Defaults to None.
            occupancy (Optional[str], optional): Occupancy type for the exposure. Defaults to None.

        Raises:
            ValueError: If exposure_period_end is before exposure_period_start.
        """
        if exposure_period_end < exposure_period_start:
            raise ValueError("Exposure period end date cannot be before start date")

        self._exposure_id = exposure_id
        self._exposure_name = exposure_name
        self._exposure_period_start = exposure_period_start
        self._exposure_period_end = exposure_period_end
        self._currency = currency
        self._aggregate = aggregate
        self._line_of_business = line_of_business
        self._stacking_id = stacking_id
        self._exposure_type = exposure_type
        self._location = location
        self._peril = peril
        self._occupancy = occupancy

    @property
    def exposure_id(self) -> str:
        return self._exposure_id

    @exposure_id.setter
    def exposure_id(self, value: str) -> None:
        self._exposure_id = value

    @property
    def exposure_name(self) -> str:
        return self._exposure_name

    @exposure_name.setter
    def exposure_name(self, value: str) -> None:
        self._exposure_name = value

    @property
    def exposure_period_start(self) -> date:
        return self._exposure_period_start

    @exposure_period_start.setter
    def exposure_period_start(self, value: date) -> None:
        """Set the exposure period start date.

        Args:
            value (date): The new start date.

        Raises:
            ValueError: If the new start date is after the current end date.
        """
        if hasattr(self, '_exposure_period_end') and value > self._exposure_period_end:
            raise ValueError("Exposure period start date cannot be after end date")
        self._exposure_period_start = value

    @property
    def exposure_period_end(self) -> date:
        return self._exposure_period_end

    @exposure_period_end.setter
    def exposure_period_end(self, value: date) -> None:
        """Set the exposure period end date.

        Args:
            value (date): The new end date.

        Raises:
            ValueError: If the new end date is before the current start date.
        """
        if hasattr(self, '_exposure_period_start') and value < self._exposure_period_start:
            raise ValueError("Exposure period end date cannot be before start date")
        self._exposure_period_end = value

    @property
    def currency(self) -> str:
        return self._currency

    @currency.setter
    def currency(self, value: str) -> None:
        self._currency = value

    @property
    def aggregate(self) -> bool:
        return self._aggregate

    @aggregate.setter
    def aggregate(self, value: bool) -> None:
        self._aggregate = value

    @property
    def line_of_business(self) -> Optional[str]:
        return self._line_of_business

    @line_of_business.setter
    def line_of_business(self, value: Optional[str]) -> None:
        self._line_of_business = value

    @property
    def stacking_id(self) -> Optional[str]:
        return self._stacking_id

    @stacking_id.setter
    def stacking_id(self, value: Optional[str]) -> None:
        self._stacking_id = value

    @property
    def exposure_type(self) -> ExposureBasis:
        return self._exposure_type

    @exposure_type.setter
    def exposure_type(self, value: ExposureBasis) -> None:
        self._exposure_type = value

    @property
    def location(self) -> Optional[str]:
        return self._location

    @location.setter
    def location(self, value: Optional[str]) -> None:
        self._location = value

    @property
    def peril(self) -> Optional[str]:
        return self._peril

    @peril.setter
    def peril(self, value: Optional[str]) -> None:
        self._peril = value

    @property
    def occupancy(self) -> Optional[str]:
        return self._occupancy

    @occupancy.setter
    def occupancy(self, value: Optional[str]) -> None:
        self._occupancy = value
    @property
    def exposure_term_length_days(self) -> int:
        return (self.exposure_period_end - self.exposure_period_start).days

__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
def __init__(
    self,
    exposure_id: str,
    exposure_name: str,
    exposure_period_start: date,
    exposure_period_end: date,
    currency: str,
    aggregate: bool = False,
    line_of_business: Optional[str] = None,
    stacking_id: Optional[str] = None,
    exposure_type: Optional[ExposureBasis] = ExposureBasis.EARNED,
    location: Optional[str] = None,
    peril: Optional[str] = None,
    occupancy: Optional[str] = None
):
    """Initialize an ExposureMetaData instance.

    Args:
        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, optional): Indicates if the exposure is aggregated. Defaults to False.
        line_of_business (Optional[str], optional): Line of business. Defaults to None.
        stacking_id (Optional[str], optional): Identifier for stacking exposures. Defaults to None.
        exposure_type (Optional[ExposureBasis], optional): Type of exposure. Defaults to ExposureBasis.EARNED.
        location (Optional[str], optional): Location associated with the exposure. Defaults to None.
        peril (Optional[str], optional): Peril associated with the exposure. Defaults to None.
        occupancy (Optional[str], optional): Occupancy type for the exposure. Defaults to None.

    Raises:
        ValueError: If exposure_period_end is before exposure_period_start.
    """
    if exposure_period_end < exposure_period_start:
        raise ValueError("Exposure period end date cannot be before start date")

    self._exposure_id = exposure_id
    self._exposure_name = exposure_name
    self._exposure_period_start = exposure_period_start
    self._exposure_period_end = exposure_period_end
    self._currency = currency
    self._aggregate = aggregate
    self._line_of_business = line_of_business
    self._stacking_id = stacking_id
    self._exposure_type = exposure_type
    self._location = location
    self._peril = peril
    self._occupancy = occupancy

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
class ExposureValues:
    """Represents the key financial values associated with an insurance exposure.

    Attributes:
        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.
    """
    def __init__(self, exposure_value: float, attachment_point: float, limit: float):
        """Initialize an ExposureValues instance.

        Args:
            exposure_value (float): The total value of the exposure.
            attachment_point (float): The threshold amount at which coverage begins to apply.
            limit (float): The maximum amount payable under the coverage.

        Raises:
            ValueError: If attachment_point or limit is negative.
        """
        if attachment_point < 0:
            raise ValueError("Attachment point cannot be negative")
        if limit < 0:
            raise ValueError("Limit cannot be negative")

        self._exposure_value = exposure_value
        self._attachment_point = attachment_point
        self._limit = limit

    @property
    def exposure_value(self) -> float:
        return self._exposure_value

    @exposure_value.setter
    def exposure_value(self, value: float) -> None:
        self._exposure_value = value

    @property
    def attachment_point(self) -> float:
        return self._attachment_point

    @attachment_point.setter
    def attachment_point(self, value: float) -> None:
        """Set the attachment point.

        Args:
            value (float): The new attachment point.

        Raises:
            ValueError: If the new attachment point is negative.
        """
        if value < 0:
            raise ValueError("Attachment point cannot be negative")
        self._attachment_point = value

    @property
    def limit(self) -> float:
        return self._limit

    @limit.setter
    def limit(self, value: float) -> None:
        """Set the limit.

        Args:
            value (float): The new limit.

        Raises:
            ValueError: If the new limit is negative.
        """
        if value < 0:
            raise ValueError("Limit cannot be negative")
        self._limit = value

__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
def __init__(self, exposure_value: float, attachment_point: float, limit: float):
    """Initialize an ExposureValues instance.

    Args:
        exposure_value (float): The total value of the exposure.
        attachment_point (float): The threshold amount at which coverage begins to apply.
        limit (float): The maximum amount payable under the coverage.

    Raises:
        ValueError: If attachment_point or limit is negative.
    """
    if attachment_point < 0:
        raise ValueError("Attachment point cannot be negative")
    if limit < 0:
        raise ValueError("Limit cannot be negative")

    self._exposure_value = exposure_value
    self._attachment_point = attachment_point
    self._limit = limit

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
class 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:
        exposures (List[Exposure]): The list of Exposure objects managed by this container.

    Args:
        exposures (List[Exposure]): A list of Exposure objects to initialize the container.

    Methods:
        append(exposure: Exposure): Appends an Exposure object to the collection.
        __getitem__(key): 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.
    """

    def __init__(self, exposures: List[Exposure])->None:
        self._exposures = exposures

    @property
    def exposures(self) -> List[Exposure]:
        """Returns the list of Exposure objects managed by this container."""
        return self._exposures

    @exposures.setter
    def exposures(self, list_of_exposure_classes: List[Exposure]) -> None:
        """Sets the list of Exposure objects managed by this container."""
        self._exposures = list_of_exposure_classes

    @property
    def modelling_years(self) -> List[int]: 
        """
        Returns a sorted list of unique modelling years for all exposures.

        Returns:
            List[int]: A sorted list of unique modelling years.
        """
        years = {exposure.modelling_year for exposure in self.exposures}
        return sorted(years)

    def append(self, exposure: Exposure) -> None:
        """Append an Exposure object to the collection.

        Args:
            exposure (Exposure): The Exposure object to append.
        """
        self._exposures.append(exposure)

    def __getitem__(self, key):
        """Get an Exposure object by index or a slice of Exposures.

        Args:
            key: An integer index or a slice object.

        Returns:
            Union[Exposure, 'Exposures']: An Exposure object if key is an integer,
                                         or a new Exposures instance if key is a slice.
        """
        if isinstance(key, slice):
            cls = type(self)
            return cls(self._exposures[key])
        index = operator.index(key)
        return self._exposures[index]

    def __iter__(self):
        """Return an iterator over the exposures.

        Returns:
            Iterator[Exposure]: An iterator over the Exposure objects.
        """
        return iter(self._exposures)

    def __len__(self) -> int:
        """Return the number of exposures in the collection.

        Returns:
            int: The number of Exposure objects.
        """
        return len(self._exposures)

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
def __getitem__(self, key):
    """Get an Exposure object by index or a slice of Exposures.

    Args:
        key: An integer index or a slice object.

    Returns:
        Union[Exposure, 'Exposures']: An Exposure object if key is an integer,
                                     or a new Exposures instance if key is a slice.
    """
    if isinstance(key, slice):
        cls = type(self)
        return cls(self._exposures[key])
    index = operator.index(key)
    return self._exposures[index]

__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
def __iter__(self):
    """Return an iterator over the exposures.

    Returns:
        Iterator[Exposure]: An iterator over the Exposure objects.
    """
    return iter(self._exposures)

__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
def __len__(self) -> int:
    """Return the number of exposures in the collection.

    Returns:
        int: The number of Exposure objects.
    """
    return len(self._exposures)

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
def append(self, exposure: Exposure) -> None:
    """Append an Exposure object to the collection.

    Args:
        exposure (Exposure): The Exposure object to append.
    """
    self._exposures.append(exposure)