oasislmf.preparation.il_inputs

Functions

get_calc_rule_ids(il_inputs_calc_rules_df, calc_rule_type)

Merges IL inputs with the correct calc_rule table and returns calc rule IDs.

get_il_input_items(gul_inputs_df, exposure_data, ...)

Generates IL (Insured Loss) input items by applying financial terms to GUL items.

Module Contents

oasislmf.preparation.il_inputs.get_calc_rule_ids(il_inputs_calc_rules_df, calc_rule_type)[source]

Merges IL inputs with the correct calc_rule table and returns calc rule IDs.

Args:

il_inputs_calc_rules_df (pandas.DataFrame): IL input items dataframe. calc_rule_type (str): Type of calc_rule to look for.

Returns:

pandas.Series: Series of calculation rule IDs.

oasislmf.preparation.il_inputs.get_il_input_items(gul_inputs_df, exposure_data, target_dir, logger, exposure_profile=get_default_exposure_profile(), accounts_profile=get_default_accounts_profile(), fm_aggregation_profile=get_default_fm_aggregation_profile(), do_disaggregation=True, oasis_files_prefixes=OASIS_FILES_PREFIXES['il'], chunksize=2 * 10**5, intermediary_csv=False)[source]

Generates IL (Insured Loss) input items by applying financial terms to GUL items.

This function builds the Financial Module (FM) structure by processing insurance policy terms across multiple hierarchical levels. It takes GUL (Ground-Up Loss) items and enriches them with policy terms (deductibles, limits, shares) from location and account data.

Overview of Processing Flow:

  1. SETUP: Prepare data structures, merge account IDs, handle step policies

  2. LEVEL PROCESSING: For each FM level (site coverage -> policy layer): a. Extract terms from location/account data for this level b. Compute aggregation IDs (agg_id) based on aggregation keys c. Calculate TIV (Total Insured Value) for percentage-based terms d. Assign calculation rules and profile IDs e. Merge terms back to gul_inputs_df (handling layered/non-layered separately) f. Write level data to FM output files

  3. FINALIZE: Assign output IDs, fill missing PolNumbers, write fm_xref

Key Data Structures:

  • gul_inputs_df: Main working DataFrame, starts with GUL items and accumulates FM columns (agg_id, layer_id, profile_id, level_id) as levels are processed. Each row represents an item that will flow through the FM calculation.

  • level_df: Terms extracted from location/account data for the current level. Contains financial terms (deductible, limit, share) and is merged into gul_inputs_df after profile IDs are assigned.

  • agg_id: Aggregation ID - groups items that share the same financial terms at each level. Computed using groupby().ngroup() on aggregation keys.

  • layer_id: Distinguishes policy layers (1 = base, 2+ = excess layers). Rows start with layer_id=0 (unassigned) and get layer_id from level_df merge.

Layered vs Non-Layered Processing:

When merging level_df terms into gul_inputs_df, rows are handled differently:

  • Non-layered rows (layer_id == 0): Have not yet been assigned to a layer. Must NOT merge on layer_id column, as they need to pick up layer info from level_df. After merge, they may expand into multiple rows (one per layer).

  • Layered rows (layer_id > 0): Already assigned to a specific layer from a previous level. Must merge on layer_id to preserve their layer assignment.

After merging, “premature layering” is removed: if rows differ only by layer_id but have identical financial terms (same profile_id), duplicates are dropped. This prevents unnecessary row multiplication when layers don’t differ.

Output Files Written:

  • fm_policytc.csv: Maps (level_id, agg_id, layer_id) -> profile_id

  • fm_profile.csv: Profile definitions with calculation rules and term values

  • fm_programme.csv: Hierarchical structure linking levels (from_agg_id -> to_agg_id)

  • fm_xref.csv: Maps GUL item IDs to FM output IDs

Args:
gul_inputs_df (pandas.DataFrame): GUL input items with columns including

item_id, loc_id, coverage_type_id, tiv, peril_id, building_id, etc.

exposure_data: OedExposure object containing location and account DataFrames

with policy terms (deductibles, limits, shares, layers).

target_dir (str): Directory path where FM output files will be written. logger: Logger object for progress messages. exposure_profile (dict, optional): Maps OED fields to FM term types for locations. accounts_profile (dict, optional): Maps OED fields to FM term types for accounts. fm_aggregation_profile (dict, optional): Defines aggregation keys for each FM level. do_disaggregation (bool, optional): If True, split aggregate exposure terms

by NumberOfRisks. Default True.

oasis_files_prefixes (dict, optional): File name prefixes for output files. chunksize (int, optional): Rows per chunk when writing CSVs. Default 200,000. intermediary_csv (bool, optional): If True, also write CSV files alongside

binary for debugging. Defaults to False.

Returns:
pandas.DataFrame: IL inputs with columns including output_id, layer_id,

gul_input_id, agg_id, PolNumber, acc_idx, and summary columns.