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

[REFACTOR] Move metainsuranceorg.py to a folder agents/ #108

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
6 changes: 3 additions & 3 deletions catbond.py → agents/catbond.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
import isleconfig
import numpy as np
import scipy.stats
from insurancecontract import InsuranceContract
from reinsurancecontract import ReinsuranceContract
from metainsuranceorg import MetaInsuranceOrg
from contracts.insurancecontract import InsuranceContract
from contracts.reinsurancecontract import ReinsuranceContract
from agents.metainsuranceorg import MetaInsuranceOrg
from riskmodel import RiskModel
import sys, pdb
import uuid
Expand Down
File renamed without changes.
File renamed without changes.
6 changes: 3 additions & 3 deletions insurancefirm.py → agents/insurancefirm.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from metainsuranceorg import MetaInsuranceOrg
from catbond import CatBond
from agents.metainsuranceorg import MetaInsuranceOrg
from agents.catbond import CatBond
import numpy as np
from reinsurancecontract import ReinsuranceContract
from contracts.reinsurancecontract import ReinsuranceContract
import isleconfig

class InsuranceFirm(MetaInsuranceOrg):
Expand Down
19 changes: 4 additions & 15 deletions metainsuranceorg.py → agents/metainsuranceorg.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,16 @@
import numpy as np
import scipy.stats
import copy
from insurancecontract import InsuranceContract
from reinsurancecontract import ReinsuranceContract
from contracts import InsuranceContract, ReinsuranceContract
from riskmodel import RiskModel
import sys, pdb
import uuid

if isleconfig.use_abce:
from genericagentabce import GenericAgent
from agents.genericagentabce import GenericAgent
#print("abce imported")
else:
from genericagent import GenericAgent
from agents.genericagent import GenericAgent
#print("abce not imported")

def get_mean(x):
Expand Down Expand Up @@ -55,17 +54,7 @@ def init(self, simulation_parameters, agent_parameters):
self.cash_last_periods = list(np.zeros(4, dtype=int)*self.cash)

rm_config = agent_parameters['riskmodel_config']
self.riskmodel = RiskModel(damage_distribution=rm_config["damage_distribution"], \
expire_immediately=rm_config["expire_immediately"], \
cat_separation_distribution=rm_config["cat_separation_distribution"], \
norm_premium=rm_config["norm_premium"], \
category_number=rm_config["no_categories"], \
init_average_exposure=rm_config["risk_value_mean"], \
init_average_risk_factor=rm_config["risk_factor_mean"], \
init_profit_estimate=rm_config["norm_profit_markup"], \
margin_of_safety=rm_config["margin_of_safety"], \
var_tail_prob=rm_config["var_tail_prob"], \
inaccuracy=rm_config["inaccuracy_by_categ"])
self.riskmodel = RiskModel(**rm_config)

self.category_reinsurance = [None for i in range(self.simulation_no_risk_categories)]
if self.simulation_reinsurance_type == 'non-proportional':
Expand Down
4 changes: 2 additions & 2 deletions reinsurancefirm.py → agents/reinsurancefirm.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#from metainsuranceorg import MetaInsuranceOrg
from insurancefirm import InsuranceFirm
#from agents.metainsuranceorg import MetaInsuranceOrg
from agents.insurancefirm import InsuranceFirm

class ReinsuranceFirm(InsuranceFirm):
"""ReinsuranceFirm class.
Expand Down
2 changes: 2 additions & 0 deletions contracts/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from .insurancecontract import InsuranceContract
from .reinsurancecontract import ReinsuranceContract
2 changes: 1 addition & 1 deletion insurancecontract.py → contracts/insurancecontract.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import numpy as np

from metainsurancecontract import MetaInsuranceContract
from contracts.metainsurancecontract import MetaInsuranceContract


class InsuranceContract(MetaInsuranceContract):
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions reinsurancecontract.py → contracts/reinsurancecontract.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import numpy as np

from metainsurancecontract import MetaInsuranceContract
from contracts.metainsurancecontract import MetaInsuranceContract

class ReinsuranceContract(MetaInsuranceContract):
"""ReinsuranceContract class.
Expand Down Expand Up @@ -66,4 +66,4 @@ def mature(self, time):
if np.random.uniform(0,1,1) < 0.95:
reinrisk = self.property_holder.create_reinrisk(time,self.category)
if reinrisk is not None and hasattr(self.insurer, 'reinrisks_kept'):
self.insurer.reinrisks_kept.append(reinrisk)
self.insurer.reinrisks_kept.append(reinrisk)
51 changes: 20 additions & 31 deletions insurancesimulation.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from insurancefirm import InsuranceFirm
from agents.insurancefirm import InsuranceFirm
#from riskmodel import RiskModel
from reinsurancefirm import ReinsuranceFirm
from agents.reinsurancefirm import ReinsuranceFirm
from distributiontruncated import TruncatedDistWrapper
import numpy as np
import scipy.stats
Expand Down Expand Up @@ -123,18 +123,19 @@ def __init__(self, override_no_riskmodels, replic_ID, simulation_parameters, rc_

self.inaccuracy = random.sample(self.inaccuracy, self.simulation_parameters["no_riskmodels"])

risk_model_configurations = [{"damage_distribution": self.damage_distribution,
"expire_immediately": self.simulation_parameters["expire_immediately"],
"cat_separation_distribution": self.cat_separation_distribution,
"norm_premium": self.norm_premium,
"no_categories": self.simulation_parameters["no_categories"],
"risk_value_mean": risk_value_mean,
"risk_factor_mean": risk_factor_mean,
"norm_profit_markup": self.simulation_parameters["norm_profit_markup"],
"margin_of_safety": self.simulation_parameters["riskmodel_margin_of_safety"],
"var_tail_prob": self.simulation_parameters["value_at_risk_tail_probability"],
"inaccuracy_by_categ": self.inaccuracy[i]} \
for i in range(self.simulation_parameters["no_riskmodels"])]
risk_model_configurations = [
{"damage_distribution": self.damage_distribution,
"expire_immediately": self.simulation_parameters["expire_immediately"],
"cat_separation_distribution": self.cat_separation_distribution,
"norm_premium": self.norm_premium,
"category_number": self.simulation_parameters["no_categories"],
"init_average_exposure": risk_value_mean,
"init_average_risk_factor": risk_factor_mean,
"init_profit_estimate": self.simulation_parameters["norm_profit_markup"],
"margin_of_safety": self.simulation_parameters["riskmodel_margin_of_safety"],
"var_tail_prob": self.simulation_parameters["value_at_risk_tail_probability"],
"inaccuracy": self.inaccuracy[i]}
for i in range(self.simulation_parameters["no_riskmodels"])]

# prepare setting up agents (to be done from start.py)
self.agent_parameters = {"insurancefirm": [], "reinsurance": []} # TODO: rename reinsurance -> reinsurancefirm (also in start.py and below in method accept_agents
Expand Down Expand Up @@ -224,34 +225,22 @@ def build_agents(self, agent_class, agent_class_string, parameters, agent_parame
def accept_agents(self, agent_class_string, agents, agent_group=None, time=0):
# TODO: fix agent id's for late entrants (both firms and catbonds)
if agent_class_string == "insurancefirm":
try:
self.insurancefirms += agents
self.insurancefirms_group = agent_group
except:
print(sys.exc_info())
pdb.set_trace()
self.insurancefirms += agents
self.insurancefirms_group = agent_group
# fix self.history_logs['individual_contracts'] list
for agent in agents:
self.logger.add_insurance_agent()
# remove new agent cash from simulation cash to ensure stock flow consistency
new_agent_cash = sum([agent.cash for agent in agents])
self.reduce_money_supply(new_agent_cash)
elif agent_class_string == "reinsurance":
try:
self.reinsurancefirms += agents
self.reinsurancefirms_group = agent_group
except:
print(sys.exc_info())
pdb.set_trace()
self.reinsurancefirms += agents
self.reinsurancefirms_group = agent_group
# remove new agent cash from simulation cash to ensure stock flow consistency
new_agent_cash = sum([agent.cash for agent in agents])
self.reduce_money_supply(new_agent_cash)
elif agent_class_string == "catbond":
try:
self.catbonds += agents
except:
print(sys.exc_info())
pdb.set_trace()
self.catbonds += agents
else:
assert False, "Error: Unexpected agent class used {0:s}".format(agent_class_string)

Expand Down
4 changes: 2 additions & 2 deletions resume.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@
from abce import gui

from insurancesimulation import InsuranceSimulation
from insurancefirm import InsuranceFirm
from agents.insurancefirm import InsuranceFirm
from riskmodel import RiskModel
from reinsurancefirm import ReinsuranceFirm
from agents.reinsurancefirm import ReinsuranceFirm

# create conditional decorator
def conditionally(decorator_function, condition):
Expand Down
4 changes: 2 additions & 2 deletions start.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
override_no_riskmodels = False

from insurancesimulation import InsuranceSimulation
from insurancefirm import InsuranceFirm
from agents.insurancefirm import InsuranceFirm
from riskmodel import RiskModel
from reinsurancefirm import ReinsuranceFirm
from agents.reinsurancefirm import ReinsuranceFirm
import logger
import calibrationscore

Expand Down