Cell and Metadata classes

Cell

class bermuda.base.cell.Cell(period_start: date, period_end: date, evaluation_date: date, values: dict[str, float | int | ndarray | float64 | int64 | None], metadata: Metadata = None, _skip_validation: bool = False)

Base class for all elements contained within `Triangle`s.

period_start

The beginning of the experience period.

period_end

The end of the experience period (as a closed interval).

evaluation_date

The date when the information was known.

values

dictionary with key-value pairs of fields and values. For example: {“paid_loss”: 123400, “earned_premium”: 2345000}

metadata

Other metadata about the Cell.

add_statics(source_cell, fields) Cell

Add new static fields (e.g., earned_premium) to a cell.

property coordinates: Tuple[date, date, date]

period_start, period_end, evaluation_date.

Type:

Location of the cell

derive_fields(**definitions: Callable[[Cell], Any] | Any) Cell

Add new derived fields to a cell.

Parameters:

**definitions – Values are functions that accept a Cell and return a value, and keys are the names that the function values will be assigned to.

Examples

>>> ob = Cell(
...     period_start=0,
...     period_end=1,
...     values={
...         "loss": 10,
...         "premium": 50,
...     },
... )
>>> new_ob = ob.derive_fields(
...     loss_ratio=lambda c: c[
...         "loss"
...     ]
...     / c["premium"]
... )
>>> new_ob.values
{"loss": 10, "premium": 50, "loss_ratio": 0.2}
derive_metadata(**definitions: Callable[[Cell], Any] | Any) Cell

Add new derived attributes to a Cell’s metadata.

Parameters:

**definitions – Values are plain values or functions that accept a Cell and return a value. If keys are top-level attributes in metadata, their values will replace the existing values of the top-level attributes. Otherwise, the key-value pair will be added to the details field of the metadata.

dev_lag(unit: str = 'months') float | int | timedelta

Compute the development lag of the cell in the specified units.

Parameters:

unit (str) – One of ‘month’, ‘day’, ‘timedelta’. ‘month’ returns dev_lag as a float number of months, day returns dev_lag as an integer number of days, and ‘timedelta’ returns a datetime.timedelta object.

property period_length: int

The length of the cell experience period, in months.

replace(**definitions: Callable[[Cell], Any] | Any) Cell

Override values of arbitary fields with constants or functions. Calls _base_replace internally. Only validates the final cell once all replacements have been made.

select(keys: list[str]) Cell

Retain only the designated keys in values.

to_record(dev_lag_unit='month') dict[str, Any]

Return dict representation of Cell.

IncrementalCell and CumulativeCell

class bermuda.base.incremental.CumulativeCell(period_start: date, period_end: date, evaluation_date: date, values: dict[str, float | int | ndarray | float64 | int64 | None], metadata: Metadata = None, _skip_validation: bool = False)

Subclass for cumulative cells.

The base Cell class is already cumulative, so this subclass mostly exists for the sake of the type system. Cell implies cumulative or incremental; CumulativeCell implies that it doesn’t work with incremental cells.

class bermuda.base.incremental.IncrementalCell(period_start: date, period_end: date, prev_evaluation_date: date, evaluation_date: date, values: dict[str, float | int | ndarray | float64 | int64 | None], metadata: Metadata = None, _skip_validation: bool = False)
property coordinates: Tuple[date, date, date, date]

period_start, period_end, evaluation_date, prev_evaluation_date.

Type:

Location of the cell

eval_lag(unit: str = 'months') float | int | timedelta

Compute the evaluation lag of the cell in the specified units.

Parameters:

unit (str) – One of ‘month’, ‘day’, ‘timedelta’. ‘month’ returns eval_lag as a float number of months, day returns dev_lag as an integer number of days, and ‘timedelta’ returns a datetime.timedelta object.

to_record(dev_lag_unit='month') dict[str, Any]

Return dict representation of Cell.

Metadata

class bermuda.base.metadata.Metadata(risk_basis: str = 'Accident', country: str | None = None, currency: str | None = None, reinsurance_basis: str | None = None, loss_definition: str | None = None, per_occurrence_limit: float | None = None, details: dict[str, str | float | int | bool | ~datetime.date | ~numpy.ndarray | None] = <factory>, loss_details: dict[str, str | float | int | bool | ~datetime.date | ~numpy.ndarray | None] = <factory>)

Metadata about the information stored in `Cell`s.

risk_basis

The basis on which risks are assigned to experience periods. Common values are “Accident” and “Policy”.

Type:

str

country

The country where the risks are domiciled, as an ISO 3166 alpha-2 code (e.g., “US”, “ES”, “DE”).

Type:

str | None

currency

The currency in which premium and losses are denominated, as an ISO 4217 code (e.g., “USD”, “GBP”, “JPY”).

Type:

str | None

reinsurance_basis

Whether the losses are net of reinsurance. Typical values are “Gross” and “Net”; the field is typed as a str and not a bool to allow for more nuanced gradations of value.

Type:

str | None

loss_definition

The portions of loss costs and expenses that are included in loss amounts. Typical values are “Loss”, “Loss+DCC”, and “Loss+LAE”.

Type:

str | None

per_occurrence_limit

The per-occurrence limit on individual losses.

Type:

float | None

details

Other information about the data represented in the Cell. For example, details could plausibly include coverage, rated state, or product code.

Type:

dict[str, str | float | int | bool | datetime.date | numpy.ndarray | None]

loss_details

Information about the data in the Cell that only pertains to the losses. For example, you may have a triangle where losses are segmented by cause of loss, but premium is not.

Type:

dict[str, str | float | int | bool | datetime.date | numpy.ndarray | None]

as_flat_dict()

All metadata associated with the cell (currency, country, details, etc.)

bermuda.base.metadata.common_metadata(meta1: Metadata, meta2: Metadata) Metadata

Return a Metadata object that has all elements that are identical in meta1 and meta2.

bermuda.base.metadata.metadata_diff(meta_core: Metadata, meta_diff: Metadata) Metadata

Return a Metadata object with all of the items in meta_diff that are not in meta_core.