Skip to content

Commit

Permalink
instrument statistics on risky expectations daily and add final value…
Browse files Browse the repository at this point in the history
… to sim_stats see #220
  • Loading branch information
sbenthall committed Jun 27, 2023
1 parent 8c427e7 commit ab69829
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions sharkfin/simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -750,6 +750,12 @@ def __init__(
for agent in self.pop.agents:
agent.macro_day = self.rng.integers(self.days_per_quarter)

# Additional daily values tracked.
self.history["RiskyAvg_mean"] = []
self.history["RiskyAvg_std"] = []
self.history["RiskyStd_mean"] = []
self.history["RiskyStd_std"] = []

def simulate(self, quarters=None, start=True, burn_in=None):
"""
Workhorse method that runs the simulation.
Expand Down Expand Up @@ -870,6 +876,12 @@ def sim_stats(self):
if self.seed is not None:
sim_stats["seed"] = self.seed


sim_stats['Expectations_RiskyAvg_mean_final'] = self.history["RiskyAvg_mean"][-1]
sim_stats["Expectations_RiskyAvg_std_final"] = self.history["RiskyAvg_std"][-1]
sim_stats["Expectations_RiskyStd_mean_final"] = self.history["RiskyStd_mean"][-1]
sim_stats["Expectations_RiskyStd_std_final"] = self.history["RiskyStd_std"][-1]

return sim_stats

def report_class_stats(self, stat="aLvl", stat_history=None):
Expand All @@ -884,6 +896,22 @@ def report_class_stats(self, stat="aLvl", stat_history=None):
ax = sns.lineplot(data=data, x="time", y="aLvl_mean", hue="label")
ax.set_title("mean aLvl by class subpopulation")

def track(self, day, time_delta=0):
"""
Tracks the current state of agent's total assets and owned shares
"""
super().track(
day,
time_delta
)

RiskyAvg_all_agents = np.array([agent.parameters['RiskyAvg'] for agent in self.pop.agents])
RiskyStd_all_agents = np.array([agent.parameters['RiskyStd'] for agent in self.pop.agents])

self.history["RiskyAvg_mean"].append(np.mean(RiskyAvg_all_agents))
self.history["RiskyAvg_std"].append(np.std(RiskyAvg_all_agents))
self.history["RiskyStd_mean"].append(np.mean(RiskyStd_all_agents))
self.history["RiskyStd_std"].append(np.std(RiskyStd_all_agents))

class CalibrationSimulation(MarketSimulation):
"""
Expand Down

0 comments on commit ab69829

Please sign in to comment.