From c2daccb48c07b184041135c01eeff9a01e3b1f41 Mon Sep 17 00:00:00 2001 From: Xu Yang Date: Tue, 6 Aug 2024 17:07:01 +0800 Subject: [PATCH] put all the property in scenarios into local attribute to enable static scenario content (#175) --- rdagent/core/scenario.py | 6 +- rdagent/scenarios/general_model/prompts.yaml | 17 +++- rdagent/scenarios/general_model/scenario.py | 37 +++----- .../qlib/experiment/factor_experiment.py | 53 +++++------ .../factor_from_report_experiment.py | 49 ++-------- .../qlib/experiment/model_experiment.py | 51 ++++------- .../scenarios/qlib/experiment/prompts.yaml | 89 ++++++++++++++++++- 7 files changed, 166 insertions(+), 136 deletions(-) diff --git a/rdagent/core/scenario.py b/rdagent/core/scenario.py index 3e808da84..9943cc164 100644 --- a/rdagent/core/scenario.py +++ b/rdagent/core/scenario.py @@ -37,6 +37,6 @@ def get_scenario_all_desc(self) -> str: """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 2bbe894e8..e884c377f 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 08038225c..9b7e9b12d 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 @@ 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 @@ def source_data(self) -> str: @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 4e06f37a7..1c5f09f6d 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 @@ def __init__(self, *args, **kwargs) -> None: 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 - -#### [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. + return self._rich_style_description -- **[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 @@ def get_scenario_all_desc(self) -> str: 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 ab4e15d96..5cb2838d0 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 @@ class QlibFactorFromReportScenario(QlibFactorScenario): - @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.
- """ + def __init__(self) -> None: + super().__init__() + self._rich_style_description = deepcopy(prompt_dict["qlib_factor_from_report_rich_style_description"]) @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 | - """ + def rich_style_description(self) -> str: + return self._rich_style_description diff --git a/rdagent/scenarios/qlib/experiment/model_experiment.py b/rdagent/scenarios/qlib/experiment/model_experiment.py index c8e42cf16..9b88f4277 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 @@ def __init__(self, *args, **kwargs) -> None: 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 @@ def source_data(self) -> str: @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 @@ def get_scenario_all_desc(self) -> str: 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 237e77ae8..04aa06164 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