Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support ri_scope filter #1505

Merged
merged 6 commits into from
May 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 12 additions & 7 deletions oasislmf/computation/generate/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,23 +384,28 @@ def run(self):
# Write the RI input files, and write the returned RI layer info. as a
# file, which can be reused by the model runner (in the model execution
# stage) to set the number of RI iterations
fm_summary_mapping['loc_id'] = fm_summary_mapping['loc_id'].astype(exposure_data.location.dataframe['loc_id'].dtype)
xref_descriptions_df = merge_oed_to_mapping(
fm_summary_mapping,
exposure_data.location.dataframe,
oed_column_set=[loc_grp],
defaults={loc_grp: 1}
).sort_values(by='agg_id')
['loc_id'], {'LocGroup': '', 'ReinsTag': '', 'CountryCode': ''})
xref_descriptions_df[['PortNumber', 'AccNumber', 'PolNumber']] = xref_descriptions_df[['PortNumber', 'AccNumber', 'PolNumber']].astype(str)
xref_descriptions_df = merge_oed_to_mapping(
xref_descriptions_df,
exposure_data.account.dataframe,
['PortNumber', 'AccNumber', 'PolNumber'], {'CedantName': '', 'ProducerName': '', 'LOB': ''})
xref_descriptions_df = xref_descriptions_df.sort_values(by='agg_id')

del fm_summary_mapping
self.kwargs['oed_info_csv'] = exposure_data.ri_info

ri_layers = write_files_for_reinsurance(
gul_inputs_df,
xref_descriptions_df,
exposure_data.ri_info.dataframe,
exposure_data.ri_scope.dataframe,
oasis_files['fm_xref'],
xref_descriptions_df,
target_dir,
self.write_ri_tree
oasis_files['fm_xref'],
self.logger
)

with io.open(os.path.join(target_dir, 'ri_layers.json'), 'w', encoding='utf-8') as f:
Expand Down
147 changes: 0 additions & 147 deletions oasislmf/preparation/oed.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@
'load_oed_dfs',
'OedValidator'
]

import math
import os

from collections import namedtuple
from ods_tools.oed import fill_empty

from ..utils.data import get_dataframe, RI_INFO_DEFAULTS, RI_SCOPE_DEFAULTS
Expand Down Expand Up @@ -436,147 +433,3 @@ def load_oed_dfs(oed_ri_info_file, oed_ri_scope_file, show_all=False):
'ReinsTag',
'CededPercent'
]

InuringLayer = namedtuple(
"InuringLayer",
"inuring_priority reins_numbers is_valid validation_messages")
Item = namedtuple(
"Item", "item_id coverage_id areaperil_id vulnerability_id group_id")
Coverage = namedtuple(
"Coverage", "coverage_id tiv")
FmProgramme = namedtuple(
"FmProgramme", "from_agg_id level_id to_agg_id")
FmProfile = namedtuple(
"FmProfile", "profile_id calcrule_id deductible1 deductible2 deductible3 attachment limit share1 share2 share3")
FmPolicyTc = namedtuple(
"FmPolicyTc", "layer_id level_id agg_id profile_id")
GulSummaryXref = namedtuple(
"GulSummaryXref", "coverage_id summary_id summaryset_id")
FmSummaryXref = namedtuple(
"FmSummaryXref", "output_id summary_id summaryset_id")
FmXref = namedtuple(
"FmXref", "output_id agg_id layer_id")

XrefDescription = namedtuple(
"Description",
(
"xref_id portfolio_number policy_number account_number location_number location_group "
"cedant_name producer_name lob country_code reins_tag coverage_type_id peril_id tiv"
)
)
GulRecord = namedtuple("GulRecord", "event_id item_id sidx loss")


def get_no_loss_profile(profile_id):
return FmProfile(
profile_id=profile_id,
calcrule_id=CALCRULE_ID_LIMIT_ONLY,
deductible1=0.0, # Not used
deductible2=0.0, # Not used
deductible3=0.0, # Not used
attachment=0.0, # Not used
limit=0.0,
share1=0.0, # Not used
share2=0.0, # Not used
share3=0.0 # Not used
)


def get_pass_through_profile(profile_id):
return FmProfile(
profile_id=profile_id,
calcrule_id=CALCRULE_ID_DEDUCTIBLE_ONLY,
deductible1=0.0,
deductible2=0.0, # Not used
deductible3=0.0, # Not used
attachment=0.0, # Not used
limit=0.0, # Not used
share1=0.0, # Not used
share2=0.0, # Not used
share3=0.0 # Not used
)


def get_profile(
profile_id,
deductible=0,
attachment=0,
limit=0,
share=1.0
):

if limit == 0:
limit = LARGE_VALUE

return FmProfile(
profile_id=profile_id,
calcrule_id=CALCRULE_ID_DEDUCTIBLE_ATTACHMENT_LIMIT_AND_SHARE,
deductible1=deductible,
deductible2=0.0, # Not used
deductible3=0.0, # Not used
attachment=attachment,
limit=limit,
share1=share,
share2=0.0, # Not used
share3=0.0 # Not used
)


def _value_is_empty(value):
return (value == "" or value is None or math.isnan(value))


def get_reinsurance_profile(
profile_id,
attachment=0.0,
limit=0.0,
ceded=1.0,
placement=1.0
):

if _value_is_empty(attachment):
attachment = 0.0
if _value_is_empty(limit) or limit == 0:
limit = LARGE_VALUE
if _value_is_empty(ceded):
ceded = 1.0
if _value_is_empty(placement):
placement = 1.0

return FmProfile(
profile_id=profile_id,
calcrule_id=CALCRULE_ID_OCCURRENCE_CATASTROPHE_EXCESS_OF_LOSS,
deductible1=0.0, # Not used
deductible2=0.0, # Not used
deductible3=0.0, # Not used
attachment=attachment,
limit=limit,
share1=ceded,
share2=placement, # PlacementPercent
share3=1.0 # Not used
)


def get_occlim_profile(
profile_id,
attachment=0.0,
limit=0.0,
ceded=1.0,
placement=1.0
):

if limit == 0:
limit = LARGE_VALUE

return FmProfile(
profile_id=profile_id,
calcrule_id=CALCRULE_ID_OCCURRENCE_LIMIT_AND_SHARE,
deductible1=0, # Not used
deductible2=0, # Not used
deductible3=0, # Not used
attachment=attachment,
limit=limit,
share1=0, # Not used
share2=placement, # Not used
share3=1.0 # Not used
)