Skip to content

Commit

Permalink
put all the property in scenarios into local attribute to enable stat…
Browse files Browse the repository at this point in the history
…ic scenario content (#175)
  • Loading branch information
peteryang1 authored Aug 6, 2024
1 parent fbd8c6d commit c2daccb
Show file tree
Hide file tree
Showing 7 changed files with 166 additions and 136 deletions.
6 changes: 3 additions & 3 deletions rdagent/core/scenario.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
def experiment_setting(self) -> str | None:
"""Get experiment setting and return as rich text string"""
return None
17 changes: 16 additions & 1 deletion rdagent/scenarios/general_model/prompts.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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)
#### [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.
37 changes: 14 additions & 23 deletions rdagent/scenarios/general_model/scenario.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from copy import deepcopy
from pathlib import Path

from rdagent.core.prompts import Prompts
Expand All @@ -7,47 +8,37 @@


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:
raise NotImplementedError("source_data of GeneralModelScenario is not implemented")

@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:
Expand Down
53 changes: 20 additions & 33 deletions rdagent/scenarios/qlib/experiment/factor_experiment.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from copy import deepcopy
from pathlib import Path

from rdagent.components.coder.factor_coder.factor import (
Expand All @@ -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:
Expand All @@ -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 <br> Valid: 2015-01-01 to 2016-12-31 <br> Test &nbsp;: 2017-01-01 to 2020-08-01 |
"""
49 changes: 6 additions & 43 deletions rdagent/scenarios/qlib/experiment/factor_from_report_experiment.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from copy import deepcopy
from pathlib import Path

from rdagent.components.coder.factor_coder.factor import (
Expand All @@ -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)
<table border="1" style="width:100%; border-collapse: collapse;">
<tr>
<td>💡 <strong>Innovation </strong></td>
<td>Tool to quickly extract and test factors from research reports.</td>
</tr>
<tr>
<td>⚡ <strong>Efficiency </strong></td>
<td>Rapid identification of valuable factors from numerous reports.</td>
</tr>
<tr>
<td>🗃️ <strong>Outputs </strong></td>
<td>Expand and refine the factor library to support further research.</td>
</tr>
</table>
"""
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 <br> Valid: 2015-01-01 to 2016-12-31 <br> Test &nbsp;: 2017-01-01 to 2020-08-01 |
"""
def rich_style_description(self) -> str:
return self._rich_style_description
51 changes: 19 additions & 32 deletions rdagent/scenarios/qlib/experiment/model_experiment.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from copy import deepcopy
from pathlib import Path

from rdagent.components.coder.model_coder.model import (
Expand All @@ -19,49 +20,42 @@ 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:
raise NotImplementedError("source_data of QlibModelScenario is not implemented")

@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:
Expand All @@ -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 <br> Valid: 2015-01-01 to 2016-12-31 <br> Test &nbsp;: 2017-01-01 to 2020-08-01 |
"""
Loading

0 comments on commit c2daccb

Please sign in to comment.