oasislmf.preparation.il_inputs¶
Functions¶
|
Merges IL inputs with the correct calc_rule table and returns calc rule IDs. |
|
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.
- Parameters:
il_inputs_calc_rules_df (pandas.DataFrame) – IL input items dataframe.
calc_rule_type (str) – Type of calc_rule to look for.
- Returns:
Series of calculation rule IDs.
- Return type:
pandas.Series
- 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:¶
SETUP: Prepare data structures, merge account IDs, handle step policies
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
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
- param gul_inputs_df:
GUL input items with columns including item_id, loc_id, coverage_type_id, tiv, peril_id, building_id, etc.
- type gul_inputs_df:
pandas.DataFrame
- param exposure_data:
OedExposure object containing location and account DataFrames with policy terms (deductibles, limits, shares, layers).
- param target_dir:
Directory path where FM output files will be written.
- type target_dir:
str
- param logger:
Logger object for progress messages.
- param exposure_profile:
Maps OED fields to FM term types for locations.
- type exposure_profile:
dict, optional
- param accounts_profile:
Maps OED fields to FM term types for accounts.
- type accounts_profile:
dict, optional
- param fm_aggregation_profile:
Defines aggregation keys for each FM level.
- type fm_aggregation_profile:
dict, optional
- param do_disaggregation:
If True, split aggregate exposure terms by NumberOfRisks. Default True.
- type do_disaggregation:
bool, optional
- param oasis_files_prefixes:
File name prefixes for output files.
- type oasis_files_prefixes:
dict, optional
- param chunksize:
Rows per chunk when writing CSVs. Default 200,000.
- type chunksize:
int, optional
- param intermediary_csv:
If True, also write CSV files alongside binary for debugging. Defaults to False.
- type intermediary_csv:
bool, optional
- returns:
- IL inputs with columns including output_id, layer_id,
gul_input_id, agg_id, PolNumber, acc_idx, and summary columns.
- rtype:
pandas.DataFrame