diff --git a/rdagent/core/scenario.py b/rdagent/core/scenario.py index 3e808da8..9943cc16 100644 --- a/rdagent/core/scenario.py +++ b/rdagent/core/scenario.py @@ -37,6 +37,6 @@ class Scenario(ABC): """Combine all the description together""" @property - @abstractmethod - def get_experiment_setting(self) -> str: - """Get experiment setting and return as rich text string""" \ No newline at end of file + def experiment_setting(self) -> str | None: + """Get experiment setting and return as rich text string""" + return None diff --git a/rdagent/scenarios/general_model/prompts.yaml b/rdagent/scenarios/general_model/prompts.yaml index 2bbe894e..e884c377 100644 --- a/rdagent/scenarios/general_model/prompts.yaml +++ b/rdagent/scenarios/general_model/prompts.yaml @@ -70,5 +70,20 @@ general_model_output_format: |- general_model_simulator: |- The models are not loaded and backtested. That said, pay attention to its architecture. +general_model_rich_style_description: |- + ### [Model Research & Development Co-Pilot](#_scenario) - \ No newline at end of file + #### [Overview](#_summary) + + This demo automates the extraction and development of PyTorch models from academic papers. It supports various model types through two main components: Reader and Coder. + + #### [Workflow Components](#_rdloops) + + 1. **[Reader](#_research)** + - Extracts model information from papers, including architectures and parameters. + - Converts content into a structured format using Large Language Models. + + 2. **[Evolving Coder](#_development)** + - Translates structured information into executable PyTorch code. + - Ensures correct tensor shapes with an evolving coding mechanism. + - Refines the code to match source specifications. diff --git a/rdagent/scenarios/general_model/scenario.py b/rdagent/scenarios/general_model/scenario.py index 08038225..9b7e9b12 100644 --- a/rdagent/scenarios/general_model/scenario.py +++ b/rdagent/scenarios/general_model/scenario.py @@ -1,3 +1,4 @@ +from copy import deepcopy from pathlib import Path from rdagent.core.prompts import Prompts @@ -7,9 +8,17 @@ prompt_dict = Prompts(file_path=Path(__file__).parent / "prompts.yaml") class GeneralModelScenario(Scenario): + def __init__(self) -> None: + super().__init__() + self._background = deepcopy(prompt_dict["general_model_background"]) + self._output_format = deepcopy(prompt_dict["general_model_output_format"]) + self._interface = deepcopy(prompt_dict["general_model_interface"]) + self._simulator = deepcopy(prompt_dict["general_model_simulator"]) + self._rich_style_description = deepcopy(prompt_dict["general_model_rich_style_description"]) + @property def background(self) -> str: - return prompt_dict["general_model_background"] + return self._background @property def source_data(self) -> str: @@ -17,37 +26,19 @@ class GeneralModelScenario(Scenario): @property def output_format(self) -> str: - return prompt_dict["general_model_output_format"] + return self._output_format @property def interface(self) -> str: - return prompt_dict["general_model_interface"] + return self._interface @property def simulator(self) -> str: - return prompt_dict["general_model_simulator"] + return self._simulator @property def rich_style_description(self) -> str: - return """ -### [Model Research & Development Co-Pilot](#_scenario) - -#### [Overview](#_summary) - -This demo automates the extraction and development of PyTorch models from academic papers. It supports various model types through two main components: Reader and Coder. - -#### [Workflow Components](#_rdloops) - -1. **[Reader](#_research)** - - Extracts model information from papers, including architectures and parameters. - - Converts content into a structured format using Large Language Models. - -2. **[Evolving Coder](#_development)** - - Translates structured information into executable PyTorch code. - - Ensures correct tensor shapes with an evolving coding mechanism. - - Refines the code to match source specifications. - - """ + return self._rich_style_description def get_scenario_all_desc(self) -> str: return f"""Background of the scenario: diff --git a/rdagent/scenarios/qlib/experiment/factor_experiment.py b/rdagent/scenarios/qlib/experiment/factor_experiment.py index 4e06f37a..1c5f09f6 100644 --- a/rdagent/scenarios/qlib/experiment/factor_experiment.py +++ b/rdagent/scenarios/qlib/experiment/factor_experiment.py @@ -1,3 +1,4 @@ +from copy import deepcopy from pathlib import Path from rdagent.components.coder.factor_coder.factor import ( @@ -20,49 +21,43 @@ class QlibFactorExperiment(FactorExperiment[FactorTask, QlibFBWorkspace, FactorF 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"]) + @property def background(self) -> str: - return prompt_dict["qlib_factor_background"] + return self._background @property def source_data(self) -> str: - return get_data_folder_intro() + return self._source_data @property def output_format(self) -> str: - return prompt_dict["qlib_factor_output_format"] + return self._output_format @property def interface(self) -> str: - return prompt_dict["qlib_factor_interface"] + return self._interface @property def simulator(self) -> str: - return prompt_dict["qlib_factor_simulator"] + return self._simulator @property def rich_style_description(self) -> str: - return """ -### R&D Agent-Qlib: Automated Quantitative Trading & Iterative Factors Evolution Demo + return self._rich_style_description -#### [Overview](#_summary) - -The demo showcases the iterative process of hypothesis generation, knowledge construction, and decision-making. It highlights how financial factors evolve through continuous feedback and refinement. - -#### [Automated R&D](#_rdloops) - -- **[R (Research)](#_research)** - - Iterative development of ideas and hypotheses. - - Continuous learning and knowledge construction. - -- **[D (Development)](#_development)** - - Progressive implementation and code generation of factors. - - Automated testing and validation of financial factors. - -#### [Objective](#_summary) - -To demonstrate the dynamic evolution of financial factors through the Qlib platform, emphasizing how each iteration enhances the accuracy and reliability of the resulting financial factors. - """ + @property + def experiment_setting(self) -> str: + return self._experiment_setting def get_scenario_all_desc(self) -> str: return f"""Background of the scenario: @@ -76,11 +71,3 @@ The output of your code should be in the format: The simulator user can use to test your factor: {self.simulator} """ - - @property - def get_experiment_setting(self) -> str: - return """ -| Dataset 📊 | Model 🤖 | Factors 🌟 | Data Split 🧮 | -|---------|----------|---------------|-------------------------------------------------| -| CSI300 | LGBModel | Alpha158 Plus | Train: 2008-01-01 to 2014-12-31
Valid: 2015-01-01 to 2016-12-31
Test  : 2017-01-01 to 2020-08-01 | - """ diff --git a/rdagent/scenarios/qlib/experiment/factor_from_report_experiment.py b/rdagent/scenarios/qlib/experiment/factor_from_report_experiment.py index ab4e15d9..5cb2838d 100644 --- a/rdagent/scenarios/qlib/experiment/factor_from_report_experiment.py +++ b/rdagent/scenarios/qlib/experiment/factor_from_report_experiment.py @@ -1,3 +1,4 @@ +from copy import deepcopy from pathlib import Path from rdagent.components.coder.factor_coder.factor import ( @@ -14,48 +15,10 @@ prompt_dict = Prompts(file_path=Path(__file__).parent / "prompts.yaml") class QlibFactorFromReportScenario(QlibFactorScenario): + def __init__(self) -> None: + super().__init__() + self._rich_style_description = deepcopy(prompt_dict["qlib_factor_from_report_rich_style_description"]) + @property def rich_style_description(self) -> str: - return """ -### R&D Agent-Qlib: Automated Quantitative Trading & Factor Extraction from Financial Reports Demo - - -#### [Overview](#_summary) - -This demo showcases the process of extracting factors from financial research reports, implementing these factors, and analyzing their performance through Qlib backtesting, continually expanding and refining the factor library. - -#### [Automated R&D](#_rdloops) - -- **[R (Research)](#_research)** - - Iterative development of ideas and hypotheses from financial reports. - - Continuous learning and knowledge construction. - -- **[D (Development)](#_development)** - - Progressive factor extraction and code generation. - - Automated implementation and testing of financial factors. - -#### [Objective](#_summary) - - - - - - - - - - - - - - -
💡 Innovation Tool to quickly extract and test factors from research reports.
Efficiency Rapid identification of valuable factors from numerous reports.
🗃️ Outputs Expand and refine the factor library to support further research.
- """ - - @property - def get_experiment_setting(self) -> str: - return """ -| Dataset 📊 | Model 🤖 | Factors 🌟 | Data Split 🧮 | -|---------|----------|---------------|-------------------------------------------------| -| CSI300 | LGBModel | Alpha158 Plus | Train: 2008-01-01 to 2014-12-31
Valid: 2015-01-01 to 2016-12-31
Test  : 2017-01-01 to 2020-08-01 | - """ + return self._rich_style_description diff --git a/rdagent/scenarios/qlib/experiment/model_experiment.py b/rdagent/scenarios/qlib/experiment/model_experiment.py index c8e42cf1..9b88f427 100644 --- a/rdagent/scenarios/qlib/experiment/model_experiment.py +++ b/rdagent/scenarios/qlib/experiment/model_experiment.py @@ -1,3 +1,4 @@ +from copy import deepcopy from pathlib import Path from rdagent.components.coder.model_coder.model import ( @@ -19,9 +20,18 @@ class QlibModelExperiment(ModelExperiment[ModelTask, QlibFBWorkspace, ModelFBWor class QlibModelScenario(Scenario): + def __init__(self) -> None: + super().__init__() + self._background = deepcopy(prompt_dict["qlib_model_background"]) + self._output_format = deepcopy(prompt_dict["qlib_model_output_format"]) + self._interface = deepcopy(prompt_dict["qlib_model_interface"]) + self._simulator = deepcopy(prompt_dict["qlib_model_simulator"]) + self._rich_style_description = deepcopy(prompt_dict["qlib_model_rich_style_description"]) + self._experiment_setting = deepcopy(prompt_dict["qlib_model_experiment_setting"]) + @property def background(self) -> str: - return prompt_dict["qlib_model_background"] + return self._background @property def source_data(self) -> str: @@ -29,39 +39,23 @@ class QlibModelScenario(Scenario): @property def output_format(self) -> str: - return prompt_dict["qlib_model_output_format"] + return self._output_format @property def interface(self) -> str: - return prompt_dict["qlib_model_interface"] + return self._interface @property def simulator(self) -> str: - return prompt_dict["qlib_model_simulator"] + return self._simulator @property def rich_style_description(self) -> str: - return """ -### Qlib Model Evolving Automatic R&D Demo - -#### [Overview](#_summary) - -The demo showcases the iterative process of hypothesis generation, knowledge construction, and decision-making in model construction in quantitative finance. It highlights how models evolve through continuous feedback and refinement. - -#### [Automated R&D](#_rdloops) - -- **[R (Research)](#_research)** - - Iteration of ideas and hypotheses. - - Continuous learning and knowledge construction. - -- **[D (Development)](#_development)** - - Evolving code generation and model refinement. - - Automated implementation and testing of models. - -#### [Objective](#_summary) - -To demonstrate the dynamic evolution of models through the Qlib platform, emphasizing how each iteration enhances the accuracy and reliability of the resulting models. - """ + return self._rich_style_description + + @property + def experiment_setting(self) -> str: + return self._experiment_setting def get_scenario_all_desc(self) -> str: return f"""Background of the scenario: @@ -73,10 +67,3 @@ The output of your code should be in the format: The simulator user can use to test your model: {self.simulator} """ - - def get_experiment_setting(self) -> str: - return """ -| Dataset 📊 | Model 🤖 | Factors 🌟 | Data Split 🧮 | -|---------|----------|---------------|-------------------------------------------------| -| CSI300 | RDAgent-dev | 20 factors (Alpha158) | Train: 2008-01-01 to 2014-12-31
Valid: 2015-01-01 to 2016-12-31
Test  : 2017-01-01 to 2020-08-01 | - """ diff --git a/rdagent/scenarios/qlib/experiment/prompts.yaml b/rdagent/scenarios/qlib/experiment/prompts.yaml index 237e77ae..04aa0616 100644 --- a/rdagent/scenarios/qlib/experiment/prompts.yaml +++ b/rdagent/scenarios/qlib/experiment/prompts.yaml @@ -46,6 +46,67 @@ qlib_factor_simulator: |- 3. build a portfolio based on the predicted return based on a strategy. 4. evaluate the portfolio's performance including the return, sharpe ratio, max drawdown, and so on. +qlib_factor_rich_style_description : |- + ### R&D Agent-Qlib: Automated Quantitative Trading & Iterative Factors Evolution Demo + + #### [Overview](#_summary) + + The demo showcases the iterative process of hypothesis generation, knowledge construction, and decision-making. It highlights how financial factors evolve through continuous feedback and refinement. + + #### [Automated R&D](#_rdloops) + + - **[R (Research)](#_research)** + - Iterative development of ideas and hypotheses. + - Continuous learning and knowledge construction. + + - **[D (Development)](#_development)** + - Progressive implementation and code generation of factors. + - Automated testing and validation of financial factors. + + #### [Objective](#_summary) + + To demonstrate the dynamic evolution of financial factors through the Qlib platform, emphasizing how each iteration enhances the accuracy and reliability of the resulting financial factors. + +qlib_factor_from_report_rich_style_description : |- + ### R&D Agent-Qlib: Automated Quantitative Trading & Factor Extraction from Financial Reports Demo + + #### [Overview](#_summary) + + This demo showcases the process of extracting factors from financial research reports, implementing these factors, and analyzing their performance through Qlib backtest, continually expanding and refining the factor library. + + #### [Automated R&D](#_rdloops) + + - **[R (Research)](#_research)** + - Iterative development of ideas and hypotheses from financial reports. + - Continuous learning and knowledge construction. + + - **[D (Development)](#_development)** + - Progressive factor extraction and code generation. + - Automated implementation and testing of financial factors. + + #### [Objective](#_summary) + + + + + + + + + + + + + + +
💡 Innovation Tool to quickly extract and test factors from research reports.
Efficiency Rapid identification of valuable factors from numerous reports.
🗃️ Outputs Expand and refine the factor library to support further research.
+ +qlib_factor_experiment_setting: |- + | Dataset 📊 | Model 🤖 | Factors 🌟 | Data Split 🧮 | + |---------|----------|---------------|-------------------------------------------------| + | CSI300 | LGBModel | Alpha158 Plus | Train: 2008-01-01 to 2014-12-31
Valid: 2015-01-01 to 2016-12-31
Test  : 2017-01-01 to 2020-08-01 | + + qlib_model_background: |- The model is a machine learning or deep learning structure used in quantitative investment to predict the returns and risks of a portfolio or a single asset. Models are employed by investors to generate forecasts based on historical data and identified factors, which are central to many quantitative investment strategies. Each model takes the factors as input and predicts the future returns. Usually, the bigger the model is, the better the performance would be. @@ -108,4 +169,30 @@ qlib_model_simulator: |- 2. Train the model defined in your class Net to predict the next several days' returns based on the factor values. 3. Build a portfolio based on the predicted returns using a specific strategy. 4. Evaluate the portfolio's performance, including metrics such as return, Sharpe ratio, max drawdown, and others. - 5. Iterate on growing the hypothesis to enable model improvements based on performance evaluations and feedback. \ No newline at end of file + 5. Iterate on growing the hypothesis to enable model improvements based on performance evaluations and feedback. + +qlib_model_rich_style_description: |- + ### Qlib Model Evolving Automatic R&D Demo + + #### [Overview](#_summary) + + The demo showcases the iterative process of hypothesis generation, knowledge construction, and decision-making in model construction in quantitative finance. It highlights how models evolve through continuous feedback and refinement. + + #### [Automated R&D](#_rdloops) + + - **[R (Research)](#_research)** + - Iteration of ideas and hypotheses. + - Continuous learning and knowledge construction. + + - **[D (Development)](#_development)** + - Evolving code generation and model refinement. + - Automated implementation and testing of models. + + #### [Objective](#_summary) + + To demonstrate the dynamic evolution of models through the Qlib platform, emphasizing how each iteration enhances the accuracy and reliability of the resulting models. + +qlib_model_experiment_setting: |- + | Dataset 📊 | Model 🤖 | Factors 🌟 | Data Split 🧮 | + |---------|----------|---------------|-------------------------------------------------| + | CSI300 | RDAgent-dev | 20 factors (Alpha158) | Train: 2008-01-01 to 2014-12-31
Valid: 2015-01-01 to 2016-12-31
Test  : 2017-01-01 to 2020-08-01 | \ No newline at end of file