diff --git a/sharkfin/population.py b/sharkfin/population.py index c9105d7..b4f49ac 100644 --- a/sharkfin/population.py +++ b/sharkfin/population.py @@ -200,20 +200,36 @@ def class_stats(self, store=False): """ agent_data = self.agent_data().drop(columns="agents") - cs = ( - agent_data.groupby(self.ex_ante_hetero_params) - .aggregate(["mean", "std"]) - .reset_index() - ) + if self.ex_ante_hetero_params is None or len(self.ex_ante_hetero_params) == 0: + cs = agent_data.copy() + cs["aLvl_mean"] = agent_data["aLvl"] + cs["aLvl_std"] = 0 + cs["mNrm_mean"] = agent_data["mNrm"] + cs["mNrm_std"] = 0 + cs["cNrm_mean"] = agent_data["cNrm"] + cs["cNrm_std"] = 0 + cs["mNrm_ratio_StE_mean"] = agent_data["mNrm_ratio_StE"] + cs["mNrm_ratio_StE_std"] = 0 + cs["label"] = "all" + else: + cs = ( + agent_data.groupby(self.ex_ante_hetero_params) + .aggregate(["mean", "std"]) + .reset_index() + ) - cs.columns = ["_".join(col).strip("_") for col in cs.columns.values] + label = "" - label = "" + for param in self.ex_ante_hetero_params: + label += round(cs[param], 2).apply(lambda x: f"{param}={x}, ") - for param in self.ex_ante_hetero_params: - label += round(cs[param], 2).apply(lambda x: f"{param}={x}, ") + cs["label"] = label.str[:-2] - cs["label"] = label.str[:-2] + cs.columns = ["_".join(col).strip("_") for col in cs.columns.values] + + # print(cs.columns) + + # print(cs.columns) if store: self.stored_class_stats = cs @@ -314,7 +330,7 @@ def attend(self, agent, price, risky_expectations): # NOTE: This mutates the agent agent.shares = target_shares - if agent.shares < 0: + if np.any(agent.shares < 0): print(f"ERROR: Agent has negative shares after attention.") return delta_shares @@ -325,6 +341,9 @@ def assign_solution(self, agent): the agent's perceptions of the market. """ + if self.ex_ante_hetero_params is None or len(self.ex_ante_hetero_params) == 0: + return + # assign solution before simulating # get master solution pop_solution = self.solution.solution_database @@ -440,14 +459,14 @@ def macro_update(self, agent, price): agent.assign_parameters(**macro_risky_params) agent.simulate(sim_periods=1) - if agent.state_now["aNrm"] < 0: + if np.any(agent.state_now["aNrm"]) < 0: print("ERROR: Agent has negative assets after macro update.") - if agent.controls["Share"] < 0: + if np.any(agent.controls["Share"]) < 0: print("ERROR: Agent has negative risky share after macro update.") print(true_risky_expectations) - if agent.controls["Share"] > 1: + if np.any(agent.controls["Share"]) > 1: print("ERROR: Agent has share > 1 after macro update.") print(true_risky_expectations) diff --git a/simulate/parameters.py b/simulate/parameters.py index db1419c..2ca3f72 100644 --- a/simulate/parameters.py +++ b/simulate/parameters.py @@ -98,7 +98,7 @@ def build_population(agent_type, parameters, rng=None, dphm=1500): } lucas0_parameter_dict = lucas0_agent_population_params -lucas0_parameter_dict["AgentCount"] = 10 # TODO: What should this be? +lucas0_parameter_dict["AgentCount"] = 1 # TODO: What should this be? LUCAS0 = lucas0_parameter_dict