From abcf7d913b6f4e1db1dcfab5e6b447445811ef8a Mon Sep 17 00:00:00 2001 From: WinstonLiyt <104308117+WinstonLiyt@users.noreply.github.com> Date: Tue, 6 Aug 2024 14:28:48 +0800 Subject: [PATCH] doc: Improved documentation for two factor scenarios. (#172) * Fixed some bugs introduced during refactoring. * Improved documentation for two factor scenarios. * Update factor_from_report_w_sc.py * Improved some details. --- docs/scens/data_agent_fin.rst | 83 ++++++++++++++----- docs/scens/data_copilot_fin.rst | 82 +++++++++++++----- .../qlib/experiment/factor_experiment.py | 2 +- .../factor_from_report_experiment.py | 2 +- 4 files changed, 122 insertions(+), 47 deletions(-) diff --git a/docs/scens/data_agent_fin.rst b/docs/scens/data_agent_fin.rst index 41ff0cc5..2c416312 100644 --- a/docs/scens/data_agent_fin.rst +++ b/docs/scens/data_agent_fin.rst @@ -4,42 +4,79 @@ Finance Data Agent ===================== -Scen1 ------ -πŸ€– Knowledge-Based Hypothesis Generation and Iteration -Scen1 Intro -~~~~~~~~~~~ -In this scenario, our model autonomously generates and tests hypotheses using a knowledge base. The process involves: +**Automated Quantitative Trading & Iterative Factors Evolution πŸ€–** +------------------------------------------------------------------- -- **πŸ” Hypothesis Generation**: The model proposes new hypotheses. -- **πŸ“ Factor Creation**: Write and define new factors. -- **βœ… Factor Validation**: Validate the factors quantitatively. -- **πŸ“ˆ Backtesting with Qlib**: +Background +~~~~~~~~~~ +In the dynamic world of quantitative trading, **factors** are the secret weapons that traders use to harness market inefficiencies. - - **Dataset**: CSI300 - - **Model**: LGBModel - - **Factors**: Alpha158 + - - **Data Split**: +These powerful toolsβ€”ranging from straightforward metrics like price-to-earnings ratios to intricate discounted cash flow modelsβ€”unlock the potential to predict stock prices with remarkable precision. +By tapping into this rich vein of data, quantitative traders craft sophisticated strategies that not only capitalize on market patterns but also drastically enhance trading efficiency and accuracy. - - **Train**: 2008-01-01 to 2014-12-31 - - **Valid**: 2015-01-01 to 2016-12-31 - - **Test**: 2017-01-01 to 2020-08-01 -- **πŸ”„ Feedback Analysis**: Analyze backtest results. -- **πŸ”§ Hypothesis Refinement**: Refine hypotheses based on feedback and repeat. +Embrace the power of factors, and you're not just trading; you're strategically outsmarting the market. -Scen1 Demo + +Introduction +~~~~~~~~~~~~ +In this scenario, our agent illustrates the iterative process of hypothesis generation, knowledge construction, and decision-making. + +It highlights how financial factors evolve through continuous feedback and refinement. + +Here's an enhanced outline of the steps: + +**Step 1 : Hypothesis Generation πŸ”** + +- Generate and propose initial hypotheses based on previous experiment analysis and domain expertise, with thorough reasoning and financial justification. + +**Step 2 : Factor Creation ✨** + +- Based on the hypothesis, divide the tasks. +- Each task involves developing, defining, and implementing a new financial factor, including its name, description, formulation, and variables. + +**Step 3 : Factor Implementation πŸ‘¨β€πŸ’»** + +- Implement the factor code based on the description, evolving it as a developer would. +- Quantitatively validate the newly created factors. + +**Step 4 : Backtesting with Qlib πŸ“‰** + +- Integrate the full dataset into the factor implementation code and prepare the factor library. +- Perform backtesting using the Alpha158+ model in Qlib to assess the factor's effectiveness and performance. + ++----------------+------------+----------------+----------------------------------------------------+ +| 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 | | +| | | | +-----------+--------------------------+ | ++----------------+------------+----------------+----------------------------------------------------+ + + +**Step 5 : Feedback Analysis πŸ”** + - Analyze backtest results. + - Incorporate feedback to refine hypotheses. + +**Step 6 :Hypothesis Refinement ♻️** + - Refine hypotheses based on feedback and repeat the process. + +Demo ~~~~~~~~~~ .. TODO -Scen1 Quick Start +Quick Start ~~~~~~~~~~~~~~~~~ -To quickly start the factor extraction process, run the following command in your terminal within the 'rdagent' virtual environment: +To quickly start the Automated Quantitative Trading & Iterative Factors Evolution process, run the following command in your terminal within the `rdagent` virtual environment: .. code-block:: sh - python rdagent/app/qlib_rd_loop/factor.py + python rdagent/app/qlib_rd_loop/factor_w_sc.py Usage of modules diff --git a/docs/scens/data_copilot_fin.rst b/docs/scens/data_copilot_fin.rst index ab35e8ea..847790bb 100644 --- a/docs/scens/data_copilot_fin.rst +++ b/docs/scens/data_copilot_fin.rst @@ -5,42 +5,80 @@ Finance Data Copilot ===================== -Scen2: ------- -πŸ“„ Research Report-Based Factor Extraction +**Automated Quantitative Trading & Factors Extraction from Financial ReportsπŸ“„** +--------------------------------------------------------------------------------- -Scen2 Intro -~~~~~~~~~~~ -In this scenario, factors and hypotheses are extracted from research reports. The process includes: +Background +~~~~~~~~~~ +**Research reports** are treasure troves of insights, often unveiling potential **factors** that can drive successful quantitative trading strategies. +Yet, with the sheer volume of reports available, extracting the most valuable insights efficiently becomes a daunting task. -- **πŸ” Factor Extraction**: Extract relevant factors from research reports. -- **πŸ“ Factor Creation**: Define these extracted factors. -- **βœ… Factor Validation**: Validate the extracted factors. -- **πŸ“ˆ Backtesting with Qlib**: +Furthermore, rather than hastily replicating factors from a report, it's essential to delve into the underlying logic of their construction. +Does the factor capture the essential market dynamics? How unique is it compared to the factors already in your library? - - **Dataset**: CSI300 - - **Model**: LGBModel - - **Factors**: Alpha158 + - - **Data Split**: +Therefore, there is an urgent need for a systematic approach to design a framework that can effectively manage this process. +This is where our R&D Agent comes into play. - - **Train**: 2008-01-01 to 2014-12-31 - - **Valid**: 2015-01-01 to 2016-12-31 - - **Test**: 2017-01-01 to 2020-08-01 -- **πŸ”„ Feedback Analysis**: Analyze backtest results. -- **πŸ”§ Hypothesis Refinement**: Refine hypotheses based on feedback and continue the cycle. -Scen2 Demo + +Introduction +~~~~~~~~~~~~ +In this scenario, our agent demonstrates the process of extracting factors from financial research reports, implementing these factors, and analyzing their performance through Qlib backtesting. +This process continually expands and refines the factor library. + +Here's an enhanced outline of the steps: + +**Step 1 : Hypothesis Generation πŸ”** + +- Generate and propose initial hypotheses based on insights from financial reports with thorough reasoning and financial justification. + +**Step 2 : Factor Creation ✨** + +- Based on the hypothesis and financial reports, divide the tasks. +- Each task involves developing, defining, and implementing a new financial factor, including its name, description, formulation, and variables. + +**Step 3 : Factor Implementation πŸ‘¨β€πŸ’»** + +- Implement the factor code based on the description, evolving it as a developer would. +- Quantitatively validate the newly created factors. + +**Step 4 : Backtesting with Qlib πŸ“‰** + +- Integrate the full dataset into the factor implementation code and prepare the factor library. +- Perform backtesting using the Alpha158+ model in Qlib to assess the factor's effectiveness and performance. + ++----------------+------------+----------------+----------------------------------------------------+ +| 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 | | +| | | | +-----------+--------------------------+ | ++----------------+------------+----------------+----------------------------------------------------+ + + +**Step 5 : Feedback Analysis πŸ”** + - Analyze backtest results. + - Incorporate feedback to refine hypotheses. + +**Step 6 : Knowledge Base Refinement ♻️** + - Refine the knowledge base based on feedback and repeat the process. + +Demo ~~~~~~~~~~ .. TODO Scen2 Quick Start ~~~~~~~~~~~~~~~~~ -To quickly start the factor extraction process, run the following command in your terminal within the 'rdagent' virtual environment: +To quickly start the factor extraction process, run the following command in your terminal within the `rdagent` virtual environment: .. code-block:: sh - python rdagent/app/qlib_rd_loop/factor_from_report_sh.py + python rdagent/app/qlib_rd_loop/factor_from_report_w_sc.py.py Usage of modules diff --git a/rdagent/scenarios/qlib/experiment/factor_experiment.py b/rdagent/scenarios/qlib/experiment/factor_experiment.py index 71433863..fdbe28ca 100644 --- a/rdagent/scenarios/qlib/experiment/factor_experiment.py +++ b/rdagent/scenarios/qlib/experiment/factor_experiment.py @@ -43,7 +43,7 @@ class QlibFactorScenario(Scenario): @property def rich_style_description(self) -> str: return """ -### R&D Agent-Qlib: Automated Quantitative Trading & Iterative Factor Evolution Demo +### R&D Agent-Qlib: Automated Quantitative Trading & Iterative Factors Evolution Demo #### [Overview](#_summary) diff --git a/rdagent/scenarios/qlib/experiment/factor_from_report_experiment.py b/rdagent/scenarios/qlib/experiment/factor_from_report_experiment.py index 25a6b42a..3d5c1798 100644 --- a/rdagent/scenarios/qlib/experiment/factor_from_report_experiment.py +++ b/rdagent/scenarios/qlib/experiment/factor_from_report_experiment.py @@ -17,7 +17,7 @@ class QlibFactorFromReportScenario(QlibFactorScenario): @property def rich_style_description(self) -> str: return """ -### R&D Agent-Qlib: Automated Quantitative Trading & Factor Extraction from Financial Reports Demo +### R&D Agent-Qlib: Automated Quantitative Trading & Factors Extraction from Financial Reports Demo #### [Overview](#_summary)