mirror of
https://github.com/NicolasBohn/NexQuant.git
synced 2026-07-29 08:27:43 +00:00
put all the property in scenarios into local attribute to enable static scenario content (#175)
This commit is contained in:
@@ -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"""
|
||||
def experiment_setting(self) -> str | None:
|
||||
"""Get experiment setting and return as rich text string"""
|
||||
return None
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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 <br> Valid: 2015-01-01 to 2016-12-31 <br> Test : 2017-01-01 to 2020-08-01 |
|
||||
"""
|
||||
|
||||
@@ -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)
|
||||
|
||||
<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>
|
||||
"""
|
||||
|
||||
@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 : 2017-01-01 to 2020-08-01 |
|
||||
"""
|
||||
return self._rich_style_description
|
||||
|
||||
@@ -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 <br> Valid: 2015-01-01 to 2016-12-31 <br> Test : 2017-01-01 to 2020-08-01 |
|
||||
"""
|
||||
|
||||
@@ -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)
|
||||
|
||||
<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>
|
||||
|
||||
qlib_factor_experiment_setting: |-
|
||||
| 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 : 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.
|
||||
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 <br> Valid: 2015-01-01 to 2016-12-31 <br> Test : 2017-01-01 to 2020-08-01 |
|
||||
Reference in New Issue
Block a user