Skip to content

Commit 43a9cde

Browse files
author
Juan Sabuco
committed
Premium monitor added.
1 parent b9137fd commit 43a9cde

File tree

2 files changed

+31
-8
lines changed

2 files changed

+31
-8
lines changed

insurancesimulation.py

+9
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,8 @@ def __init__(self, override_no_riskmodels, replic_ID, simulation_parameters):
138138
self.history_total_reincash = []
139139
self.history_total_reincontracts = []
140140
self.history_total_reinoperational = []
141+
142+
self.history_market_premium = []
141143

142144

143145
def build_agents(self, agent_class, agent_class_string, parameters, agent_parameters):
@@ -241,6 +243,7 @@ def save_data(self):
241243
self.history_total_reincash.append(total_reincash_no)
242244
self.history_total_reincontracts.append(total_reincontracts_no)
243245
self.history_total_reinoperational.append(reinoperational_no)
246+
self.history_market_premium.append(self.market_premium)
244247

245248
individual_contracts_no = [len(insurancefirm.underwritten_contracts) for insurancefirm in self.insurancefirms]
246249
for i in range(len(individual_contracts_no)):
@@ -433,6 +436,8 @@ def replication_log_prepare(self):
433436
to_log.append(("data/two_reinoperational.dat", self.history_total_reinoperational, "a"))
434437
to_log.append(("data/two_reincontracts.dat", self.history_total_reincontracts, "a"))
435438
to_log.append(("data/two_reincash.dat", self.history_total_reincash, "a"))
439+
to_log.append(("data/two_premium.dat", self.history_market_premium, "a"))
440+
436441
return to_log
437442

438443
def replication_log_prepare_oneriskmodel(self):
@@ -443,6 +448,8 @@ def replication_log_prepare_oneriskmodel(self):
443448
to_log.append(("data/one_reinoperational.dat", self.history_total_reinoperational, "a"))
444449
to_log.append(("data/one_reincontracts.dat", self.history_total_reincontracts, "a"))
445450
to_log.append(("data/one_reincash.dat", self.history_total_reincash, "a"))
451+
to_log.append(("data/one_premium.dat", self.history_market_premium, "a"))
452+
446453
return to_log
447454

448455
def single_log_prepare(self):
@@ -453,6 +460,8 @@ def single_log_prepare(self):
453460
to_log.append(("data/reinoperational.dat", self.history_total_reinoperational, "w"))
454461
to_log.append(("data/reincontracts.dat", self.history_total_reincontracts, "w"))
455462
to_log.append(("data/reincash.dat", self.history_total_reincash, "w"))
463+
to_log.append(("data/premium.dat", self.history_market_premium, "w"))
464+
456465
return to_log
457466

458467
#if __name__ == "__main__":

plotter.py

100644100755
+22-8
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,26 @@
2525
reincash = [eval(k) for k in rfile]
2626
rfile.close()
2727

28+
rfile = open("data/premium.dat","r")
29+
premium = [eval(k) for k in rfile]
30+
rfile.close()
31+
2832
c_s = []
2933

3034
o_s = []
3135

3236
h_s = []
3337

38+
p_s = []
39+
3440
c_re = []
3541

3642
o_re= []
3743

3844
h_re = []
3945

46+
p_e = []
47+
4048
for i in range(len(contracts[0])):
4149
cs = np.mean([item[i] for item in contracts])
4250
os = np.median([item[i] for item in op])
@@ -53,24 +61,30 @@
5361
o_re.append(ore)
5462
h_re.append(hre)
5563

64+
p_s = np.median([item[i] for item in premium])
65+
p_e.append(p_s)
66+
5667
fig = plt.figure()
57-
ax0 = fig.add_subplot(611)
68+
ax0 = fig.add_subplot(711)
5869
ax0.plot(range(len(c_s)), c_s,"b")
5970
ax0.set_ylabel("Contracts")
60-
ax1 = fig.add_subplot(612)
71+
ax1 = fig.add_subplot(712)
6172
ax1.plot(range(len(o_s)), o_s,"b")
62-
ax1.set_ylabel("Active firms (out of initially 20)")
63-
ax0 = fig.add_subplot(613)
73+
ax1.set_ylabel("Active firms")
74+
ax0 = fig.add_subplot(713)
6475
ax0.plot(range(len(h_s)), h_s,"b")
6576
ax0.set_ylabel("Cash")
66-
ax0 = fig.add_subplot(614)
77+
ax0 = fig.add_subplot(714)
6778
ax0.plot(range(len(c_re)), c_re,"r")
6879
ax0.set_ylabel("Contracts")
69-
ax1 = fig.add_subplot(615)
80+
ax1 = fig.add_subplot(715)
7081
ax1.plot(range(len(o_re)), o_re,"r")
71-
ax1.set_ylabel("Active reinfirms (out of initially 1)")
72-
ax0 = fig.add_subplot(616)
82+
ax1.set_ylabel("Active reinfirms")
83+
ax0 = fig.add_subplot(716)
7384
ax0.plot(range(len(h_re)), h_re,"r")
7485
ax0.set_ylabel("Cash")
86+
ax0 = fig.add_subplot(717)
87+
ax0.plot(range(len(p_e)), p_e,"k")
88+
ax0.set_ylabel("Premium")
7589
ax1.set_xlabel("Time")
7690
plt.show()

0 commit comments

Comments
 (0)