Files
NexQuant/rdagent/scenarios/qlib/experiment/factor_experiment.py
T

74 lines
2.4 KiB
Python
Raw Normal View History

from copy import deepcopy
2024-07-04 15:56:14 +08:00
from pathlib import Path
2024-07-17 15:00:13 +08:00
from rdagent.components.coder.factor_coder.factor import (
FactorExperiment,
FactorFBWorkspace,
FactorTask,
)
2024-07-04 15:56:14 +08:00
from rdagent.core.prompts import Prompts
2024-07-05 17:42:00 +08:00
from rdagent.core.scenario import Scenario
from rdagent.scenarios.qlib.experiment.utils import get_data_folder_intro
2024-07-17 15:00:13 +08:00
from rdagent.scenarios.qlib.experiment.workspace import QlibFBWorkspace
2024-07-04 15:56:14 +08:00
prompt_dict = Prompts(file_path=Path(__file__).parent / "prompts.yaml")
2024-07-17 15:00:13 +08:00
class QlibFactorExperiment(FactorExperiment[FactorTask, QlibFBWorkspace, FactorFBWorkspace]):
def __init__(self, *args, **kwargs) -> None:
super().__init__(*args, **kwargs)
self.experiment_workspace = QlibFBWorkspace(template_folder_path=Path(__file__).parent / "factor_template")
2024-07-04 15:56:14 +08:00
class QlibFactorScenario(Scenario):
def __init__(self) -> None:
super().__init__()
self._background = deepcopy(prompt_dict["qlib_factor_background"])
self._source_data = deepcopy(get_data_folder_intro())
self._output_format = deepcopy(prompt_dict["qlib_factor_output_format"])
self._interface = deepcopy(prompt_dict["qlib_factor_interface"])
self._simulator = deepcopy(prompt_dict["qlib_factor_simulator"])
self._rich_style_description = deepcopy(prompt_dict["qlib_factor_rich_style_description"])
self._experiment_setting = deepcopy(prompt_dict["qlib_factor_experiment_setting"])
2024-07-04 15:56:14 +08:00
@property
def background(self) -> str:
return self._background
2024-07-04 15:56:14 +08:00
@property
def source_data(self) -> str:
return self._source_data
2024-07-04 15:56:14 +08:00
2024-07-05 17:42:00 +08:00
@property
def output_format(self) -> str:
return self._output_format
2024-07-05 17:42:00 +08:00
2024-07-04 15:56:14 +08:00
@property
def interface(self) -> str:
return self._interface
2024-07-04 15:56:14 +08:00
@property
def simulator(self) -> str:
return self._simulator
@property
def rich_style_description(self) -> str:
return self._rich_style_description
@property
def experiment_setting(self) -> str:
return self._experiment_setting
2024-07-04 15:56:14 +08:00
def get_scenario_all_desc(self) -> str:
return f"""Background of the scenario:
{self.background}
The source data you can use:
{self.source_data}
The interface you should follow to write the runnable code:
{self.interface}
2024-07-05 17:42:00 +08:00
The output of your code should be in the format:
{self.output_format}
2024-07-04 15:56:14 +08:00
The simulator user can use to test your factor:
{self.simulator}
"""