Files
NexQuant/rdagent/scenarios/qlib/experiment/workspace.py
T
Linlang 276b462f40 Fix ruff error1 (#81)
* fix_ruff_error1

* fix_ruff_error

* fix ruff error

* fix ruff error

* pass model.py

* rename exception class

* rename exception class

* rename func name generate_feedback

* remove prepare args

* optimize code

* optimize code

* fix code error
2024-07-18 22:36:04 +08:00

46 lines
1.3 KiB
Python

from pathlib import Path
from typing import Any
import pandas as pd
from rdagent.core.experiment import FBWorkspace
from rdagent.log import rdagent_logger as logger
from rdagent.utils.env import QTDockerEnv
class QlibFBWorkspace(FBWorkspace):
def __init__(self, template_folder_path: Path, *args, **kwargs) -> None:
super().__init__(*args, **kwargs)
self.inject_code_from_folder(template_folder_path)
def execute(self, qlib_config_name: str = "conf.yaml", run_env: dict = {}, *args, **kwargs) -> str:
qtde = QTDockerEnv()
qtde.prepare()
# Run the Docker command
execute_log = qtde.run(
local_path=str(self.workspace_path),
entry="rm -r mlruns",
env=run_env,
)
# Run the Qlib backtest
execute_log = qtde.run(
local_path=str(self.workspace_path),
entry=f"qrun {qlib_config_name}",
env=run_env,
)
execute_log = qtde.run(
local_path=str(self.workspace_path),
entry="python read_exp_res.py",
env=run_env,
)
csv_path = self.workspace_path / "qlib_res.csv"
if not csv_path.exists():
logger.error(f"File {csv_path} does not exist.")
return None
return pd.read_csv(csv_path, index_col=0).iloc[:, 0]