MCPcopy Create free account
hub / github.com/DVampire/FinAgent / run

Function run

tools/main_strategy.py:149–224  ·  view source on GitHub ↗
(cfg, env, plots, memory, provider, diverse_query, strategy_agents,  exp_path, mode = "train")

Source from the content-addressed store, hash-verified

147 save_json(valid_records, valid_save_path)
148
149def run(cfg, env, plots, memory, provider, diverse_query, strategy_agents, exp_path, mode = "train"):
150
151 trading_records_path = os.path.join(exp_path, "trading_records")
152 os.makedirs(trading_records_path, exist_ok=True)
153 memory_path = os.path.join(exp_path, "memory_records")
154 os.makedirs(memory_path, exist_ok=True)
155
156 if cfg.if_load_trading_record and cfg.trading_record_path is not None:
157 print("load trading records...")
158 record_path = os.path.join(cfg.root, cfg.trading_record_path)
159 trading_records = load_json(record_path)
160 else:
161 trading_records = {
162 "symbol": [],
163 "day": [],
164 "value": [],
165 "cash": [],
166 "position": [],
167 "ret": [],
168 "date": [],
169 "price": [],
170 "discount": [],
171 "kline_path": [],
172 "trading_path": [],
173 "total_profit": [],
174 "total_return": [],
175 "action": [],
176 "reasoning": [],
177 }
178
179 state, info = env.reset()
180
181 if cfg.checkpoint_start_date is not None:
182 for action, date in zip(trading_records["action"], trading_records["date"]):
183 if date <= cfg.checkpoint_start_date:
184 action = env.action_map[action]
185 state, reward, done, truncated, info = env.step(action)
186 else:
187 break
188
189 while True:
190
191 action = run_step(cfg,
192 state,
193 info,
194 plots,
195 memory,
196 provider,
197 diverse_query,
198 strategy_agents,
199 exp_path,
200 trading_records,
201 mode)
202
203 assert action in env.action_map.keys(), f"Action {action} is not in the action map {env.action_map.keys()}"
204
205 action = env.action_map[action]
206 state, reward, done, truncated, info = env.step(action)

Callers 1

mainFunction · 0.70

Calls 6

load_jsonFunction · 0.90
save_jsonFunction · 0.90
resetMethod · 0.80
stepMethod · 0.80
run_stepFunction · 0.70
save_localMethod · 0.45

Tested by

no test coverage detected