From e3ab50f0157f81d04b0d48b3d8fe427757a8d715 Mon Sep 17 00:00:00 2001 From: poliwop Date: Tue, 27 Jun 2023 16:34:51 -0500 Subject: [PATCH] Fixing run.py to address invest_all behavior --- hydradx/model/run.py | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/hydradx/model/run.py b/hydradx/model/run.py index 83fa6372..ae9d79a8 100644 --- a/hydradx/model/run.py +++ b/hydradx/model/run.py @@ -1,6 +1,7 @@ import time from .amm.global_state import GlobalState +from copy import deepcopy def run(initial_state: GlobalState, time_steps: int, silent: bool = False) -> list: @@ -21,16 +22,11 @@ def run(initial_state: GlobalState, time_steps: int, silent: bool = False) -> li # market evolutions new_global_state.evolve() - # agent actions - # agents = new_global_state.agents - # for agent_id, agent in agents.items(): - # if agent.trade_strategy: - # new_global_state = agent.trade_strategy.execute(new_global_state, agent.unique_id) - - for agent_id in new_global_state.agents: - # works as long as no trade_strategy adds or removes agents - if new_global_state.agents[agent_id].trade_strategy: - new_global_state = new_global_state.agents[agent_id].trade_strategy.execute(new_global_state, agent_id) + agent_ids = deepcopy(new_global_state.agents.keys()) + for agent_id in agent_ids: + agent = new_global_state.agents[agent_id] + if agent.trade_strategy: + new_global_state = agent.trade_strategy.execute(new_global_state, agent.unique_id) events.append(new_global_state.archive())