财务数据代理¶
🤖自动化量化交易与迭代因子演变¶
📖 背景¶
在动态的量化交易世界中,**因子**作为战略工具,使交易者能够利用市场低效。这些因子——从简单的指标如市盈率到复杂的模型如折现现金流——是以高准确度预测股票价格的关键。
通过利用这些因子,量化交易者可以制定复杂的策略,不仅识别市场模式,还显著提高交易效率和精确度。系统性地分析和应用这些因子的能力使普通交易与真正的战略市场超越有所区别。这就是**金融模型代理**发挥作用的地方。
🎮 演示¶
🌟 介绍¶
在这个场景中,我们的代理展示了假设生成、知识构建和决策的迭代过程。
它突出了金融因子如何通过持续的反馈和精炼而演变。
以下是步骤的增强大纲:
步骤 1 : 假设生成 🔍
基于之前实验分析和领域专业知识生成并提出初步假设,附上充分的推理和金融依据。
步骤 2 : 因子创建 ✨
根据假设,划分任务。
每个任务涉及开发、定义和实施一个新的金融因子,包括其名称、描述、公式和变量。
步骤 3 : 因子实施 👨💻
根据描述实施因子代码,像开发者一样不断演变。
对新创建的因子进行定量验证。
步骤 4 : 使用 Qlib 回测 📉
将完整数据集整合到因子实施代码中,并准备因子库。
使用 Alpha158 以及新开发的因子和 Qlib 中的 LGBModel 进行回测,以评估新因子的有效性和表现。
数据集 |
模型 |
因子 |
数据拆分 |
||||||
---|---|---|---|---|---|---|---|---|---|
CSI300 |
LGB模型 |
Alpha158 Plus |
|
步骤 5 : 反馈分析 🔍
分析回测结果以评估性能。
结合反馈来优化假设并改进模型。
步骤 6 : 假设优化 ♻️
根据回测反馈优化假设。
重复该过程以持续改进模型。
⚡ 快速开始¶
请参考 安装与配置 中的安装部分以准备您的系统依赖。
您可以通过运行以下命令尝试我们的演示:
🐍 创建一个 Conda 环境
创建一个新的conda环境,使用Python(3.10和3.11在我们的CI中经过良好测试):
conda create -n rdagent python=3.10
激活环境:
conda activate rdagent
📦 安装RDAgent
您可以从PyPI安装RDAgent包:
pip install rdagent
🚀 运行应用程序
您可以使用以下命令直接运行应用程序:
rdagent fin_factor
🛠️ 模块的使用¶
环境配置
可以在`.env`文件中设置以下环境变量,以自定义应用程序的行为:
- pydantic settings rdagent.app.qlib_rd_loop.conf.FactorBasePropSetting¶
Show JSON schema
{ "title": "FactorBasePropSetting", "type": "object", "properties": { "scen": { "default": "rdagent.scenarios.qlib.experiment.factor_experiment.QlibFactorScenario", "title": "Scen", "type": "string" }, "knowledge_base": { "default": "", "title": "Knowledge Base", "type": "string" }, "knowledge_base_path": { "default": "", "title": "Knowledge Base Path", "type": "string" }, "hypothesis_gen": { "default": "rdagent.scenarios.qlib.proposal.factor_proposal.QlibFactorHypothesisGen", "title": "Hypothesis Gen", "type": "string" }, "hypothesis2experiment": { "default": "rdagent.scenarios.qlib.proposal.factor_proposal.QlibFactorHypothesis2Experiment", "title": "Hypothesis2Experiment", "type": "string" }, "coder": { "default": "rdagent.scenarios.qlib.developer.factor_coder.QlibFactorCoSTEER", "title": "Coder", "type": "string" }, "runner": { "default": "rdagent.scenarios.qlib.developer.factor_runner.QlibFactorRunner", "title": "Runner", "type": "string" }, "summarizer": { "default": "rdagent.scenarios.qlib.developer.feedback.QlibFactorExperiment2Feedback", "title": "Summarizer", "type": "string" }, "evolving_n": { "default": 10, "title": "Evolving N", "type": "integer" } }, "additionalProperties": false }
- 配置:
env_prefix: str = QLIB_FACTOR_
protected_namespaces: tuple = ()
- field coder: str = 'rdagent.scenarios.qlib.developer.factor_coder.QlibFactorCoSTEER'¶
编码器类
- field evolving_n: int = 10¶
进化次数
- field hypothesis2experiment: str = 'rdagent.scenarios.qlib.proposal.factor_proposal.QlibFactorHypothesis2Experiment'¶
实验类的假设
- field hypothesis_gen: str = 'rdagent.scenarios.qlib.proposal.factor_proposal.QlibFactorHypothesisGen'¶
假设生成类
- field runner: str = 'rdagent.scenarios.qlib.developer.factor_runner.QlibFactorRunner'¶
运行器类
- field scen: str = 'rdagent.scenarios.qlib.experiment.factor_experiment.QlibFactorScenario'¶
Qlib Factor的场景类
- field summarizer: str = 'rdagent.scenarios.qlib.developer.feedback.QlibFactorExperiment2Feedback'¶
总结类
- pydantic settings rdagent.components.coder.factor_coder.config.FactorCoSTEERSettings
Show JSON schema
{ "title": "FactorCoSTEERSettings", "type": "object", "properties": { "coder_use_cache": { "default": false, "title": "Coder Use Cache", "type": "boolean" }, "max_loop": { "default": 10, "title": "Max Loop", "type": "integer" }, "fail_task_trial_limit": { "default": 20, "title": "Fail Task Trial Limit", "type": "integer" }, "v1_query_former_trace_limit": { "default": 5, "title": "V1 Query Former Trace Limit", "type": "integer" }, "v1_query_similar_success_limit": { "default": 5, "title": "V1 Query Similar Success Limit", "type": "integer" }, "v2_query_component_limit": { "default": 1, "title": "V2 Query Component Limit", "type": "integer" }, "v2_query_error_limit": { "default": 1, "title": "V2 Query Error Limit", "type": "integer" }, "v2_query_former_trace_limit": { "default": 1, "title": "V2 Query Former Trace Limit", "type": "integer" }, "v2_add_fail_attempt_to_latest_successful_execution": { "default": false, "title": "V2 Add Fail Attempt To Latest Successful Execution", "type": "boolean" }, "v2_error_summary": { "default": false, "title": "V2 Error Summary", "type": "boolean" }, "v2_knowledge_sampler": { "default": 1.0, "title": "V2 Knowledge Sampler", "type": "number" }, "knowledge_base_path": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "title": "Knowledge Base Path" }, "new_knowledge_base_path": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "title": "New Knowledge Base Path" }, "max_seconds": { "default": 1000000, "title": "Max Seconds", "type": "integer" }, "data_folder": { "default": "git_ignore_folder/factor_implementation_source_data", "title": "Data Folder", "type": "string" }, "data_folder_debug": { "default": "git_ignore_folder/factor_implementation_source_data_debug", "title": "Data Folder Debug", "type": "string" }, "simple_background": { "default": false, "title": "Simple Background", "type": "boolean" }, "file_based_execution_timeout": { "default": 120, "title": "File Based Execution Timeout", "type": "integer" }, "select_method": { "default": "random", "title": "Select Method", "type": "string" }, "python_bin": { "default": "python", "title": "Python Bin", "type": "string" } }, "additionalProperties": false }
- 配置:
env_prefix: str = FACTOR_CoSTEER_
- field data_folder: str = 'git_ignore_folder/factor_implementation_source_data'
包含金融数据的文件夹路径(默认是Qlib中的基本数据)
- field data_folder_debug: str = 'git_ignore_folder/factor_implementation_source_data_debug'
包含部分财务数据的文件夹路径(用于调试)
- field file_based_execution_timeout: int = 120
每个因子实现执行的超时时间(秒)
- field python_bin: str = 'python'
Python 二进制文件的路径
- field select_method: str = 'random'
因子实现选择的方法
- field simple_background: bool = False
是否使用简单的背景信息进行代码反馈